use of org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository in project cas by apereo.
the class RegisteredServiceTestUtils method getRegisteredService.
@SneakyThrows
public static AbstractRegisteredService getRegisteredService(final String id) {
final RegexRegisteredService s = new RegexRegisteredService();
s.setServiceId(id);
s.setEvaluationOrder(1);
s.setName("Test registered service " + id);
s.setDescription("Registered service description");
s.setProxyPolicy(new RegexMatchingRegisteredServiceProxyPolicy("^https?://.+"));
s.setId(RandomUtils.getNativeInstance().nextInt(Math.abs(s.hashCode())));
s.setTheme("exampleTheme");
s.setUsernameAttributeProvider(new PrincipalAttributeRegisteredServiceUsernameProvider("uid"));
final DefaultRegisteredServiceAccessStrategy accessStrategy = new DefaultRegisteredServiceAccessStrategy(true, true);
accessStrategy.setRequireAllAttributes(true);
accessStrategy.setRequiredAttributes(getTestAttributes());
s.setAccessStrategy(accessStrategy);
s.setLogo("https://logo.example.org/logo.png");
s.setLogoutType(LogoutType.BACK_CHANNEL);
s.setLogoutUrl(new URL("https://sys.example.org/logout.png"));
s.setProxyPolicy(new RegexMatchingRegisteredServiceProxyPolicy("^http.+"));
s.setPublicKey(new RegisteredServicePublicKeyImpl("classpath:RSA1024Public.key", "RSA"));
final ReturnAllowedAttributeReleasePolicy policy = new ReturnAllowedAttributeReleasePolicy();
policy.setAuthorizedToReleaseCredentialPassword(true);
policy.setAuthorizedToReleaseProxyGrantingTicket(true);
final CachingPrincipalAttributesRepository repo = new CachingPrincipalAttributesRepository(TimeUnit.SECONDS.name(), 10);
repo.setMergingStrategy(AbstractPrincipalAttributesRepository.MergingStrategy.ADD);
policy.setPrincipalAttributesRepository(repo);
policy.setAttributeFilter(new RegisteredServiceRegexAttributeFilter("https://.+"));
policy.setAllowedAttributes(new ArrayList<>(getTestAttributes().keySet()));
s.setAttributeReleasePolicy(policy);
return s;
}
use of org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository in project cas by apereo.
the class RegisteredServiceTestUtils method getRegisteredService.
@SneakyThrows
public static AbstractRegisteredService getRegisteredService(final String id, final Class<? extends RegisteredService> clazz, final boolean uniq, final Map requiredAttributes) {
val s = (AbstractRegisteredService) clazz.getDeclaredConstructor().newInstance();
s.setServiceId(id);
s.setEvaluationOrder(1);
if (uniq) {
val uuid = Iterables.get(Splitter.on('-').split(UUID.randomUUID().toString()), 0);
s.setName("TestService" + uuid);
} else {
s.setName(id);
}
s.setDescription("Registered service description");
s.setProxyPolicy(new RegexMatchingRegisteredServiceProxyPolicy("^https?://.+"));
s.setId(RandomUtils.nextInt());
s.setTheme("exampleTheme");
s.setUsernameAttributeProvider(new PrincipalAttributeRegisteredServiceUsernameProvider("uid"));
val accessStrategy = new DefaultRegisteredServiceAccessStrategy(true, true);
accessStrategy.setRequireAllAttributes(true);
accessStrategy.setRequiredAttributes(requiredAttributes);
accessStrategy.setUnauthorizedRedirectUrl(new URI("https://www.github.com"));
s.setAccessStrategy(accessStrategy);
s.setLogo("https://logo.example.org/logo.png");
s.setLogoutType(RegisteredServiceLogoutType.BACK_CHANNEL);
s.setLogoutUrl("https://sys.example.org/logout.png");
s.setProxyPolicy(new RegexMatchingRegisteredServiceProxyPolicy("^http.+"));
s.setPublicKey(new RegisteredServicePublicKeyImpl("classpath:RSA1024Public.key", "RSA"));
val policy = new ReturnAllowedAttributeReleasePolicy();
policy.setAuthorizedToReleaseCredentialPassword(true);
policy.setAuthorizedToReleaseProxyGrantingTicket(true);
val repo = new CachingPrincipalAttributesRepository(TimeUnit.SECONDS.name(), 10);
repo.setMergingStrategy(PrincipalAttributesCoreProperties.MergingStrategyTypes.ADD);
policy.setPrincipalAttributesRepository(repo);
policy.setAttributeFilter(new RegisteredServiceRegexAttributeFilter("https://.+"));
policy.setAllowedAttributes(new ArrayList<>(getTestAttributes().keySet()));
s.setAttributeReleasePolicy(policy);
return s;
}
use of org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository in project cas by apereo.
the class RegisteredServiceAttributeReleasePolicyTests method checkServiceAttributeFilterAllAttributesWithCachingTurnedOn.
@Test
public void checkServiceAttributeFilterAllAttributesWithCachingTurnedOn() {
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(), 100);
repository.setAttributeRepositoryIds(Set.of(stub.getId()));
val p = PrincipalFactoryUtils.newPrincipalFactory().createPrincipal("uid", Collections.singletonMap("mail", List.of("final@example.com")));
policy.setPrincipalAttributesRepository(repository);
val context = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(CoreAttributesTestUtils.getRegisteredService()).service(CoreAttributesTestUtils.getService()).principal(p).build();
val attr = policy.getAttributes(context);
assertEquals(attributes.size() + 1, attr.size());
}
Aggregations