Search in sources :

Example 6 with ShibbolethCompatiblePersistentIdGenerator

use of org.apereo.cas.authentication.principal.ShibbolethCompatiblePersistentIdGenerator in project cas by apereo.

the class DefaultUsernameAttributeProviderMapper method toUsernameAttributeProvider.

@Override
public RegisteredServiceUsernameAttributeProvider toUsernameAttributeProvider(final ServiceData data) {
    final RegisteredServiceUsernameAttributeProviderEditBean userAttrProvider = data.getUserAttrProvider();
    final String uidType = userAttrProvider.getType();
    if (StringUtils.equalsIgnoreCase(uidType, RegisteredServiceUsernameAttributeProviderEditBean.Types.DEFAULT.toString())) {
        return new DefaultRegisteredServiceUsernameProvider();
    } else if (StringUtils.equalsIgnoreCase(uidType, RegisteredServiceUsernameAttributeProviderEditBean.Types.ANONYMOUS.toString())) {
        final String salt = userAttrProvider.getValue();
        if (StringUtils.isNotBlank(salt)) {
            final ShibbolethCompatiblePersistentIdGenerator generator = new ShibbolethCompatiblePersistentIdGenerator(salt);
            return new AnonymousRegisteredServiceUsernameAttributeProvider(generator);
        } else {
            throw new IllegalArgumentException("Invalid sale value for anonymous ids " + salt);
        }
    } else if (StringUtils.equalsIgnoreCase(uidType, RegisteredServiceUsernameAttributeProviderEditBean.Types.ATTRIBUTE.toString())) {
        final String attr = userAttrProvider.getValue();
        if (StringUtils.isNotBlank(attr)) {
            return new PrincipalAttributeRegisteredServiceUsernameProvider(attr);
        } else {
            throw new IllegalArgumentException("Invalid attribute specified for username");
        }
    }
    return null;
}
Also used : AnonymousRegisteredServiceUsernameAttributeProvider(org.apereo.cas.services.AnonymousRegisteredServiceUsernameAttributeProvider) RegisteredServiceUsernameAttributeProviderEditBean(org.apereo.cas.mgmt.services.web.beans.RegisteredServiceUsernameAttributeProviderEditBean) PrincipalAttributeRegisteredServiceUsernameProvider(org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider) DefaultRegisteredServiceUsernameProvider(org.apereo.cas.services.DefaultRegisteredServiceUsernameProvider) ShibbolethCompatiblePersistentIdGenerator(org.apereo.cas.authentication.principal.ShibbolethCompatiblePersistentIdGenerator)

Example 7 with ShibbolethCompatiblePersistentIdGenerator

use of org.apereo.cas.authentication.principal.ShibbolethCompatiblePersistentIdGenerator in project cas by apereo.

the class DefaultUsernameAttributeProviderMapper method mapUsernameAttributeProvider.

@Override
public void mapUsernameAttributeProvider(final RegisteredServiceUsernameAttributeProvider provider, final ServiceData bean) {
    final RegisteredServiceUsernameAttributeProviderEditBean uBean = bean.getUserAttrProvider();
    if (provider instanceof DefaultRegisteredServiceUsernameProvider) {
        uBean.setType(RegisteredServiceUsernameAttributeProviderEditBean.Types.DEFAULT.toString());
    } else if (provider instanceof AnonymousRegisteredServiceUsernameAttributeProvider) {
        final AnonymousRegisteredServiceUsernameAttributeProvider anonymous = (AnonymousRegisteredServiceUsernameAttributeProvider) provider;
        uBean.setType(RegisteredServiceUsernameAttributeProviderEditBean.Types.ANONYMOUS.toString());
        final PersistentIdGenerator generator = anonymous.getPersistentIdGenerator();
        if (generator instanceof ShibbolethCompatiblePersistentIdGenerator) {
            final ShibbolethCompatiblePersistentIdGenerator sh = (ShibbolethCompatiblePersistentIdGenerator) generator;
            if (sh.getSalt() != null) {
                final String salt = new String(sh.getSalt(), Charset.defaultCharset());
                uBean.setValue(salt);
            } else {
                throw new IllegalArgumentException("Salt cannot be null");
            }
        }
    } else if (provider instanceof PrincipalAttributeRegisteredServiceUsernameProvider) {
        final PrincipalAttributeRegisteredServiceUsernameProvider p = (PrincipalAttributeRegisteredServiceUsernameProvider) provider;
        uBean.setType(RegisteredServiceUsernameAttributeProviderEditBean.Types.ATTRIBUTE.toString());
        uBean.setValue(p.getUsernameAttribute());
    }
}
Also used : AnonymousRegisteredServiceUsernameAttributeProvider(org.apereo.cas.services.AnonymousRegisteredServiceUsernameAttributeProvider) RegisteredServiceUsernameAttributeProviderEditBean(org.apereo.cas.mgmt.services.web.beans.RegisteredServiceUsernameAttributeProviderEditBean) PrincipalAttributeRegisteredServiceUsernameProvider(org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider) DefaultRegisteredServiceUsernameProvider(org.apereo.cas.services.DefaultRegisteredServiceUsernameProvider) ShibbolethCompatiblePersistentIdGenerator(org.apereo.cas.authentication.principal.ShibbolethCompatiblePersistentIdGenerator) ShibbolethCompatiblePersistentIdGenerator(org.apereo.cas.authentication.principal.ShibbolethCompatiblePersistentIdGenerator) PersistentIdGenerator(org.apereo.cas.authentication.principal.PersistentIdGenerator)

Aggregations

ShibbolethCompatiblePersistentIdGenerator (org.apereo.cas.authentication.principal.ShibbolethCompatiblePersistentIdGenerator)7 Test (org.junit.Test)4 AnonymousRegisteredServiceUsernameAttributeProvider (org.apereo.cas.services.AnonymousRegisteredServiceUsernameAttributeProvider)3 RegisteredServiceUsernameAttributeProviderEditBean (org.apereo.cas.mgmt.services.web.beans.RegisteredServiceUsernameAttributeProviderEditBean)2 DefaultRegisteredServiceUsernameProvider (org.apereo.cas.services.DefaultRegisteredServiceUsernameProvider)2 PrincipalAttributeRegisteredServiceUsernameProvider (org.apereo.cas.services.PrincipalAttributeRegisteredServiceUsernameProvider)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 PersistentIdGenerator (org.apereo.cas.authentication.principal.PersistentIdGenerator)1 Principal (org.apereo.cas.authentication.principal.Principal)1 Service (org.apereo.cas.authentication.principal.Service)1 AbstractRegisteredService (org.apereo.cas.services.AbstractRegisteredService)1 DefaultRegisteredServiceProperty (org.apereo.cas.services.DefaultRegisteredServiceProperty)1 RefuseRegisteredServiceProxyPolicy (org.apereo.cas.services.RefuseRegisteredServiceProxyPolicy)1 RegexRegisteredService (org.apereo.cas.services.RegexRegisteredService)1 RegisteredServiceProperty (org.apereo.cas.services.RegisteredServiceProperty)1