本文整理汇总了C#中Principal.getAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Principal.getAttributes方法的具体用法?C# Principal.getAttributes怎么用?C# Principal.getAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Principal
的用法示例。
在下文中一共展示了Principal.getAttributes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: determinePrincipalIdForRegisteredService
/**
* Determines the principal id to use for a {@link RegisteredService} using the following rules:
*
* <ul>
* <li> If the service is marked to allow anonymous access, a persistent id is returned. </li>
* <li> If the attribute name matches {@link RegisteredService#DEFAULT_USERNAME_ATTRIBUTE}, then the default principal id is returned.</li>
* <li>If the service is set to ignore attributes, or the username attribute exists in the allowed attributes for the service,
* the corresponding attribute value will be returned.
* </li>
* <li>Otherwise, the default principal's id is returned as the username attribute with an additional warning.</li>
* </ul>
*
* @param principal The principal object to be validated and constructed
* @param registeredService Requesting service for which a principal is being validated.
* @param serviceTicket An instance of the service ticket used for validation
*
* @return The principal id to use for the requesting registered service
*/
private string determinePrincipalIdForRegisteredService(Principal principal, RegisteredService registeredService,
ServiceTicket serviceTicket)
{
string principalId = null;
string serviceUsernameAttribute = registeredService.getUsernameAttribute();
if (registeredService.isAnonymousAccess())
{
principalId = this.persistentIdGenerator.generate(principal, serviceTicket.getService());
}
else if (string.IsNullOrEmpty(serviceUsernameAttribute))
{
principalId = principal.getId();
}
else
{
if ((registeredService.isIgnoreAttributes() || registeredService.getAllowedAttributes().Contains(serviceUsernameAttribute)) &&
principal.getAttributes().ContainsKey(serviceUsernameAttribute))
{
principalId = principal.getAttributes().First(x => x.Key == registeredService.getUsernameAttribute()).Value.ToString();
}
else
{
principalId = principal.getId();
Object[] errorLogParameters = new Object[] { principalId, registeredService.getUsernameAttribute(),
principal.getAttributes(), registeredService.getServiceId(), principalId };
//log.warn("Principal [{}] did not have attribute [{}] among attributes [{}] so CAS cannot "
// + "provide on the validation response the user attribute the registered service [{}] expects. "
// + "CAS will instead return the default username attribute [{}]", errorLogParameters);
}
}
//log.debug("Principal id to return for service [{}] is [{}]. The default principal id is [{}].",
// new Object[] {registeredService.getName(), principal.getId(), principalId});
return principalId;
}