Exemplo n.º 1
0
        public ClaimTypeConfig CopyPersistedProperties()
        {
            ClaimTypeConfig copy;

            if (this is IdentityClaimTypeConfig)
            {
                copy = new IdentityClaimTypeConfig()
                {
                    DirectoryObjectPropertyForGuestUsers = ((IdentityClaimTypeConfig)this).DirectoryObjectPropertyForGuestUsers
                };
            }
            else
            {
                copy = new ClaimTypeConfig();
            }

            copy._ClaimType = this._ClaimType;
            copy._DirectoryObjectProperty = this._DirectoryObjectProperty;
            copy._DirectoryObjectType     = this._DirectoryObjectType;
            copy._EntityDataKey           = this._EntityDataKey;
            copy._ClaimValueType          = this._ClaimValueType;
            copy._CreateAsIdentityClaim   = this._CreateAsIdentityClaim;
            copy._PrefixToBypassLookup    = this._PrefixToBypassLookup;
            copy._DirectoryObjectPropertyToShowAsDisplayText = this._DirectoryObjectPropertyToShowAsDisplayText;
            copy._FilterExactMatchOnly = this._FilterExactMatchOnly;
            copy._ClaimTypeDisplayName = this._ClaimTypeDisplayName;
            return(copy);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a copy of the current object. This copy does not have any member of the base SharePoint base class set
        /// </summary>
        /// <returns></returns>
        public ClaimTypeConfig CopyConfiguration()
        {
            ClaimTypeConfig copy;

            if (this is IdentityClaimTypeConfig)
            {
                copy = new IdentityClaimTypeConfig();
                FieldInfo[] fieldsToCopyFromInheritedClass = typeof(IdentityClaimTypeConfig).GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                foreach (FieldInfo field in fieldsToCopyFromInheritedClass)
                {
                    field.SetValue(copy, field.GetValue(this));
                }
            }
            else
            {
                copy = new ClaimTypeConfig();
            }

            // Copy non-inherited private fields
            FieldInfo[] fieldsToCopy = typeof(ClaimTypeConfig).GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);
            foreach (FieldInfo field in fieldsToCopy)
            {
                field.SetValue(copy, field.GetValue(this));
            }
            return(copy);
        }
Exemplo n.º 3
0
        public static IdentityClaimTypeConfig ConvertClaimTypeConfig(ClaimTypeConfig ctConfig)
        {
            IdentityClaimTypeConfig identityCTConfig = new IdentityClaimTypeConfig();

            identityCTConfig.ClaimType               = ctConfig.ClaimType;
            identityCTConfig.ClaimTypeDisplayName    = ctConfig.ClaimTypeDisplayName;
            identityCTConfig.ClaimValueType          = ctConfig.ClaimValueType;
            identityCTConfig.DirectoryObjectProperty = ctConfig.DirectoryObjectProperty;
            identityCTConfig.DirectoryObjectPropertyToShowAsDisplayText = ctConfig.DirectoryObjectPropertyToShowAsDisplayText;
            identityCTConfig.EntityDataKey        = ctConfig.EntityDataKey;
            identityCTConfig.EntityType           = ctConfig.EntityType;
            identityCTConfig.FilterExactMatchOnly = ctConfig.FilterExactMatchOnly;
            identityCTConfig.PrefixToBypassLookup = ctConfig.PrefixToBypassLookup;
            identityCTConfig.UseMainClaimTypeOfDirectoryObject = ctConfig.UseMainClaimTypeOfDirectoryObject;
            return(identityCTConfig);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Update the DirectoryObjectPropertyForGuestUsers of the identity ClaimTypeConfig.
        /// </summary>
        /// <param name="newIdentifier">new DirectoryObjectPropertyForGuestUsers</param>
        /// <returns></returns>
        public bool UpdateIdentifierForGuestUsers(AzureADObjectProperty newIdentifier)
        {
            if (newIdentifier == AzureADObjectProperty.NotSet)
            {
                throw new ArgumentNullException("newIdentifier");
            }

            bool identifierUpdated = false;
            IdentityClaimTypeConfig identityClaimType = innerCol.FirstOrDefault(x => x is IdentityClaimTypeConfig) as IdentityClaimTypeConfig;

            if (identityClaimType == null)
            {
                return(identifierUpdated);
            }

            if (identityClaimType.DirectoryObjectPropertyForGuestUsers == newIdentifier)
            {
                return(identifierUpdated);
            }

            identityClaimType.DirectoryObjectPropertyForGuestUsers = newIdentifier;
            identifierUpdated = true;
            return(identifierUpdated);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Update the DirectoryObjectProperty of the identity ClaimTypeConfig. If new value duplicates an existing item, it will be removed from the collection
        /// </summary>
        /// <param name="newIdentifier">new DirectoryObjectProperty</param>
        /// <returns>True if the identity ClaimTypeConfig was successfully updated</returns>
        public bool UpdateUserIdentifier(AzureADObjectProperty newIdentifier)
        {
            if (newIdentifier == AzureADObjectProperty.NotSet)
            {
                throw new ArgumentNullException("newIdentifier");
            }

            bool identifierUpdated = false;
            IdentityClaimTypeConfig identityClaimType = innerCol.FirstOrDefault(x => x is IdentityClaimTypeConfig) as IdentityClaimTypeConfig;

            if (identityClaimType == null)
            {
                return(identifierUpdated);
            }

            if (identityClaimType.DirectoryObjectProperty == newIdentifier)
            {
                return(identifierUpdated);
            }

            // Check if the new DirectoryObjectProperty duplicates an existing item, and delete it if so
            for (int i = 0; i < innerCol.Count; i++)
            {
                ClaimTypeConfig curCT = (ClaimTypeConfig)innerCol[i];
                if (curCT.EntityType == DirectoryObjectType.User &&
                    curCT.DirectoryObjectProperty == newIdentifier)
                {
                    innerCol.RemoveAt(i);
                    break;  // There can be only 1 potential duplicate
                }
            }

            identityClaimType.DirectoryObjectProperty = newIdentifier;
            identifierUpdated = true;
            return(identifierUpdated);
        }