Search in sources :

Example 1 with PrincipalAttributesRepository

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;
}
Also used : RegisteredServiceAttributeReleasePolicyStrategyEditBean(org.apereo.cas.mgmt.services.web.beans.RegisteredServiceAttributeReleasePolicyStrategyEditBean) ReturnAllAttributeReleasePolicy(org.apereo.cas.services.ReturnAllAttributeReleasePolicy) PrincipalAttributesRepository(org.apereo.cas.authentication.principal.PrincipalAttributesRepository) AbstractRegisteredServiceAttributeReleasePolicy(org.apereo.cas.services.AbstractRegisteredServiceAttributeReleasePolicy) GroovyScriptAttributeReleasePolicy(org.apereo.cas.services.GroovyScriptAttributeReleasePolicy) DenyAllAttributeReleasePolicy(org.apereo.cas.services.DenyAllAttributeReleasePolicy) ScriptedRegisteredServiceAttributeReleasePolicy(org.apereo.cas.services.ScriptedRegisteredServiceAttributeReleasePolicy) ReturnAllowedAttributeReleasePolicy(org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy) RegisteredServiceAttributeFilter(org.apereo.cas.services.RegisteredServiceAttributeFilter) ReturnMappedAttributeReleasePolicy(org.apereo.cas.services.ReturnMappedAttributeReleasePolicy) RegisteredServiceAttributeReleasePolicyEditBean(org.apereo.cas.mgmt.services.web.beans.RegisteredServiceAttributeReleasePolicyEditBean) Map(java.util.Map)

Example 2 with PrincipalAttributesRepository

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();
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) DefaultPrincipalAttributesRepository(org.apereo.cas.authentication.principal.DefaultPrincipalAttributesRepository) PrincipalAttributesRepository(org.apereo.cas.authentication.principal.PrincipalAttributesRepository)

Aggregations

PrincipalAttributesRepository (org.apereo.cas.authentication.principal.PrincipalAttributesRepository)2 Map (java.util.Map)1 DefaultPrincipalAttributesRepository (org.apereo.cas.authentication.principal.DefaultPrincipalAttributesRepository)1 RegisteredServiceAttributeReleasePolicyEditBean (org.apereo.cas.mgmt.services.web.beans.RegisteredServiceAttributeReleasePolicyEditBean)1 RegisteredServiceAttributeReleasePolicyStrategyEditBean (org.apereo.cas.mgmt.services.web.beans.RegisteredServiceAttributeReleasePolicyStrategyEditBean)1 AbstractRegisteredServiceAttributeReleasePolicy (org.apereo.cas.services.AbstractRegisteredServiceAttributeReleasePolicy)1 DenyAllAttributeReleasePolicy (org.apereo.cas.services.DenyAllAttributeReleasePolicy)1 GroovyScriptAttributeReleasePolicy (org.apereo.cas.services.GroovyScriptAttributeReleasePolicy)1 RegisteredServiceAttributeFilter (org.apereo.cas.services.RegisteredServiceAttributeFilter)1 ReturnAllAttributeReleasePolicy (org.apereo.cas.services.ReturnAllAttributeReleasePolicy)1 ReturnAllowedAttributeReleasePolicy (org.apereo.cas.services.ReturnAllowedAttributeReleasePolicy)1 ReturnMappedAttributeReleasePolicy (org.apereo.cas.services.ReturnMappedAttributeReleasePolicy)1 ScriptedRegisteredServiceAttributeReleasePolicy (org.apereo.cas.services.ScriptedRegisteredServiceAttributeReleasePolicy)1 ApplicationContext (org.springframework.context.ApplicationContext)1