Activate Custom Claims Provider In SharePoint 2013 Using Windows PowerShell

Introduction

A custom claims provider issues claims and packages claims into the security tokens, which can be used to give permission to the items in a customized way. Claims augmentation enables an application to augment the additional claims into the user token. Claims can be displayed in the people picker control through claims picking. In this article, I will explain how to activate Custom Claims Provider in SharePoint 2013, using Windows PowerShell.

Pre-Requisites

  1. Open Visual Studio.
  2. Open New Project dialog box. Expand Office/SharePoint node and then choose SharePoint solutions.

    New Project

  3. Choose SharePoint 2013 – Empty project template. Name the project as ClaimProviderProject.

    Empty

  4. Choose the Deploy as a farm solution option button and choose Finish button.

    Deploy

  5. To create a custom claims provider class file, right click ClaimProviderProject project -> Add -> New Item.

     New Item

  6. Add the class file and name it as CustomClaimsProvider.cs.

    Add the class file

  7. Complete the implementation of custom claims provider class by overriding the SPClaimProvider properties and methods.

Activate Custom Claims Provider

  1. Build this solution and take the WSP file.
  2. Using Windows PowerShell, add WSP file to SharePoint.

    Add-SPSolution "D:\New folder\ClaimProviderProject\ClaimProviderProject\bin\Debug\ClaimProviderProject.wsp"

    windows PowerShell Add WSP file

  3. Install WSP file to our Web Application.
    1. Install-SPSolution -WebApplication "http:\\www.siteURL.com" -GACDeployment   
    2.   
    3. -FullTrustBinDeployment -Identity Ascentn.SharePoint.SettingsList.wsp   
    4.   
    5. -CompatibilityLevel All   
    Install WSP file

  4. Deploy the installed WSP file and enable the Claims provider feature at Farm solution level.
    1. Enable-SPFeature -Url "http:\\www.siteURL.com" -Identity CustomClaimsProvider   
    Deploy the WSP file

  5. Check whether the custom claims provider is enabled or not, using the script, given below-
    1. Get-SPClaimProvider -Identity "CustomClaimsProvider"   
    script

  6. Set the IsEnabled to True for the claim provider, if it is not enabled, using the script, given below-
    1. $kdealerClaimProviderDisplayName = "Custom Claims Provider"  
    2. $manager = Get - SPClaimProviderManager  
    3. $providers = $manager.ClaimProviders  
    4. $provider = $providers | ? {  
    5.     $_.DisplayName - eq $kdealerClaimProviderDisplayName  
    6. } | Select - First 1  
    7. $provider.IsEnabled = $True  
    8. $manager.Update()  
    script

  7. Add the provider association to the Web Application, using the script, given below-
    1. $webUrl = "http://www.siteURL.com"  
    2. $zone = "Default"  
    3. $claimProviderInternalName = "CustomClaimsProvider"  
    4. $webApplication = Get - SPWebApplication $webUrl  
    5. if ($webApplication.IisSettings.ContainsKey($zone))   
    6. {  
    7.     $settings = $webApplication.GetIisSettingsWithFallback($zone)  
    8.     $providers = $settings.ClaimsProviders  
    9.     if (-not($providers.Contains($claimProviderInternalName))) {  
    10.         $providers += $claimProviderInternalName  
    11.         Set - SPWebApplication - Identity $WebApplication - Zone $Zone - AdditionalClaimProvider $providers  
    12.         Write - Host "Registered $claimProviderInternalName on $($webApplication.Url) in zone $zone"  
    13.     } else {  
    14.         Write - Host "$claimProviderInternalName already registered on $($webApplication.Url) in zone $zone"  
    15.     }  
    16. }  
    Add provider association
      
  8. Check whether the custom claims provider is populated in the assigning permission to an item or not.

    assigning permission

Summary

Thus, you have learned, how to activate custom claims provider in SharePoint 2013, using Windows PowerShell.