use of org.apereo.services.persondir.support.StubPersonAttributeDao in project cas by apereo.
the class PersonDirectoryPrincipalResolverTests method verifyNoPrincipalAttrWithoutNull.
@Test
public void verifyNoPrincipalAttrWithoutNull() {
val context = PrincipalResolutionContext.builder().attributeMerger(CoreAuthenticationUtils.getAttributeMerger(casProperties.getAuthn().getAttributeRepository().getCore().getMerger())).attributeRepository(new StubPersonAttributeDao(new HashMap<>(0))).principalFactory(PrincipalFactoryUtils.newPrincipalFactory()).returnNullIfNoAttributes(false).principalNameTransformer(String::trim).useCurrentPrincipalId(false).resolveAttributes(true).activeAttributeRepositoryIdentifiers(CollectionUtils.wrapSet(IPersonAttributeDao.WILDCARD)).principalAttributeNames("cn").build();
val resolver = new PersonDirectoryPrincipalResolver(context);
val p = resolver.resolve(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), Optional.of(CoreAuthenticationTestUtils.getPrincipal()), Optional.of(new SimpleTestUsernamePasswordAuthenticationHandler()));
assertNotNull(p);
}
use of org.apereo.services.persondir.support.StubPersonAttributeDao 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());
}
use of org.apereo.services.persondir.support.StubPersonAttributeDao in project cas by apereo.
the class CoreAuthenticationUtilsTests method verifyAttributeRepositoriesByFilter.
@Test
public void verifyAttributeRepositoriesByFilter() {
val repository = new StubPersonAttributeDao(CoreAuthenticationTestUtils.getAttributes()) {
@Override
public IPersonAttributes getPerson(final String uid, final IPersonAttributeDaoFilter filter) {
if (filter.choosePersonAttributeDao(this)) {
return super.getPerson(uid, filter);
}
return null;
}
};
var attrs = CoreAuthenticationUtils.retrieveAttributesFromAttributeRepository(repository, "casuser", Set.of("*"), Optional.of(CoreAuthenticationTestUtils.getPrincipal("casuser")));
assertTrue(attrs.containsKey("uid"));
assertTrue(attrs.containsKey("mail"));
assertTrue(attrs.containsKey("memberOf"));
attrs = CoreAuthenticationUtils.retrieveAttributesFromAttributeRepository(repository, "casuser", Set.of("Invalid"), Optional.of(CoreAuthenticationTestUtils.getPrincipal("casuser")));
assertTrue(attrs.isEmpty());
}
Aggregations