SharePoint 2013/2016 – Migrate from Windows claims to ADFS

Many farms are moving from Windows Authentication(NTLM or Kerberos) to SAML. This migration and change requires a lot of planning. This guide is only to give a frame work of migrating some of the simpler farms. This guide also assumes that the ADFS server is already setup and just needs to be configured.

The difference of this guide and other guides are two things. We will be using the -UseDefaultConfiguration when created the trusted identity token issuer. This will give us an OOB claims provider instead of having your farm fending for itself with the people picker/claim provider. The next difference is the user and group migrations. We will be using Convert-SPWebapplication instead of developing a script to use Move-SPUser. More details later in the post about both of these.

Requirements:

  1. The SharePoint farm has to be at June 2014 CU (or higher) for SharePoint 2013(15.0.4623.1001).
  2. The web applications must be Windows Claims. SAML is not supported on classic.
  3. ADFS must be backed with the same Active Directory used in Windows Claims.

Steps to be completed:

  1. Configure ADFS
  2. Creating Trusted Identity Provider
  3. Migrate Users and Groups

Config ADFS

As stated above we assume the ADFS server is setup and connected to AD and ready to configure the Relying Party Trusts.

  1. In AD FS, right click Relying Party Trusts and select Add Relying Party Trust.


  2. This will bring up Add Relying Party Trust Wizard. Click Start


  3. Click Enter data about the relying party manually, Next.


  4. Type in a display name and description(optional). Click Next.


  5. We want to select AD FS 1.0 and 1.1 profile since SharePoint does not support anything but SAML 1.1.


  6. We will need to enter in the web application with /_trust. This will need to be HTTPS.


  7. We will need to add in the realm for an identifier. I entered in urn:sp13:contoso. We will be using this on the SharePoint side.


  8. I’m not using Multi-factor so just clicking Next


  9. We’re permitting everybody through. Click Next


  10. Click Next


  11. Click Close and leave the box checked. We will be mapping claims.


  12. In the Issuance Transform Rules, click Add Rule…


  13. Leave the drop down value at Send LDAP Attributes as Claims. Click Next


  14. Give the claim rule a name. Select Active Directory from the dropdown.


  15. We will only be mapping the required fields here. The first one we will map is your identifier claim. This is the claim that a user needs to have in AD to sign in. The only choices Account-Name, Email or USER-PRINCIPAL-NAME. Adjust your guide as needed. I will be using Email. The only other Claim is for security groups.


LDAP Attribute Outgoing Claim Type
User-Principal-Name UPN
E-Mail-Address E-Mail Address
SAM-Account-Name Windows account name
Token-Groups as SIDs Group SID
  1. We will need the Token-sign certificate from ADFS. Click on Certificates, then click on the token-signing certificate, then View Certificate


  2. Click on Details tab and Copy to File…


  3. DER .CER is the file format we want. Click Next


  4. Give the file a name and location. Click Next


  5. Click Finish. Copy the certificate to the SharePoint server.


Creating Trusted Identity Provider

  1. On the SharePoint server, open PowerShell ISE. We will be loading the SharePoint module using Add-PSSnapin *sharepoint*


  2. This is to set the path of the token signing certificate we got from ADFS
$adfscertPath = “c:\adfstoken.cer” 
$adfscert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($adfsCertPath)

3. We want SharePoint to trust the certificate.

New-SPTrustedRootAuthority -Name “ADFS Token Signing Cert” -Certificate $adfscert

4. The script to create the trusted provider in SharePoint.

The -Realm is what we put in as an identifier for ADFS(urn:sp13:contoso)

The -IdentifierClaimIs can only be ACCOUNT-NAME, EMAIL, or USER-PRINCIPAL-NAME.


$ap = New-SPTrustedIdentityTokenIssuer -Name “ADFS” -Description “ADFS provider” -Realm “urn:sp13:contoso” -ImportTrustCertificate $adfscert -signInURL “https://adfs.contoso.com/adfs/ls” -UseDefaultConfiguration -IdentifierClaimIs EMAIL

 We can add in more claims after the trusted provider is created. Example is below of adding a role claim.

$ap = Get-SPTrustedIdentityTokenIssuer “ADFS”
$ap.ClaimTypes.Add(“http://schemas.microsoft.com/ws/2008/06/identity/claims/role”)
$map = New-SPClaimTypeMapping “http://schemas.microsoft.com/ws/2008/06/identity/claims/role” -IncomingClaimTypeDisplayName “Role” -SameAsIncoming
$ap.AddClaimTypeInformation($map)
$ap.Update()

5. Associate the new trusted provider to your web application(s). In central admin, select Application Management, then Manage web applications. Select your web application, then Authentication Providers. For each zone, select Windows Authentication and Trust Identity provider. Both are required for the migration.


Migrate Users and Groups

The migration of users and groups are very similar to the migration scripts with a difference of the groups. The groups will change from Windows claim + SID to ADFS + SID. Other migrations are passing the unqualified name through the SAML token. The claim provider that is provisioned will not show you the SID just like Windows does either.

The PowerShell we will be running is Convert-SPWebApplication.

$wa = get-spwebapplication https://contoso
Convert-SPWebApplication -Identity $wa -From CLAIMS-WINDOWS -To CLAIMS-TRUSTED-DEFAULT -TrustedProvider $ap -RetainPermissions 

This will need to be run on each web application. After the conversion is done, you can disable the Windows Authentication.

People picker will have two results for all users that have an Email address in Active Directory. The ADFS results is the one we would want to select.


Resources

The Convert-SPWebApplication command cannot convert from Windows claims to SAML in SharePoint Server 2013 – https://support.microsoft.com/en-us/help/3042604/the-convert-spwebapplication-command-cannot-convert-from-windows-claim

Configure SAML-based claims authentication with AD FS in SharePoint 2013 – https://technet.microsoft.com/en-us/library/hh305235.aspx

SharePoint – FBA – 8306 – The security token username and password could not be validated.

Forms based authentication(FBA) can have general bucket errors. In this blog post, I will be going over the 8306. This one seems to stump many people and can be difficult to trouble shoot if we don’t know where to start.

 

What flavor of FBA?

FBA can come in various deployments with the backend being SQL, .NET, etc. The most common being LDAP which I will be using in this post for the 8306. The deployment documents for this is in the following TechNet articles.

2013 – https://technet.microsoft.com/en-us/library/ee806890.aspx

2010 – https://technet.microsoft.com/en-us/library/ee806890(v=office.14).aspx

 

What Process is tossing 8306?

The error that we’re chasing down can be reproduced in any environment with FBA. The text of the error states we have failed to issue a token.

Log Name: Application

Source: Microsoft-SharePoint Products-SharePoint Foundation

Date: 12/23/2017 3:00:50 PM

Event ID: 8306

Task Category: Claims Authentication

Level: Error

Keywords:

User: contoso\mosssvc

Computer: WFE1.contoso.com

Description:

An exception occurred when trying to issue security token: The security token username and password could not be validated..

This is being tossed by the web application’s application pool(0x2AD0) but really it’s bubbling up from the Security Token Service.

ULS logs shows us the exception for the web app:


Here you can see the failure happen earlier in the request(filter by correlationID) in the STS:


With this information we need to take a Network trace from the WFE since it’s making the request to the DC(Domain Controller). I use a tool called Netmon 3.4 We can check the web.config of the STS to see where we are pointing to verifying the username and password.

<membership>

<providers>

<add name=”membership”

type=”Microsoft.Office.Server.Security.LdapMembershipProvider, Microsoft.Office.Server, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”


server=”yourserver.com”

port=”389″

useSSL=”false”

userDNAttribute=”distinguishedName”

userNameAttribute=”sAMAccountName”

userContainer=”OU=UserAccounts,DC=internal,DC=yourcompany,DC=com”

userObjectClass=”person”

userFilter=”(&amp;(ObjectClass=person))”

scope=”Subtree”

otherRequiredUserAttributes=”sn,givenname,cn” />

</providers>

</membership>

LDAP is used over ports 386 and 636(SSL). Netmon has standard filters that can be applied.


Netmon on the WFE:


The Netmon here show that we’re not getting any response from the DC which is one example of this error. Others may manifest itself as different issues all together.

Root Cause?

The ULS logs usually just says it failed while trying to validate the Username and Password.

12/23/2017 16:09:35.77    w3wp.exe (0x5A80)    0x92C0    SharePoint Foundation    Claims Authentication    fo1t    Monitorable    STS Call: Failed to issue new security token. 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.).    7580399e-8900-708b-67e2-ab7bcf6013a3

Here are the most common reasons you’ll see 8306 in your FBA deployment:

  1. Somebody put in the wrong username and password
  2. Communication with the DC(in my example above I had a firewall block LDAP traffic)
  3. Misconfiguration of the web.configs

The first reason is odd one, but it’s true. Putting in incorrect credentials will toss a 8306 with the same text as above (The user name and password is not validated.). If you’re seeing inconsistent results, you might have a DC that isn’t responding correctly which the Netmon will be valuable to isolate the issue to one WFE or DC that is affected.

The Pitfalls of Resetting the Config Cache

I see many SharePoint admins resetting the config cache but not knowing what it is or what it does.  This seems to be a go to action for anything wrong with SharePoint along with IISReset, PSConfig, and rebooting the servers.

What is the Config Cache?

The config cache is a copy of your objects table from your configuration database.  The location for the config cache cannot be changed.

Location: C:\ProgramData\Microsoft\SharePoint\Config\<GUID of ConfigDatabase>

We may see multiple folders due to the number of Config Databases(farms) the server has been connected to.

The config cache is updated and mostly used by OWSTimer.  If the config cache has incorrect formatted XML, the OWSTimer will fail to initialize(also will fail if it doesn’t complete the rebuild).

Cache.INI

The folder will contain many XML files and one cache.ini.  The cache.ini controls the version of the config cache.  This integer value controls the version of the config cache.

Setting it to 1 will make the entire cache to rebuild.

Config Database location:

<GUID>.XML

The files are objects from the object table.  The file name is the GUID.  Inside you can see the version number and other information about object.  Each time an object is updated the cache.ini will be updated.

When to reset?

Resetting the config cache will not fix most things.  Update conflicts happen when the refresh does not happen automatically.  The object is newer in the ConfigDB than on that server’s config cache.

Only reset the config cache when you see the following in the Application Logs(Event Viewer):

Log Name:      Application

Source:        Microsoft-SharePoint Products-SharePoint Foundation

Date:          12/20/2017 8:46:23 AM

Event ID:      6398

Task Category: Timer

Level:         Critical

Keywords:

User:          domain\farmaccount

Computer:      SharePointServer

Description:

The Execute method of job definition Microsoft.SharePoint.Diagnostics.SPDiagnosticsMetricsProvider (ID 0a77ce6a-69d3-47d4-86ae-56c772fd498d) threw an exception. More information is included below.

An update conflict has occurred, and you must re-try this action. The object SPWebService was updated by domain\farmaccount, in the OWSTIMER (9920) process, on machine SharePointServer.  View the tracing log for more information about the conflict.

It doesn’t hurt anything, right?

There are some possible negative effects when trying to reset the configuration cache.  Resetting the config cache on large farms will cause performance issues and/or take down your farm.  I’m talking more about those fancy scripts on the web that try to rebuild the cache across the entire farm in parallel.  Just do it manually, one server at a time.  This can cause SQL to lock the objects table and may fail to rebuild the config cache or take days to rebuild.

Config Cache while rebuilding

The config cache is done rebuilding after the cache.ini is no longer locked by OWSTimer.exe and has a value other than 1.

After the build is done, you’ll see numerous XML files and the cache.ini should be showing the version of the config cache.

Bottom line…

The issue we are trying to fix is unlikely to be fixed by resetting the config cache.  ULS logs are always the best place to look before taking action that may not be needed.   Manual reset, one server at a time is the way to do it if you’re looking to reset it.

User Profile Picture Import with Active Directory Import(Dirsync)

UPDATE 8/16/17 My colleague, Josh, wrote a great post on his blog detailing the benefits and considerations when moving to ADI. https://joshroark.com/sharepoint-considerations-when-switching-from-fim-sync-to-ad-import/

UPDATE 1/16/19 New version of this script and details located here: https://adamsorenson.com/sharepoint-profile-picture-import-1-3/

SharePoint 2013 introduced Active Directory Import. This is built on a technology called DirSync. There are many advantages with using Active Directory Import. We do not need to start up the User Profile Synchronization service and the syncs are many times faster than FIM. SharePoint 2016 only has two options: External Identity Provider(MIM) or Active Directory Import. This script will import profile pictures from Active Directory to SharePoint using DirSync. You can have your pictures imported and use Active Directory Import. This assumes your user profiles are being imported and populated. This will require your account to have Replicate Directory Changes for your domain as you would for SharePoint. I would suggest using the same account that you are using to sync users in SharePoint.

Scroll to the bottom for the entire script. Make sure to create the DNLookup.xml

There is logging and even a write to disk so you can see the pictures that were imported. Logs and the pictures will be written to $location. Here are the variables that will need to be changed to your environment:

$Location = “C:\Dirsync\”
#First time running, just run “DirSync” then “UploadPicture $adusers”
#Update RootDSE to match your domain
$RootDSE = [ADSI]”LDAP://dc=contoso,dc=com”
$site = Get-SpSite http://MySiteHost
$domain = “contoso\”
#This will write the pictures to the folder specified in $location
$write2disk = $true
#LDAP filter that is currently set to pull in users with thumbnailphoto and not disabled users.
$LDAPFilter = “(&(objectCategory=person)(objectclass=user)(thumbnailphoto=*)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))”
#Set $UseDifferentSvcAccount to true to be prompted for a different service account. False will use the user that is running the script to connect to AD.
$UseDifferentSvcAccount = $false
We also need a DNLookup.xml in the $location file. We need the DNLookup just like SharePoint does since DirSync returns DN. Create that file and fill it with this sample data:

<Users>
<UR>
<dn>CN=aa,ou=hh</dn>
<sAMAccountName>PlaceholderAccountDonotdelete</sAMAccountName>
</UR>
<UR>
<dn>CN=bb,ou=hh</dn>
<sAMAccountName>PlaceholderAccountDonotdelete2</sAMAccountName>
</UR>
</Users>
The first time you run this script it will run a full sync. The cookie.bin will be populated. This will require your account to have Replicate Directory Changes(same requirement for SharePoint) for your domain as you would for SharePoint. I would suggest using the same account that you are using to sync users in SharePoint.

NOTE: We still need to run Update-SPProfilePhotoStore to create the thumbnails

Download the script from Github