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;
}
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());
}
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;
}
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;
}
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);
}
Aggregations