예제 #1
0
        private PickerEntity GetPickerEntity(User user)
        {
            UPSClaimProviderLogger.LogDebug("GetPickerEntity invoked!");

            PickerEntity entity = CreatePickerEntity();

            string originalIssuer = SPOriginalIssuers.Format(SPOriginalIssuerType.TrustedProvider, SPTrustedIdentityTokenIssuerName);

            UPSClaimProviderLogger.LogDebug($"originalIssuer: {originalIssuer}");
            entity.Claim = new SPClaim(UPSEmailAddressClaimType, user.Email, UPSEmailAddressClaimValueType, originalIssuer);
            string claimAsString = entity.Claim.ToEncodedString();

            UPSClaimProviderLogger.LogDebug($"claimAsString: {claimAsString}");


            entity.Description = user.Username;
            entity.DisplayText = user.Username;
            entity.EntityData[PeopleEditorEntityDataKeys.DisplayName] = user.Username;
            entity.EntityData[PeopleEditorEntityDataKeys.Email]       = user.Email;
            entity.EntityData[PeopleEditorEntityDataKeys.AccountName] = user.Email;
            entity.EntityData[PeopleEditorEntityDataKeys.Department]  = user.Department;
            entity.EntityData[PeopleEditorEntityDataKeys.JobTitle]    = user.JobTitle;
            entity.EntityType = SPClaimEntityTypes.User;
            entity.IsResolved = true;
            return(entity);
        }
예제 #2
0
        protected override void FillResolve(Uri context, string[] entityTypes, string resolveInput, List <Microsoft.SharePoint.WebControls.PickerEntity> resolved)
        {
            UPSClaimProviderLogger.LogDebug("FillResolve type1 invoked!");
            string outputString;

            outputString = $"resolveInput: {resolveInput}";
            UPSClaimProviderLogger.LogDebug(outputString);

            List <User> foundUsers = usersDAL.GetUsersBySearchPattern(resolveInput);

            if (foundUsers.Count > 0)
            {
                UPSClaimProviderLogger.LogDebug($"Count of users found: {foundUsers.Count} - input resolved");
                foundUsers.ForEach((foundUser) =>
                {
                    PickerEntity entity = GetPickerEntity(foundUser);
                    resolved.Add(entity);
                    UPSClaimProviderLogger.LogDebug($"Added PickerEntity to resolved with Claim -  Claim.Value: {entity.Claim.Value}, Claim.ClaimType: {entity.Claim.ClaimType}, Claim.OriginalIssuer: {entity.Claim.OriginalIssuer}");
                });
            }
            else if (foundUsers.Count == 0)
            {
                UPSClaimProviderLogger.LogDebug("No users found - input unresolved");
            }
            ;
        }
예제 #3
0
        protected override void FillSearch(Uri context, string[] entityTypes, string searchPattern, string hierarchyNodeID, int maxCount, Microsoft.SharePoint.WebControls.SPProviderHierarchyTree searchTree)
        {
            UPSClaimProviderLogger.LogDebug("FillSearch invoked!");

            LogDebugSearchTree(searchTree);

            string outputString;

            outputString = $"searchPattern: {searchPattern}, hierarchyNodeID: {hierarchyNodeID}, maxCount: {maxCount}";
            UPSClaimProviderLogger.LogDebug(outputString);

            List <User> foundUsers = usersDAL.GetUsersBySearchPattern(searchPattern);

            if (foundUsers.Count > 0)
            {
                UPSClaimProviderLogger.LogDebug($"Count of users found: {foundUsers.Count}");

                foundUsers.ForEach((foundUser) =>
                {
                    PickerEntity entity = GetPickerEntity(foundUser);
                    searchTree.AddEntity(entity);
                    UPSClaimProviderLogger.LogDebug($"Added PickerEntity with Claim -  Claim.Value: {entity.Claim.Value}, Claim.ClaimType: {entity.Claim.ClaimType}, Claim.OriginalIssuer: {entity.Claim.OriginalIssuer}");
                });
            }
            else if (foundUsers.Count == 0)
            {
                UPSClaimProviderLogger.LogDebug("No users found");
            }
            ;
        }
예제 #4
0
 protected void LogDebugSearchTree(Microsoft.SharePoint.WebControls.SPProviderHierarchyTree searchTree)
 {
     UPSClaimProviderLogger.LogDebug($"Writing to log SPProviderHierarchyTree:");
     UPSClaimProviderLogger.LogDebug($"searchTree.Name: {searchTree.Name}");
     UPSClaimProviderLogger.LogDebug($"searchTree.ProviderName: {searchTree.ProviderName}");
     UPSClaimProviderLogger.LogDebug($"searchTree.IsRoot: {searchTree.IsRoot}");
     UPSClaimProviderLogger.LogDebug($"searchTree.IsLeaf: {searchTree.IsLeaf}");
     UPSClaimProviderLogger.LogDebug($"searchTree.HierarchyNodeID: {searchTree.HierarchyNodeID}");
     UPSClaimProviderLogger.LogDebug($"searchTree.HasChildren: {searchTree.HasChildren}");
     UPSClaimProviderLogger.LogDebug($"searchTree.Count: {searchTree.Count}");
 }
예제 #5
0
        public List <User> GetUsersBySearchPattern(string searchPattern)
        {
            UPSClaimProviderLogger.LogDebug("UPSUsersDAL.GetUsersBySearchPattern invoked!");
            string      outputString;
            List <User> foundUsers = new List <User>();

            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    UPSClaimProviderLogger.LogDebug("Running with elevated privileges");
                    // Access the User Profile Service
                    try
                    {
                        SPServiceContext serviceContext = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);
                        UPSClaimProviderLogger.LogDebug("Reference to SPServiceContext obtained");
                        UserProfileManager userProfileManager = new UserProfileManager(serviceContext);
                        UPSClaimProviderLogger.LogDebug("Reference to UserProfileManager obtained");
                        ProfileBase[] searchResults = userProfileManager.Search(searchPattern);
                        UPSClaimProviderLogger.LogDebug($"searchResults.Length: {searchResults.Length}");
                        outputString = searchResults.Aggregate("", (result, item) => String.Concat(result, "User display name: ", item.DisplayName, "; "));
                        UPSClaimProviderLogger.LogDebug(outputString);


                        Array.ForEach(searchResults, (profileBaseItem) =>
                        {
                            UserProfile item = (UserProfile)profileBaseItem;
                            User user        = UserProfileToUser(item);
                            outputString     = $"Retrieved user properties - Email: {user.Email}, Username: {user.Username}, Firstname: {user.Firstname}, Lastname: {user.Lastname}, Department: {user.Department}, JobTitle: {user.JobTitle}";
                            UPSClaimProviderLogger.LogDebug(outputString);
                            foundUsers.Add(user);
                        });
                    }
                    catch (System.Exception e)
                    {
                        UPSClaimProviderLogger.LogError(e.Message);
                    }
                });
            }
            catch (System.Exception e)
            {
                UPSClaimProviderLogger.LogError($"Error while trying to elevate privileges: {e.Message}");
            };

            return(foundUsers);
        }
예제 #6
0
        // Get the first TrustedLoginProvider associated with current claim provider
        public static SPTrustedLoginProvider GetSPTrustAssociatedWithCP(string ProviderInternalName)
        {
            var lp = SPSecurityTokenServiceManager.Local.TrustedLoginProviders.Where(x => String.Equals(x.ClaimProviderName, ProviderInternalName, StringComparison.OrdinalIgnoreCase));

            if (lp != null && lp.Count() == 1)
            {
                return(lp.First());
            }

            if (lp != null && lp.Count() > 1)
            {
                UPSClaimProviderLogger.LogError(String.Format("[{0}] Claims provider {0} is associated to multiple SPTrustedIdentityTokenIssuer, which is not supported because at runtime there is no way to determine what TrustedLoginProvider is currently calling", ProviderInternalName));
                return(null);
            }

            UPSClaimProviderLogger.LogError(String.Format("[{0}] Claims provider {0} is not associated with any SPTrustedIdentityTokenIssuer. Set property ClaimProviderName with PowerShell cmdlet Get-SPTrustedIdentityTokenIssuer to create association.", ProviderInternalName));
            return(null);
        }
예제 #7
0
        protected override void FillResolve(Uri context, string[] entityTypes, SPClaim resolveInput, List <Microsoft.SharePoint.WebControls.PickerEntity> resolved)
        {
            UPSClaimProviderLogger.LogDebug("FillResolve type2 invoked!");

            string outputString;

            outputString  = $"resolveInput - ";
            outputString += $"ClaimType: {resolveInput.ClaimType}; ";
            outputString += $"OriginalIssuer: {resolveInput.OriginalIssuer}; ";
            outputString += $"Value: {resolveInput.Value}; ";
            outputString += $"ValueType: {resolveInput.ValueType}; ";
            UPSClaimProviderLogger.LogDebug(outputString);

            UPSClaimProviderLogger.LogDebug($"SPTrustedIdentityTokenIssuerName: {SPTrustedIdentityTokenIssuerName}");

            if (!resolveInput.OriginalIssuer.ToLower().Contains(SPTrustedIdentityTokenIssuerName.ToLower()))
            {
                return;
            }

            SPClaimProviderManager cpm = SPClaimProviderManager.Local;
            string accountName         = cpm.EncodeClaim(resolveInput);
            User   foundUser           = usersDAL.GetUserByAccountName(accountName);

            if (foundUser == null)
            {
                UPSClaimProviderLogger.LogError($"usersDAL.GetUserByAccountName(accountName) returned null! Error performing the final resolving of the user in FillResolve type2");
                return;
            }
            ;
            UPSClaimProviderLogger.LogDebug($"foundUser.Email: {foundUser.Email}");

            PickerEntity entity = GetPickerEntity(foundUser);

            resolved.Add(entity);
            UPSClaimProviderLogger.LogDebug($"Added PickerEntity to resolved with Claim -  Claim.Value: {entity.Claim.Value}, Claim.ClaimType: {entity.Claim.ClaimType}, Claim.OriginalIssuer: {entity.Claim.OriginalIssuer}");
        }
예제 #8
0
        public User GetUserByAccountName(string accountName)
        {
            UPSClaimProviderLogger.LogDebug("UPSUsersDAL.GetUserByAccountName invoked!");
            UPSClaimProviderLogger.LogDebug($"accountName: {accountName}");
            User foundUser = null;

            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    UPSClaimProviderLogger.LogDebug("Running with elevated privileges");
                    // Access the User Profile Service
                    try
                    {
                        SPServiceContext serviceContext = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);
                        UPSClaimProviderLogger.LogDebug("Reference to SPServiceContext obtained");
                        UserProfileManager userProfileManager = new UserProfileManager(serviceContext);
                        UPSClaimProviderLogger.LogDebug("Reference to UserProfileManager obtained");

                        UserProfile userProfile = userProfileManager.GetUserProfile(accountName);
                        UPSClaimProviderLogger.LogDebug($"userProfile: {userProfile}");
                        foundUser = UserProfileToUser(userProfile);
                    }
                    catch (System.Exception e)
                    {
                        UPSClaimProviderLogger.LogError(e.Message);
                    }
                });
            }
            catch (System.Exception e)
            {
                UPSClaimProviderLogger.LogError($"Error while trying to elevate privileges: {e.Message}");
            };

            return(foundUser);
        }