miércoles, 22 de marzo de 2017

User Information List in SharePoint All details

As per the Name SharePoint User Information List stores information about a user by having some metadata set up for the user. Some examples are User Picture, Email, DisplayName, LoginName etc. For a complete list of fields, see further down this blogpost under "User Information List Fields".
When a user get added in User Information List?
When we grant any user permissions to a user, they are added automatically to the hidden User Information list a new item will be created in the User Information List storing some information about the user.
Even though if we grant access to any active directory group the group gets added to the hidden User Information list as well but the user does not get added until they access the site. (As an example, I granted an AD group permissions to my site & only the AD group showed up in the hidden User Information list not the users
It has been changed little bit in SharePoint 2013. As it shows user in list as soon as I give them permission to site regardless of they logon or not
Where the User Information details are used in SharePoint
When a user add/create or edit an item, documents or pages SharePoint will display the Created By or Last modified by details for the users and these all comes from the SharePoint User Information List
URL for User Information List SP 2010 ?
http://siteurl/_catalogs/users/detail.aspx - If you want to see the detail view of only Users in the list.
http://siteurl/_catalogs/users/simple.aspx - The blow URL will show the simple view of only Users in the List
http://siteurl/_catalogs/users/allgroups.aspx - This will provide all the groups without users available in Site.
URL for User Information List SharePoint 2013?
http://siteurl/_catalogs/users/detail.aspx - If you want to see the detail view of only Users in the list.
http://siteurl/_catalogs/users/simple.aspx - The blow URL will show the simple view of only Users in the List
http://siteurl/_catalogs/users/allgroups.aspx - This will provide all the groups without users available in
http://siteurl/_layouts/15/people.aspx?MembershipGroupId=0
URL for User Information List SharePoint online, O365

Or
http://siteurl/_layouts/15/people.aspx?MembershipGroupId=0
Note : /_catalogs folder is not mapped as virtual folder in IIS, like /_layouts, /settings.aspx or other application pages that we have in SharePoint site etc, i.e. it will work only on the root site.
Here the important thing is that these endless Users, AllUsers, SiteUsers, etc properties of SPWeb and SPSite, which may return different results depending on the context site, should not mislead you: users are created on site collection level.   
User Information List is a special one but still is a list and is bound to the web scope. So it is stored only in the root web of each site collection and you wouldn't find it in any subweb
In theory this list should be updated with user profile synchronization as well, but at first SharePoint may be used without user profiles, and second because of a lot of bugs in this process, on practice the most reliable way to force synchronization between user profiles and user information list is to delete user from the list explicitly and call SPWeb.EnsureUser(). We had similar situation and it was the only method which really worked (in our case it was more tricky: samAccountName of the user account in AD was changed, but as SID remained the same, Sharepoint still showed old account name).
If there is some users who’s details are showing differently in SharePoint than its AD value
You can try to sync the user profile with user Information List by below given Power shell script.
To fix the issue run the PowerShell as below. abcDomainName\pqrUserLoginId ---> abc is the domain and pqr is the user login.
$web=Get-SPWeb ...web URL...
$web|Set-SPUser -identity "abcDomainName\pqrUserLoginId" -SyncFromAD

The problem is the UserInformationList is stored in AllUserData table. This is not the UserInfo table. It is absolutely different portion of data. You can see its data by navigating to http://<SiteCollectionUrl>/_catalogs/users/detail.aspx. It is the site (Web scope) level data and the UserInformationList (hidden list) is created for the Root Web of each site collection. While UserInfostores data of the site collection level. Information in UserInfo table can be different from UserInformationList. So if i get the user from PowerShel I get the right display name.

$web = Get-SPWeb -Identity 'WebUrl'
$user = $web | Get-SPUser -Identity 'login'
$user.DisplayName

If I Remove users from User Information List


We can remove a user from the User Information List (UIL) in a site collection from SharePoint 2010 and 2013. SharePoint stores user information in the UIL to extract data when this user is being searched by the people picker, the people picker extracts information from multiple locations:
– The User Information List
– Active Directory

The people picker does not extract information from the User Profile Service Application (UPSA). The UPSA syncs information from the AD and updates the UIL but it does not delete the user from it.

For example if I will delete myself from the Active Directory and navigate back to SharePoint to see what happened.
– I can no longer log on with “myLogInName”
– I can still find “myLogInName” with the people picker.
– The permissions are still visible
I want to delete myLogInName user from the Site Collection so this user won’t be found by the people picker and the permissions will be deleted.

Solution
I can’t just click on the user and delete him because I’ll be redirected to the My Site (the My Site will be scheduled for deletion in 14 days by the My Site Cleanup Timer Job).
You will have to add the following right behind the URL
SharePoint 2010
<URL>/_layouts/people.aspx?MembershipGroupId=0

and click on “Actions –> Delete Users from Site Collection
After that
I can now
– no longer log on with “myLogInName”
– no longer find him using the people picker
– no longer find his permissions because they have been deleted
Downside is that you’ll receive the following error while clicking on this user at documents

With the following information from the ULS Viewer
System.ArgumentException: User cannot be found.
at Microsoft.SharePoint.SPList.GetItemById(String strId, Int32 id, String strRootFolder, Boolean cacheRowsetAndId, String strViewFields, Boolean bDatesInUtc)
at Microsoft.SharePoint.SPContext.get_Item()

Deleting users from UIL’s in bulk and across Site Collections
Please read the following blog from Nico Martens if you would like to delete users in bulk with PowerShell.
http://sharepointrelated.com/2012/10/11/remove-bulk-users-from-user-information-list-people-picker/

Timer Job that is working behind the User Information List?
To synchronize the User Profile user Data with user Information List there are two timer jobs that are responsible
  1. 1.      User Profile to SharePoint Quick Sync and
  2. 2.      User Profile to SharePoint Full Sync,
Can I set Alert on SharePoint User information list? Or Can I Track changes to the SharePoint User Information list.
How do you track the changes in "User Information List" without using any custom code? One way is to enable auditing under site collection administration for "Editing users and permissions". However this add an extra load to the database and may result in performance issues. Moreover his requirement was to track only when a user is added or removed from site collection. 
Another approached is to setup alerts. However, the User Information List does not have any option to setup alerts or go to setting etc as normal lists. So how can we configure alerts on the list?
1. Our first requirement was to get the GUID. To get this we queried dbo.Lists table in the content database holding this site collection.

2. The query should be: Select tp_ID From Lists with(NoLock)where tp_Title = 'User Information List'

3. Make a note of this ID, Now go to any other list in the top site in your site collection and click on Alert Me under Actions.

4. In the next page in URL remove the contents after ?List= and add the GUID noted in step 3.

5. Press enter and now you will find that the fields are populated with User Information List and you can create the alerts.
It is not possible to add event handlers to the user info list ?
 No, we cannot attach any event handler to User Information List. Please check the MS details on that on this article (http://msdn.microsoft.com/en-us/library/aa979520.aspx), we know that  “Lists:List events do not fire on the UserInfo list.”
       Another asynchronous was discussed in this post below:       we can think to create a service to monitor the change inUserInfo list, or get the modification logs from audit information is also a solid alternative.

Please see this following thread:

How user Information list is linked with SharePoint User Profile Service?
To keep all the information in the user information lists up to data with User profile and user Information list is a task that is handled by the Profile Synchronization and the Quick Profile Synchronization timer jobs. By default the first job runs once every hour, the second one runs every couple of minutes and is incremental. The first time user data is replicated from the user profile to the user information list of a site a full update is needed. So the Profile Synchronization job needs to run in order to get the data replicated to the site and this may take up to an hour. If information about a user is already stored in the user information list and the information changes in the user profile it will be synchronized with the data in the site collection by the  Quick Profile Synchronization job.
You can also kick off the profile synchronization jobs by running the stsadm sync command.
  stsadm -o sync

If you believe that information is not synced between the user profiles and the user information lists in one or more sites you can request a list of content databases that have not been synchronized for x number of days by using the following stsadm sync command.
 stsadm -o sync -listolddatabases <x number of days>
 If one or more content databases show up in this list you can clean up the sync list so they can be added to the list again.
 stsadm -o sync -deleteolddatabases <x number of days>
 You can also use the sync command to change the schedule for the synchronization job.
For more information on the stsadm sync command have a look here http://technet.microsoft.com/en-us/library/cc263196.aspx.
To synchronize the User Profile user Data with user Information List there are two timer jobs that are responsible
  1. 3.      User Profile to SharePoint Quick Sync and
  2. 4.      User Profile to SharePoint Full Sync,
That synchronize the User Profile database information with the UIL. Sometimes this stops working (properly) and in that case you need to run:
stsadm -o sync -listolddatabases 0
stsadm -o sync -deleteolddatabases 0
The first command will list Content Databases that haven't had the UPA -> UIL sync occur in 0 or more days. The second command will delete the records corresponding to those databases (it doesn't delete databases/end user data).
If still the issue is there you can delete the user from user Information list and run the user profile sync again to fix the issue.
How to access User information list using Server Object model?
// Get the List Object for User Information List
SPList userInformationList = SPContext.Current.Web.SiteUserInfoList;
// Get the Object of current logged in user
SPUser user = SPContext.Current.Web.EnsureUser(@"web");
// Here is actual User Information is within this SPListItem
SPListItem userItem = userInformationList.Items.GetItemById(user.ID);
The above code will give you the SPListItem object which links to the currently logged in user (the one executing the request) and you have almost all the details about the user you can play around it and user it further.
You can then work with the SPListItem object like normal to get or set the properties like this:
string userPictureURL = userItem["Picture"].ToString();


How to access User Information list using Client object model?
Here is the example of to get current log in user Id and show user Information by fetching from user Information list.
var contextObj = new SP.ClientContext.get_current();
    var webObj = contextObj.get_web();

    var userInfoListObj = webObj.get_siteUserInfoList();

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'ID\' />' +
                                '<Value Type=\'Number\'>' + userId + '</Value></Eq>' +
                                '</Where></Query><RowLimit>1</RowLimit></View>');

    this.userInfoListObj= userInfoListObj.getItems(camlQuery);

    contextObj.load(this.userListItem);

    contextObj.executeQueryAsync(
            Function.createDelegate(this, onSucceeded),
            Function.createDelegate(this, onFailed));

The onSucceeded function is called when the query runs successfully, otherwise the onFailed function will be executed.
function onSuceeded(sender, eventArgs)
{
        var item = this.userListItem.itemAt(0);
        var name = item.get_item('Name');
        var userName = "Name";

        if (name) {
            userName = name;
        }

        alert(userName);
}

We need to execute the code after SP.js is loaded SP.SOD.executeOrDelayUntilScriptLoaded(LoadUserInfo, 'SP.js');
How to access User information list for SharePoint online Site?
/_catalogs/users/detail.aspx is work in both Onpremise and SharePoint Online
How to access User Information list using powershell scripts.
You can write a PowerShell script(named ListWebUserInformationListItems.ps1) as following:
 # Run with SharePoint 2010 Management Shell
$webUrl = Read-Host "Enter the web url"
$web = Get-SPWeb $webUrl
$list = $web.Lists["User Information List"]
$query = New-Object Microsoft.SharePoint.SPQuery
$queryCamlString = '<Query><OrderBy><FieldRef Name="Title" Ascending="True" /></OrderBy></Query>'
$query.Query = $queryCamlString
$userInformationListItems = $list.GetItems($query)
foreach($userInformationListItem in $userInformationListItems)
{
    echo $userInformationListItem.Title
}

sábado, 18 de marzo de 2017

SharePoint 2010 Form based authentication problem Event ID:1315 and Event ID:8306

Assume that you have a SharePoint 2010 site with configured as Claim Based Authentiction with custom SQL Membership . You have move your site and membership database to another server and you have facing with connection problems on existing SQL MemberShip users by getting this fallowing errors
In ULS Logs:
11.13.2012 15:40:18.20 w3wp.exe (0x18C8) 0x17C8 SharePoint Foundation Claims Authentication 0000 Unexpected Password check on ‘user@mail.com’ generated exception: ‘System.ServiceModel.FaultException`1[Microsoft.IdentityModel.Tokens.FailedAuthenticationException]: The security token username and password could not be validated. (Fault Detail is equal to Microsoft.IdentityModel.Tokens.FailedAuthenticationException: The security token username and password could not be validated.).’.
11.13.2012 15:40:18.20 w3wp.exe (0x18C8) 0x17C8 SharePoint Foundation Claims Authentication fo1t Monitorable SPSecurityTokenService.Issue() failed: System.ServiceModel.FaultException`1[Microsoft.IdentityModel.Tokens.FailedAuthenticationException]: The security token username and password could not be validated. (Fault Detail is equal to Microsoft.IdentityModel.Tokens.FailedAuthenticationException: The security token username and password could not be validated.).
and In Event logs
Presence of Event ID 8306 in the Application Event Log
11/08/2012 03:29:11 PM Error SERVERA 8306 Microsoft-SharePoint Products-SharePoint Foundation Claims Authentication DOMAIN\User An exception occurred when trying to issue security token: The security token username and password could not be validated..
Presence of Event ID 1315 in the Application Event Log with Event code: 4006
Event message: Membership credential verification failed.
The problem is here if you try to login site with one of existing FBA user even password is correct , cound not able to validate password . If you create a new FBA user , there is no problem on login.
The main cause of this issue could be changes of the Machine Key.
Why ?
The Password information is stored in the aspnet_Membership table in Asp.Net Membership database . The   SqlMembershipProvider allows for passwords to be stored in the database    using one of the following three techniques:
  • Clear – the password is stored in the database as plain-text. I strongly        discourage using this option. If the database is compromised – be it by a hacker        who finds a back door or a disgruntled employee who has database access – every        single user’s credentials are there for the taking.
  • Hashed – passwords are hashed using a one-way hash algorithm and a randomly        generated salt value. This hashed value (along with the salt) is stored in the database.
  • Encrypted – an encrypted version of the password is stored in the database
The password storage technique used depends on the SqlMembershipProvider    settings specified in Web.config.  The default behavior is to    store the hash of the password.
the particular encryption or hashing algorithm used by the SqlMembershipProvider is determined by the settings in the <machineKey> element.
So if you have move your site to another server you may consider that the MachineKey if anyhow is changed , the existing users’ passwords can not be validated.
1) First Check for the MachineKey values in web.config for related your FBA SharePoint site. If you have any difference on target site make them equalize.
2) Also don’t forget to check other servers in your farm for the same site should be same MachineKey. If any difference in MachineKeys may cause integrity problems.
Somehow If the data integrity has broken , recreating users or forcing the users reset their password will help about the issue.