-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make LDAPCP SE more customizable for developers and add a custom samp…
…le (#229) * scaffold sample * work * work * Update .gitignore * update sample * update readme files * Add property CustomFilter to class DirectoryConnection * work * Update LDAPCPSE_Custom.cs * Update CHANGELOG.md
- Loading branch information
Showing
18 changed files
with
360 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.dll |
72 changes: 72 additions & 0 deletions
72
...sic/Features/LDAPCPSE_basic.ClaimsProvider/LDAPCPSE_basic.ClaimsProvider.EventReceiver.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using Microsoft.SharePoint; | ||
using Microsoft.SharePoint.Administration; | ||
using Microsoft.SharePoint.Administration.Claims; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Yvand.LdapClaimsProvider.Logging; | ||
|
||
namespace LDAPCPSE_basic.Features | ||
{ | ||
/// <summary> | ||
/// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade. | ||
/// </summary> | ||
/// <remarks> | ||
/// The GUID attached to this class may be used during packaging and should not be modified. | ||
/// </remarks> | ||
|
||
[Guid("8a0189bf-2e90-48b0-85f7-f639b42e3ef8")] | ||
public class LDAPCPSECustomEventReceiver : SPClaimProviderFeatureReceiver | ||
{ | ||
public override string ClaimProviderAssembly => typeof(LDAPCPSE_Custom).Assembly.FullName; | ||
|
||
public override string ClaimProviderDescription => LDAPCPSE_Custom.ClaimsProviderName; | ||
|
||
public override string ClaimProviderDisplayName => LDAPCPSE_Custom.ClaimsProviderName; | ||
|
||
public override string ClaimProviderType => typeof(LDAPCPSE_Custom).FullName; | ||
|
||
public override void FeatureActivated(SPFeatureReceiverProperties properties) | ||
{ | ||
ExecBaseFeatureActivated(properties); | ||
} | ||
|
||
private void ExecBaseFeatureActivated(Microsoft.SharePoint.SPFeatureReceiverProperties properties) | ||
{ | ||
// Wrapper function for base FeatureActivated. | ||
// Used because base keywork can lead to unverifiable code inside lambda expression | ||
base.FeatureActivated(properties); | ||
SPSecurity.RunWithElevatedPrivileges((SPSecurity.CodeToRunElevated)delegate () | ||
{ | ||
try | ||
{ | ||
Logger svc = Logger.Local; | ||
Logger.Log($"[{LDAPCPSE_Custom.ClaimsProviderName}] Activating farm-scoped feature for claims provider \"{LDAPCPSE_Custom.ClaimsProviderName}\"", TraceSeverity.High, EventSeverity.Information, TraceCategory.Configuration); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.LogException((string)LDAPCPSE_Custom.ClaimsProviderName, $"activating farm-scoped feature for claims provider \"{LDAPCPSE_Custom.ClaimsProviderName}\"", TraceCategory.Configuration, ex); | ||
} | ||
}); | ||
} | ||
|
||
public override void FeatureUninstalling(SPFeatureReceiverProperties properties) | ||
{ | ||
} | ||
|
||
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) | ||
{ | ||
SPSecurity.RunWithElevatedPrivileges((SPSecurity.CodeToRunElevated)delegate () | ||
{ | ||
try | ||
{ | ||
Logger.Log($"[{LDAPCPSE_Custom.ClaimsProviderName}] Deactivating farm-scoped feature for claims provider \"{LDAPCPSE_Custom.ClaimsProviderName}\": Removing claims provider from the farm (but not its configuration)", TraceSeverity.High, EventSeverity.Information, TraceCategory.Configuration); | ||
base.RemoveClaimProvider((string)LDAPCPSE_Custom.ClaimsProviderName); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.LogException((string)LDAPCPSE_Custom.ClaimsProviderName, $"deactivating farm-scoped feature for claims provider \"{LDAPCPSE_Custom.ClaimsProviderName}\"", TraceCategory.Configuration, ex); | ||
} | ||
}); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...E_basic/Features/LDAPCPSE_basic.ClaimsProvider/LDAPCPSE_basic.ClaimsProvider.Template.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"> | ||
</Feature> |
2 changes: 2 additions & 0 deletions
2
...APCPSE_basic/Features/LDAPCPSE_basic.ClaimsProvider/LDAPCPSE_basic.ClaimsProvider.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<feature xmlns:dm0="http://schemas.microsoft.com/VisualStudio/2008/DslTools/Core" dslVersion="1.0.0.0" Id="23e0908f-e7c6-4359-a4f6-294e0a9568dd" creator="Yvan Duhamel" featureId="4d6c1089-9e73-458d-9b77-10566ff6ec63" imageUrl="" receiverAssembly="$SharePoint.Project.AssemblyFullName$" receiverClass="$SharePoint.Type.8a0189bf-2e90-48b0-85f7-f639b42e3ef8.FullName$" scope="Farm" solutionId="184186f1-9e4b-4624-9782-21e275751d43" title="LDAPCPSE_basic.ClaimsProvider" version="" deploymentPath="$SharePoint.Feature.FileNameWithoutExtension$" xmlns="http://schemas.microsoft.com/VisualStudio/2008/SharePointTools/FeatureModel" /> |
49 changes: 49 additions & 0 deletions
49
custom-claims-provider-samples/LDAPCPSE_basic/LDAPCPSE_Custom.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Microsoft.SharePoint.Administration; | ||
using System; | ||
using Yvand.LdapClaimsProvider; | ||
using Yvand.LdapClaimsProvider.Configuration; | ||
using Yvand.LdapClaimsProvider.Logging; | ||
|
||
namespace LDAPCPSE_basic | ||
{ | ||
public class LDAPCPSE_Custom : LDAPCPSE | ||
{ | ||
/// <summary> | ||
/// Sets the name of the claims provider, also set in (Get-SPTrustedIdentityTokenIssuer).ClaimProviderName property | ||
/// </summary> | ||
public new const string ClaimsProviderName = "LDAPCPSE_Custom"; | ||
|
||
/// <summary> | ||
/// Do not remove or change this property | ||
/// </summary> | ||
public override string Name => ClaimsProviderName; | ||
|
||
public LDAPCPSE_Custom(string displayName) : base(displayName) | ||
{ | ||
} | ||
|
||
public override ILdapProviderSettings GetSettings() | ||
{ | ||
ClaimsProviderSettings settings = ClaimsProviderSettings.GetDefaultSettings(ClaimsProviderName); | ||
settings.EntityDisplayTextPrefix = "(custom) "; | ||
//settings.UserIdentifierClaimTypeConfig.DirectoryObjectAttributeForDisplayText = "displayName"; | ||
return settings; | ||
} | ||
|
||
public override void ValidateRuntimeSettings(OperationContext operationContext) | ||
{ | ||
Uri currentSite = operationContext.UriContext; | ||
string currentUser = operationContext.UserInHttpContext?.Value; | ||
Logger.Log($"New request with input {operationContext.Input} from URL {currentSite} and user {currentUser}", TraceSeverity.High, EventSeverity.Information, TraceCategory.Custom); | ||
// Returns all groups, or only users members of group testLdapcpGroup_002 | ||
string customFilter = "(|(objectClass=group)(memberOf=CN=testLdapcpGroup_002,OU=ldapcp,DC=contoso,DC=local))"; | ||
customFilter = "(|(&(objectClass=group)(|(sAMAccountName=testLdapcpGroup_002)(sAMAccountName=testLdapcpGroup_003)))(memberOf=CN=testLdapcpGroup_002,OU=ldapcp,DC=contoso,DC=local))"; | ||
operationContext.LdapConnections[0].CustomFilter = customFilter; | ||
//if (currentSite.Port == 6000) | ||
//{ | ||
// operationContext.LdapConnections[0].CustomFilter = "(telephoneNumber=00110011)"; | ||
//} | ||
Logger.Log($"Apply custom LDAP filter \"{customFilter}\"", TraceSeverity.High, EventSeverity.Information, TraceCategory.Custom); | ||
} | ||
} | ||
} |
Oops, something went wrong.