本文整理匯總了C#中System.ServiceModel.ServiceAuthorizationManager.CheckAccess方法的典型用法代碼示例。如果您正苦於以下問題:C# ServiceAuthorizationManager.CheckAccess方法的具體用法?C# ServiceAuthorizationManager.CheckAccess怎麽用?C# ServiceAuthorizationManager.CheckAccess使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.ServiceModel.ServiceAuthorizationManager
的用法示例。
在下文中一共展示了ServiceAuthorizationManager.CheckAccess方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CheckAccess
public class myServiceAuthorizationManager : ServiceAuthorizationManager
{
// Override the CheckAccess method to enforce access control requirements.
public override bool CheckAccess(OperationContext operationContext)
{
AuthorizationContext authContext =
operationContext.ServiceSecurityContext.AuthorizationContext;
if (authContext.ClaimSets == null) return false;
if (authContext.ClaimSets.Count != 1) return false;
ClaimSet myClaimSet = authContext.ClaimSets[0];
if (!IssuedBySTS_B(myClaimSet)) return false;
if (myClaimSet.Count != 1) return false;
Claim myClaim = myClaimSet[0];
if (myClaim.ClaimType ==
"http://www.tmpuri.org:accessAuthorized")
{
string resource = myClaim.Resource as string;
if (resource == null) return false;
if (resource != "true") return false;
return true;
}
else
{
return false;
}
}
// This helper method checks whether SAML Token was issued by STS-B.
// It compares the Thumbprint Claim of the Issuer against the
// Certificate of STS-B.
private bool IssuedBySTS_B(ClaimSet myClaimSet)
{
ClaimSet issuerClaimSet = myClaimSet.Issuer;
if (issuerClaimSet == null) return false;
if (issuerClaimSet.Count != 1) return false;
Claim issuerClaim = issuerClaimSet[0];
if (issuerClaim.ClaimType != ClaimTypes.Thumbprint)
return false;
if (issuerClaim.Resource == null) return false;
byte[] claimThumbprint = (byte[])issuerClaim.Resource;
// It is assumed that stsB_Certificate is a variable of type
// X509Certificate2 that is initialized with the Certificate of
// STS-B.
X509Certificate2 stsB_Certificate = GetStsBCertificate();
byte[] certThumbprint = stsB_Certificate.GetCertHash();
if (claimThumbprint.Length != certThumbprint.Length)
return false;
for (int i = 0; i < claimThumbprint.Length; i++)
{
if (claimThumbprint[i] != certThumbprint[i]) return false;
}
return true;
}
示例2: CheckAccessCore
public class myService_M_AuthorizationManager : ServiceAuthorizationManager
{
// set max size for message
int someMaxSize = 16000;
protected override bool CheckAccessCore(OperationContext operationContext, ref Message message)
{
bool accessAllowed = false;
MessageBuffer requestBuffer = message.CreateBufferedCopy(someMaxSize);
// do access checks using the message parameter value and set accessAllowed appropriately
if (accessAllowed)
{
// replace incoming message with fresh copy since accessing the message consumes it
message = requestBuffer.CreateMessage();
}
return accessAllowed;
}
}