サンプル 1: クレーム プロバイダーを記述する
最終更新日: 2010年8月3日
適用対象: SharePoint Foundation 2010
クレーム プロバイダーのサンプル
クレーム プロバイダーを記述するには、まず、SPClaimProvider クラスから派生するクラスを作成します。次の例は、クレーム プロバイダーを記述する方法を示しています。この例の実装では、エンティティ、階層、解決、または検索をサポートしません。このトピックは、読者が既に「[方法] クレーム プロバイダーを作成する」を読んでいることを前提としています。
クレーム プロバイダーの作成の詳細とチュートリアルについては、「クレームに関するチュートリアル: SharePoint 2010 のクレーム プロバイダーを記述する」を参照してください。
![]() |
---|
追加のコード例、および SPClaimProvider クラスとそのメンバーの詳細については、「SPClaimProvider」を参照してください。また、「SharePoint SPIdentity Team Blog」および「Share-n-dipity (英語)」を定期的に確認し、追加の例と更新がないかどうかを確かめてください。 |
using System;
using System.Collections.Generic;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Administration.Claims;
using Microsoft.SharePoint.Diagnostics;
namespace MySample.Sample.Server.SampleClaimsProvider
{
/// <summary>
/// The SampleNameIdClaimsProvider class is a claims provider for an security token service(STS).
/// This claims provider inserts a NameIdentifier
/// (https://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier)
/// claim type in the SAML token issued by the STS.
/// The value of this claim type is the SharePointID of the user requesting the SAML token.
/// </summary>
[Microsoft.SharePoint.Security.SharePointPermission(System.Security.Permissions.SecurityAction.Demand, ObjectModel = true)]
[Microsoft.SharePoint.Security.SharePointPermission(System.Security.Permissions.SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SampleNameIdClaimsProvider : SPClaimProvider
{
#region Constructor
/// <summary>
/// Constructor for the SampleNameIdClaimsProvider class. It sets the displayName
/// of the claims provider, which is displayed in the Central Administration user interface for
/// people picker name resolution.
/// </summary>
/// <param name="displayName">String that gets displayed in the Central Administration user interface
/// for people picker name resolution.</param>
public SampleNameIdClaimsProvider (string displayName) : base(displayName)
{
}
#endregion Constructor
#region Private Methods/Properties
/// <summary>
/// Returns the URI of the SampleNameIdClaimsProvider claim.
/// </summary>
/// <returns>String representing the URI for a claim that specifies the name of an entity.</returns>
private static string SampleNameIdClaimType
{
get{ return "https://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier"; }
}
/// <summary>
/// Returns the value type of the SampleNameIdClaimsProvider claim.
/// </summary>
/// <returns>String representing the value type of the NameIdentifier claim.</returns>
private static string SampleNameIdClaimValueType
{
get{ return Microsoft.IdentityModel.Claims.ClaimValueTypes.String; }
}
#endregion Private Methods/Properties
#region Protected Methods
/// <summary>
/// This is the main function of the SampleNameIdClaimsProvider.
/// It creates a SampleNameId claim, sets SharePointID as its value,
/// and then adds this claim to the SPClaim list claims.
/// </summary>
/// <param name="context">URI context of the request.</param>
/// <param name="entity">SharePointID of the entity requesting the claim.</param>
/// <param name="claims">SPClaim generic list where SampleNameId claim is added.</param>
/// <returns>void</returns>
protected override void FillClaimsForEntity(Uri context, SPClaim entity, List<SPClaim> claims)
{
if (null == entity)
{
throw new ArgumentNullException("entity");
}
if(null == claims)
{
throw new ArgumentNullException("claims");
}
//Adding the SampleNameId claims to the claims list and setting SharePointID as its value.
claims.Add(CreateClaim(SampleNameIdClaimType, entity.Value, SampleNameIdClaimValueType));
}
/// <summary>
/// This function adds the claims types that will be added from this claims provider.
/// </summary>
/// <param name="claimTypes">String generic list where claims URIs will be added.</param>
/// <returns>void</returns>
protected override void FillClaimTypes(List<string> claimTypes)
{
if(null == claimTypes)
{
throw new ArgumentNullException("claimTypes");
}
// Add the claim types that will be added by this claims provider.
claimTypes.Add(SampleNameIdClaimType);
}
/// <summary>
/// This method adds the valueTypes of the claimTypes that will be placed
/// into the SAML token.
/// Note: The claimValueTypes should be in the same order as the claimTypes.
/// </summary>
/// <param name="claimValueTypes>List where claim value types will be added.</param>
/// <returns>void</returns>
protected override void FillClaimValueTypes(List<string> claimValueTypes)
{
if(null == claimValueTypes)
{
throw new ArgumentNullException("claimValueTypes");
}
//Adding the SampleNameId claim value type.
claimValueTypes.Add(NameIdentifierClaimValueType);
};
#region Non-Implemented
/// <summary>
/// This function adds all the entity types that this claims provider will
/// be supporting for people picker. In this example, this functionality is not supported.
/// </summary>
protected override void FillEntityTypes(List<string> entityTypes)
{
throw new NotImplementedException();
}
/// <summary>
/// This function adds the hierarchy to the hierarchy tree. This functionality is also
/// used for people picker. In this example, this functionality is not supported.
/// </summary>
protected override void FillHierarchy(Uri context, string[] entityTypes, string hierarchyNodeID, int numberOfLevels, Microsoft.SharePoint.WebControls.SPProviderHierarchyTree hierarchy)
{
throw new NotImplementedException();
}
/// <summary>
/// This method is used to resolve multiple claims. This functionality is also
/// used for people picker. In this example this functionality is not supported.
/// </summary>
protected override void FillResolve(Uri context, string[] entityTypes, SPClaim resolveInput, List<Microsoft.SharePoint.WebControls.PickerEntity> resolved)
{
throw new NotImplementedException();
}
/// <summary>
/// This method is used to resolve multiple claims. This functionality is also
/// used for people picker. In this example, this functionality is not supported.
/// </summary>
protected override void FillResolve(Uri context, string[] entityTypes, string resolveInput, List<Microsoft.SharePoint.WebControls.PickerEntity> resolved)
{
throw new NotImplementedException();
}
/// <summary>
/// This method is used to fill schema. This functionality is also
/// used for people picker. In this example, this functionality is not supported.
/// </summary>
protected override void FillSchema(Microsoft.SharePoint.WebControls.SPProviderSchema schema)
{
throw new NotImplementedException();
}
/// <summary>
/// This method is used to enable search. This functionality is also
/// used for people picker. In this example, this functionality is not supported.
/// </summary>
protected override void FillSearch(Uri context, string[] entityTypes, string searchPattern, string hierarchyNodeID, int maxCount, Microsoft.SharePoint.WebControls.SPProviderHierarchyTree searchTree)
{
throw new NotImplementedException();
}
#endregion NULL-Implementation
#endregion Protected Methods
#region Public Methods
/// <summary>
/// Returns the name of the claims provider. This name should be unique and you
/// must ensure that this name does not clash with the existing claims provider.
/// </summary>
/// <returns>String containing unique name for the claims provider.</returns>
public override string Name
{
get{ return SampleNameIdClaimProvider.SampleClaimProviderName; }
}
/// <summary>
/// Returns the name of the claims provider. This name should be unique and you
/// must ensure that this name does not clash with the existing claims provider.
/// </summary>
/// <returns>String containing unique name for the claim provider.</returns>
internal static string SampleClaimProviderName
{
get{ return "SampleClaimsProvider"; }
}
/// <summary>
/// Informs whether the claims provider supports entity information. The claims provider
/// infrastructure adds the claims only if this SupportsEntityInformation property is true.
/// </summary>
/// <returns>true, representing entity information is supported.</returns>
public override bool SupportsEntityInformation
{
get{ return true; }
}
/// <summary>
/// Informs whether hierarchy is supported. This is used for people picker functionality.
/// In this example, this functionality is not supported; therefore it is set to false.
/// </summary>
/// <returns>false, representing entity information is not supported.</returns>
public override bool SupportsHierarchy
{
get{ return false; }
}
/// <summary>
/// Informs whether resolve entity feature is supported. This is used for people picker functionality.
/// In this example, this functionality is not supported; therefore it is set to false.
/// </summary>
/// <returns>false, representing entity information is not supported.</returns>
public override bool SupportsResolve
{
get{ return false; }
}
/// <summary>
/// Informs whether search functionality is supported on the basis of claims value.
/// In this example, this functionality is not supported; therefore it is set to false.
/// </summary>
/// <returns>false, representing search is not supported.</returns>
public override bool SupportsSearch
{
get{ return false; }
}
#endregion Public Methods
}
}