use of org.apereo.cas.authentication.principal.PrincipalAttributesRepository in project cas by apereo.
the class DefaultAttributeReleasePolicyMapper method toAttributeReleasePolicy.
@Override
public RegisteredServiceAttributeReleasePolicy toAttributeReleasePolicy(final RegisteredServiceEditBean.ServiceData data) {
final RegisteredServiceAttributeReleasePolicyEditBean attrRelease = data.getAttrRelease();
final RegisteredServiceAttributeReleasePolicyStrategyEditBean policyBean = attrRelease.getAttrPolicy();
final String policyType = policyBean.getType();
final AbstractRegisteredServiceAttributeReleasePolicy policy;
if (StringUtils.equalsIgnoreCase(policyType, AbstractRegisteredServiceAttributeReleasePolicyStrategyBean.Types.SCRIPT.toString())) {
policy = new ScriptedRegisteredServiceAttributeReleasePolicy(policyBean.getScriptFile());
} else if (StringUtils.equalsIgnoreCase(policyType, AbstractRegisteredServiceAttributeReleasePolicyStrategyBean.Types.GROOVY.toString())) {
policy = new GroovyScriptAttributeReleasePolicy(policyBean.getScriptFile());
} else if (StringUtils.equalsIgnoreCase(policyType, AbstractRegisteredServiceAttributeReleasePolicyStrategyBean.Types.ALL.toString())) {
policy = new ReturnAllAttributeReleasePolicy();
} else if (StringUtils.equalsIgnoreCase(policyType, AbstractRegisteredServiceAttributeReleasePolicyStrategyBean.Types.ALLOWED.toString())) {
policy = new ReturnAllowedAttributeReleasePolicy((List) policyBean.getAttributes());
} else if (StringUtils.equalsIgnoreCase(policyType, AbstractRegisteredServiceAttributeReleasePolicyStrategyBean.Types.MAPPED.toString())) {
policy = new ReturnMappedAttributeReleasePolicy((Map) policyBean.getAttributes());
} else if (StringUtils.equalsIgnoreCase(policyType, AbstractRegisteredServiceAttributeReleasePolicyStrategyBean.Types.DENY.toString())) {
policy = new DenyAllAttributeReleasePolicy();
} else {
policy = new ReturnAllowedAttributeReleasePolicy();
}
policy.setAuthorizedToReleaseCredentialPassword(attrRelease.isReleasePassword());
policy.setAuthorizedToReleaseProxyGrantingTicket(attrRelease.isReleaseTicket());
policy.setExcludeDefaultAttributes(attrRelease.isExcludeDefault());
final RegisteredServiceAttributeFilter filter = this.attributeFilterMapper.toAttributeFilter(data);
if (filter != null) {
policy.setAttributeFilter(filter);
}
final PrincipalAttributesRepository principalRepository = this.principalAttributesRepositoryMapper.toPrincipalRepository(data);
if (principalRepository != null) {
policy.setPrincipalAttributesRepository(principalRepository);
}
return policy;
}
use of org.apereo.cas.authentication.principal.PrincipalAttributesRepository in project cas by apereo.
the class AbstractRegisteredServiceAttributeReleasePolicy method resolveAttributesFromPrincipalAttributeRepository.
/**
* Resolve attributes from principal attribute repository.
*
* @param principal the principal
* @return the map
*/
protected Map<String, Object> resolveAttributesFromPrincipalAttributeRepository(final Principal principal) {
PrincipalAttributesRepository repository = getPrincipalAttributesRepository();
if (repository == null) {
LOGGER.debug("No principal attribute repository is defined for the service. Evaluating global attribute caching policy...");
final ApplicationContext applicationContext = ApplicationContextProvider.getApplicationContext();
if (applicationContext != null) {
if (applicationContext.containsBean("globalPrincipalAttributeRepository")) {
LOGGER.debug("Loading global principal attribute repository with caching policies...");
repository = applicationContext.getBean("globalPrincipalAttributeRepository", PrincipalAttributesRepository.class);
} else {
LOGGER.warn("No global principal attribute repository can be located from the application context.");
}
}
}
if (repository != null) {
LOGGER.debug("Using principal attribute repository [{}] to retrieve attributes", repository);
return repository.getAttributes(principal);
}
return principal.getAttributes();
}
Aggregations