Skip to content

Commit

Permalink
Use helper SPClaimTypes.Equals when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvand committed Jul 18, 2019
1 parent e876494 commit a52aaaf
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions LDAPCP/LDAPCP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,16 @@ private bool InitializeClaimTypeConfigList(ClaimTypeConfigCollection nonProcesse
{
// Search if current claim type in trust exists in ClaimTypeConfigCollection
ClaimTypeConfig claimTypeConfig = nonProcessedClaimTypes.FirstOrDefault(x =>
String.Equals(x.ClaimType, claimTypeInformation.MappedClaimType, StringComparison.InvariantCultureIgnoreCase) &&
!String.IsNullOrWhiteSpace(x.ClaimType) &&
SPClaimTypes.Equals(x.ClaimType, claimTypeInformation.MappedClaimType) &&
!x.UseMainClaimTypeOfDirectoryObject &&
!String.IsNullOrEmpty(x.LDAPAttribute) &&
!String.IsNullOrEmpty(x.LDAPClass));

if (claimTypeConfig == null) { continue; }
claimTypeConfig.ClaimTypeDisplayName = claimTypeInformation.DisplayName;
claimTypesSetInTrust.Add(claimTypeConfig);
if (String.Equals(SPTrust.IdentityClaimTypeInformation.MappedClaimType, claimTypeConfig.ClaimType, StringComparison.InvariantCultureIgnoreCase))
if (SPClaimTypes.Equals(SPTrust.IdentityClaimTypeInformation.MappedClaimType, claimTypeConfig.ClaimType))
{
// Identity claim type found, set IdentityClaimTypeConfig property
identityClaimTypeFound = true;
Expand All @@ -245,7 +246,7 @@ private bool InitializeClaimTypeConfigList(ClaimTypeConfigCollection nonProcesse
if (!String.IsNullOrEmpty(this.CurrentConfiguration.MainGroupClaimType))
{
// If MainGroupClaimType is set, try to set MainGroupClaimTypeConfig with the ClaimTypeConfig that has the same ClaimType
if (String.Equals(claimTypeConfig.ClaimType, this.CurrentConfiguration.MainGroupClaimType, StringComparison.InvariantCultureIgnoreCase))
if (SPClaimTypes.Equals(claimTypeConfig.ClaimType, this.CurrentConfiguration.MainGroupClaimType))
{
MainGroupClaimTypeConfig = claimTypeConfig;
groupClaimTypeFound = true;
Expand Down Expand Up @@ -501,7 +502,7 @@ protected override void FillSearch(Uri context, string[] entityTypes, string sea
{
ClaimTypeConfig ctConfig = ProcessedClaimTypesList.FirstOrDefault(x =>
!x.UseMainClaimTypeOfDirectoryObject &&
String.Equals(x.ClaimType, entity.Claim.ClaimType, StringComparison.InvariantCultureIgnoreCase));
SPClaimTypes.Equals(x.ClaimType, entity.Claim.ClaimType));

string nodeName = ctConfig != null ? ctConfig.ClaimTypeDisplayName : entity.Claim.ClaimType;
matchNode = new SPProviderHierarchyNode(_ProviderInternalName, nodeName, entity.Claim.ClaimType, true);
Expand Down Expand Up @@ -1156,7 +1157,7 @@ protected virtual void AugmentEntity(Uri context, SPClaim entity, SPClaimProvide
}

IEnumerable<ClaimTypeConfig> allGroupsCTConfig = this.ProcessedClaimTypesList.Where(x => x.EntityType == DirectoryObjectType.Group && !x.UseMainClaimTypeOfDirectoryObject);
ClaimTypeConfig mainGroupCTConfig = allGroupsCTConfig.FirstOrDefault(x => String.Equals(x.ClaimType, this.CurrentConfiguration.MainGroupClaimType, StringComparison.InvariantCultureIgnoreCase));
ClaimTypeConfig mainGroupCTConfig = allGroupsCTConfig.FirstOrDefault(x => SPClaimTypes.Equals(x.ClaimType, this.CurrentConfiguration.MainGroupClaimType));
if (mainGroupCTConfig == null)
{
ClaimsProviderLogging.Log($"[{ProviderInternalName}] Configuration for claim type '{this.CurrentConfiguration.MainGroupClaimType}' cannot be found, please add it in claim types configuration list.",
Expand Down Expand Up @@ -1184,7 +1185,7 @@ protected virtual void AugmentEntity(Uri context, SPClaim entity, SPClaimProvide
if (ldapConnection.GetGroupMembershipUsingDotNetHelpers)
{
directoryGroups = GetGroupsFromActiveDirectory(ldapConnection, currentContext, mainGroupCTConfig);
directoryGroups.AddRange(GetGroupsFromLDAPDirectory(ldapConnection, currentContext, allGroupsCTConfig.Where(x => !String.Equals(x.ClaimType, this.CurrentConfiguration.MainGroupClaimType, StringComparison.InvariantCultureIgnoreCase))));
directoryGroups.AddRange(GetGroupsFromLDAPDirectory(ldapConnection, currentContext, allGroupsCTConfig.Where(x => !SPClaimTypes.Equals(x.ClaimType, this.CurrentConfiguration.MainGroupClaimType))));
}
else
{
Expand Down Expand Up @@ -1273,7 +1274,7 @@ protected virtual List<SPClaim> GetGroupsFromActiveDirectory(LDAPConnection ldap
}

// https://github.com/Yvand/LDAPCP/issues/22: UserPrincipal.FindByIdentity() doesn't support emails, so if IncomingEntity is an email, user needs to be retrieved in a different way
if (String.Equals(currentContext.IncomingEntity.ClaimType, WIF4_5.ClaimTypes.Email, StringComparison.InvariantCultureIgnoreCase))
if (SPClaimTypes.Equals(currentContext.IncomingEntity.ClaimType, WIF4_5.ClaimTypes.Email))
{
using (UserPrincipal userEmailPrincipal = new UserPrincipal(principalContext) { Enabled = true, EmailAddress = currentContext.IncomingEntity.Value })
{
Expand Down Expand Up @@ -1596,7 +1597,7 @@ protected virtual SPClaim CreateClaim(string type, string value, string valueTyp
{
string claimValue = String.Empty;
//var attr = ProcessedAttributes.Where(x => x.ClaimTypeProp == type).FirstOrDefault();
var attr = ProcessedClaimTypesList.FirstOrDefault(x => String.Equals(x.ClaimType, type, StringComparison.InvariantCultureIgnoreCase));
var attr = ProcessedClaimTypesList.FirstOrDefault(x => SPClaimTypes.Equals(x.ClaimType, type));
//if (inputHasKeyword && attr.DoNotAddPrefixIfInputHasKeywordProp)
if ((!inputHasKeyword || !attr.DoNotAddClaimValuePrefixIfBypassLookup) &&
!HasPrefixToken(attr.ClaimValuePrefix, ClaimsProviderConstants.LDAPCPCONFIG_TOKENDOMAINNAME) &&
Expand All @@ -1620,7 +1621,7 @@ protected virtual PickerEntity CreatePickerEntityHelper(ConsolidatedResult resul
string permissionClaimType = result.ClaimTypeConfig.ClaimType;
bool isIdentityClaimType = false;

if ((String.Equals(permissionClaimType, SPTrust.IdentityClaimTypeInformation.MappedClaimType, StringComparison.InvariantCultureIgnoreCase)
if ((SPClaimTypes.Equals(permissionClaimType, SPTrust.IdentityClaimTypeInformation.MappedClaimType)
|| result.ClaimTypeConfig.UseMainClaimTypeOfDirectoryObject) && result.ClaimTypeConfig.LDAPClass == IdentityClaimTypeConfig.LDAPClass)
{
isIdentityClaimType = true;
Expand Down Expand Up @@ -1705,7 +1706,7 @@ protected virtual string FormatPermissionValue(string claimType, string claimVal
{
string value = claimValue;

var attr = ProcessedClaimTypesList.FirstOrDefault(x => String.Equals(x.ClaimType, claimType, StringComparison.InvariantCultureIgnoreCase));
var attr = ProcessedClaimTypesList.FirstOrDefault(x => SPClaimTypes.Equals(x.ClaimType, claimType));
if (HasPrefixToken(attr.ClaimValuePrefix, ClaimsProviderConstants.LDAPCPCONFIG_TOKENDOMAINNAME))
{
value = string.Format("{0}{1}", attr.ClaimValuePrefix.Replace(ClaimsProviderConstants.LDAPCPCONFIG_TOKENDOMAINNAME, domainName), value);
Expand Down Expand Up @@ -1861,7 +1862,7 @@ protected virtual List<PickerEntity> CreatePickerEntityForSpecificClaimTypes(str
ConsolidatedResult result = new ConsolidatedResult();
result.ClaimTypeConfig = ctConfig;
result.Value = input;
bool isIdentityClaimType = String.Equals(claim.ClaimType, IdentityClaimTypeConfig.ClaimType, StringComparison.InvariantCultureIgnoreCase);
bool isIdentityClaimType = SPClaimTypes.Equals(claim.ClaimType, IdentityClaimTypeConfig.ClaimType);
pe.DisplayText = FormatPermissionDisplayText(pe, isIdentityClaimType, result);

entities.Add(pe);
Expand Down

0 comments on commit a52aaaf

Please sign in to comment.