Search in sources :

Example 1 with CachingPrincipalAttributesRepository

use of org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository in project cas by apereo.

the class JasigRegisteredServiceDeserializationProblemHandler method handleUnknownProperty.

@Override
public boolean handleUnknownProperty(final DeserializationContext ctxt, final JsonParser p, final JsonDeserializer<?> deserializer, final Object beanOrClass, final String propertyName) throws IOException {
    boolean handled = false;
    if (beanOrClass instanceof CachingPrincipalAttributesRepository) {
        final CachingPrincipalAttributesRepository repo = CachingPrincipalAttributesRepository.class.cast(beanOrClass);
        switch(propertyName) {
            case "duration":
                for (int i = 1; i <= TOKEN_COUNT_DURATION; i++) {
                    p.nextToken();
                }
                final String timeUnit = p.getText();
                for (int i = 1; i <= TOKEN_COUNT_EXPIRATION; i++) {
                    p.nextToken();
                }
                final int expiration = p.getValueAsInt();
                repo.setTimeUnit(timeUnit);
                repo.setExpiration(expiration);
                LOGGER.warn("CAS has converted legacy JSON property [{}] for type [{}]. It parsed 'expiration' value [{}] with time unit of [{}]." + "It is STRONGLY recommended that you review the configuration and upgrade from the legacy syntax.", propertyName, beanOrClass.getClass().getName(), expiration, timeUnit);
                handled = true;
                break;
            default:
                break;
        }
    }
    return handled;
}
Also used : CachingPrincipalAttributesRepository(org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository)

Example 2 with CachingPrincipalAttributesRepository

use of org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository in project cas by apereo.

the class RegisteredServiceAttributeReleasePolicyTests method checkServiceAttributeFilterByAttributeRepositoryId.

@Test
public void checkServiceAttributeFilterByAttributeRepositoryId() {
    val policy = new ReturnAllAttributeReleasePolicy();
    val attributes = new HashMap<String, List<Object>>();
    attributes.put("values", Arrays.asList(new Object[] { "v1", "v2", "v3" }));
    attributes.put("cn", Arrays.asList(new Object[] { "commonName" }));
    attributes.put("username", Arrays.asList(new Object[] { "uid" }));
    val person = mock(IPersonAttributes.class);
    when(person.getName()).thenReturn("uid");
    when(person.getAttributes()).thenReturn(attributes);
    val stub = new StubPersonAttributeDao(attributes);
    stub.setId("SampleStubRepository");
    val dao = new MergingPersonAttributeDaoImpl();
    dao.setPersonAttributeDaos(List.of(stub));
    ApplicationContextProvider.registerBeanIntoApplicationContext(this.applicationContext, dao, PrincipalResolver.BEAN_NAME_ATTRIBUTE_REPOSITORY);
    val repository = new CachingPrincipalAttributesRepository(TimeUnit.MILLISECONDS.name(), 0);
    val p = PrincipalFactoryUtils.newPrincipalFactory().createPrincipal("uid", Collections.singletonMap("mail", List.of("final@example.com")));
    repository.setAttributeRepositoryIds(CollectionUtils.wrapSet("SampleStubRepository".toUpperCase()));
    policy.setPrincipalAttributesRepository(repository);
    val context = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(CoreAttributesTestUtils.getRegisteredService()).service(CoreAttributesTestUtils.getService()).principal(p).build();
    var attr = policy.getAttributes(context);
    assertEquals(attr.size(), attributes.size() + 1);
    repository.setAttributeRepositoryIds(CollectionUtils.wrapSet("DoesNotExist"));
    policy.setPrincipalAttributesRepository(repository);
    attr = policy.getAttributes(context);
    assertEquals(1, attr.size());
}
Also used : lombok.val(lombok.val) MergingPersonAttributeDaoImpl(org.apereo.services.persondir.support.MergingPersonAttributeDaoImpl) HashMap(java.util.HashMap) CachingPrincipalAttributesRepository(org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository) StubPersonAttributeDao(org.apereo.services.persondir.support.StubPersonAttributeDao) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with CachingPrincipalAttributesRepository

use of org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository in project cas by apereo.

the class JasigRegisteredServiceDeserializationProblemHandler method handleUnknownProperty.

@Override
public boolean handleUnknownProperty(final DeserializationContext ctxt, final JsonParser p, final JsonDeserializer<?> deserializer, final Object beanOrClass, final String propertyName) throws IOException {
    boolean handled = false;
    if (beanOrClass instanceof CachingPrincipalAttributesRepository) {
        final CachingPrincipalAttributesRepository repo = CachingPrincipalAttributesRepository.class.cast(beanOrClass);
        switch(propertyName) {
            case "duration":
                p.nextToken();
                p.nextToken();
                p.nextToken();
                p.nextToken();
                p.nextToken();
                p.nextToken();
                final String timeUnit = p.getText();
                p.nextToken();
                p.nextToken();
                p.nextToken();
                final int expiration = p.getValueAsInt();
                repo.setTimeUnit(timeUnit);
                repo.setExpiration(expiration);
                LOGGER.warn("CAS has converted legacy JSON property [{}] for type [{}]. It parsed 'expiration' value [{}] with time unit of [{}]." + "It is STRONGLY recommended that you review the configuration and upgrade the legacy syntax.", propertyName, beanOrClass.getClass().getName(), expiration, timeUnit);
                handled = true;
                break;
            default:
                break;
        }
    }
    return handled;
}
Also used : CachingPrincipalAttributesRepository(org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository)

Example 4 with CachingPrincipalAttributesRepository

use of org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository in project cas by apereo.

the class DefaultPrincipalAttributesRepositoryMapper method toPrincipalRepository.

@Override
public PrincipalAttributesRepository toPrincipalRepository(final RegisteredServiceEditBean.ServiceData data) {
    final RegisteredServiceAttributeReleasePolicyEditBean attrRelease = data.getAttrRelease();
    final RegisteredServiceAttributeReleasePolicyEditBean.Types attrType = attrRelease.getAttrOption();
    if (attrType == RegisteredServiceAttributeReleasePolicyEditBean.Types.CACHED) {
        final CachingPrincipalAttributesRepository r = new CachingPrincipalAttributesRepository(attrRelease.getCachedTimeUnit().toUpperCase(), attrRelease.getCachedExpiration());
        switch(attrRelease.getMergingStrategy()) {
            case ADD:
                r.setMergingStrategy(AbstractPrincipalAttributesRepository.MergingStrategy.ADD);
                break;
            case MULTIVALUED:
                r.setMergingStrategy(AbstractPrincipalAttributesRepository.MergingStrategy.MULTIVALUED);
                break;
            case REPLACE:
                r.setMergingStrategy(AbstractPrincipalAttributesRepository.MergingStrategy.REPLACE);
                break;
            default:
                r.setMergingStrategy(AbstractPrincipalAttributesRepository.MergingStrategy.NONE);
                break;
        }
        return r;
    }
    if (attrType == RegisteredServiceAttributeReleasePolicyEditBean.Types.DEFAULT) {
        return new DefaultPrincipalAttributesRepository();
    }
    return null;
}
Also used : DefaultPrincipalAttributesRepository(org.apereo.cas.authentication.principal.DefaultPrincipalAttributesRepository) RegisteredServiceAttributeReleasePolicyEditBean(org.apereo.cas.mgmt.services.web.beans.RegisteredServiceAttributeReleasePolicyEditBean) CachingPrincipalAttributesRepository(org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository)

Example 5 with CachingPrincipalAttributesRepository

use of org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository in project cas by apereo.

the class CasCoreAuthenticationPrincipalConfiguration method globalPrincipalAttributeRepository.

@Bean
@RefreshScope
@ConditionalOnMissingBean(name = "globalPrincipalAttributeRepository")
public PrincipalAttributesRepository globalPrincipalAttributeRepository() {
    final PrincipalAttributesProperties props = casProperties.getAuthn().getAttributeRepository();
    final long cacheTime = props.getExpirationTime();
    if (cacheTime < 0) {
        return new DefaultPrincipalAttributesRepository();
    }
    return new CachingPrincipalAttributesRepository(props.getExpirationTimeUnit().toUpperCase(), cacheTime);
}
Also used : DefaultPrincipalAttributesRepository(org.apereo.cas.authentication.principal.DefaultPrincipalAttributesRepository) PrincipalAttributesProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties) CachingPrincipalAttributesRepository(org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

CachingPrincipalAttributesRepository (org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository)8 lombok.val (lombok.val)3 HashMap (java.util.HashMap)2 SneakyThrows (lombok.SneakyThrows)2 DefaultPrincipalAttributesRepository (org.apereo.cas.authentication.principal.DefaultPrincipalAttributesRepository)2 RegisteredServiceRegexAttributeFilter (org.apereo.cas.services.support.RegisteredServiceRegexAttributeFilter)2 MergingPersonAttributeDaoImpl (org.apereo.services.persondir.support.MergingPersonAttributeDaoImpl)2 StubPersonAttributeDao (org.apereo.services.persondir.support.StubPersonAttributeDao)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 URI (java.net.URI)1 URL (java.net.URL)1 PrincipalAttributesProperties (org.apereo.cas.configuration.model.core.authentication.PrincipalAttributesProperties)1 RegisteredServiceAttributeReleasePolicyEditBean (org.apereo.cas.mgmt.services.web.beans.RegisteredServiceAttributeReleasePolicyEditBean)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1