Search in sources :

Example 1 with IPersonAttributes

use of org.apereo.services.persondir.IPersonAttributes in project cas by apereo.

the class ShibbolethPersonAttributeDao method getPerson.

@Override
public IPersonAttributes getPerson(final String uid) {
    final AttributeResolutionContext attributeResolutionContext = new AttributeResolutionContext();
    attributeResolutionContext.setPrincipal(uid);
    try {
        this.attributeResolver.resolveAttributes(attributeResolutionContext);
        final Map<String, List<Object>> attributes = attributeResolutionContext.getResolvedIdPAttributes().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, p -> p.getValue().getValues().stream().map(IdPAttributeValue::getValue).collect(Collectors.toList())));
        return new NamedPersonImpl(uid, attributes);
    } catch (final ResolutionException e) {
        throw Throwables.propagate(e);
    }
}
Also used : IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) ResolutionException(net.shibboleth.idp.attribute.resolver.ResolutionException) Throwables(com.google.common.base.Throwables) IdPAttributeValue(net.shibboleth.idp.attribute.IdPAttributeValue) BasePersonAttributeDao(org.apereo.services.persondir.support.BasePersonAttributeDao) Set(java.util.Set) Collectors(java.util.stream.Collectors) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) AttributeResolutionContext(net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext) List(java.util.List) NamedPersonImpl(org.apereo.services.persondir.support.NamedPersonImpl) Map(java.util.Map) AttributeResolver(net.shibboleth.idp.attribute.resolver.AttributeResolver) Collections(java.util.Collections) ResolutionException(net.shibboleth.idp.attribute.resolver.ResolutionException) NamedPersonImpl(org.apereo.services.persondir.support.NamedPersonImpl) AttributeResolutionContext(net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext) List(java.util.List) Map(java.util.Map)

Example 2 with IPersonAttributes

use of org.apereo.services.persondir.IPersonAttributes in project cas by apereo.

the class AbstractPrincipalAttributesRepository method retrievePersonAttributesToPrincipalAttributes.

/**
     * Obtains attributes first from the repository by calling
     * {@link org.apereo.services.persondir.IPersonAttributeDao#getPerson(String)}.
     *
     * @param id the person id to locate in the attribute repository
     * @return the map of attributes
     */
protected Map<String, List<Object>> retrievePersonAttributesToPrincipalAttributes(final String id) {
    final IPersonAttributes attrs = getAttributeRepository().getPerson(id);
    if (attrs == null) {
        LOGGER.debug("Could not find principal [{}] in the repository so no attributes are returned.", id);
        return Collections.emptyMap();
    }
    final Map<String, List<Object>> attributes = attrs.getAttributes();
    if (attributes == null) {
        LOGGER.debug("Principal [{}] has no attributes and so none are returned.", id);
        return Collections.emptyMap();
    }
    return attributes;
}
Also used : IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) List(java.util.List)

Example 3 with IPersonAttributes

use of org.apereo.services.persondir.IPersonAttributes in project cas by apereo.

the class PersonDirectoryPrincipalResolver method retrievePersonAttributes.

/**
     * Retrieve person attributes map.
     *
     * @param principalId the principal id
     * @param credential  the credential whose id we have extracted. This is passed so that implementations
     *                    can extract useful bits of authN info such as attributes into the principal.
     * @return the map
     */
protected Map<String, List<Object>> retrievePersonAttributes(final String principalId, final Credential credential) {
    final IPersonAttributes personAttributes = this.attributeRepository.getPerson(principalId);
    final Map<String, List<Object>> attributes;
    if (personAttributes == null) {
        attributes = null;
    } else {
        attributes = personAttributes.getAttributes();
    }
    return attributes;
}
Also used : IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) List(java.util.List)

Example 4 with IPersonAttributes

use of org.apereo.services.persondir.IPersonAttributes in project cas by apereo.

the class RegisteredServiceAttributeReleasePolicyTests method checkServiceAttributeFilterAllAttributesWithCachingTurnedOn.

@Test
public void checkServiceAttributeFilterAllAttributesWithCachingTurnedOn() {
    final ReturnAllAttributeReleasePolicy policy = new ReturnAllAttributeReleasePolicy();
    final Map<String, List<Object>> attributes = new HashMap<>();
    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" }));
    final IPersonAttributeDao dao = new StubPersonAttributeDao(attributes);
    final IPersonAttributes person = mock(IPersonAttributes.class);
    when(person.getName()).thenReturn("uid");
    when(person.getAttributes()).thenReturn(attributes);
    final CachingPrincipalAttributesRepository repository = new CachingPrincipalAttributesRepository(TimeUnit.MILLISECONDS.name(), 100);
    repository.setAttributeRepository(dao);
    final Principal p = new DefaultPrincipalFactory().createPrincipal("uid", Collections.singletonMap("mail", "final@example.com"));
    policy.setPrincipalAttributesRepository(repository);
    final Map<String, Object> attr = policy.getAttributes(p, CoreAuthenticationTestUtils.getRegisteredService());
    assertEquals(attr.size(), attributes.size());
}
Also used : HashMap(java.util.HashMap) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) ArrayList(java.util.ArrayList) List(java.util.List) CachingPrincipalAttributesRepository(org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository) Principal(org.apereo.cas.authentication.principal.Principal) StubPersonAttributeDao(org.apereo.services.persondir.support.StubPersonAttributeDao) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with IPersonAttributes

use of org.apereo.services.persondir.IPersonAttributes in project cas by apereo.

the class AbstractCachingPrincipalAttributesRepositoryTests method setUp.

@Before
public void setUp() {
    attributes = new HashMap<>();
    attributes.put("a1", Arrays.asList("v1", "v2", "v3"));
    List email = new ArrayList<>();
    email.add("final@example.com");
    attributes.put(MAIL, email);
    attributes.put("a6", Arrays.asList("v16", "v26", "v63"));
    attributes.put("a2", Arrays.asList("v4"));
    attributes.put("username", Arrays.asList("uid"));
    this.dao = mock(IPersonAttributeDao.class);
    final IPersonAttributes person = mock(IPersonAttributes.class);
    when(person.getName()).thenReturn("uid");
    when(person.getAttributes()).thenReturn(attributes);
    when(dao.getPerson(any(String.class))).thenReturn(person);
    email = new ArrayList<>();
    email.add("final@school.com");
    this.principal = this.principalFactory.createPrincipal("uid", Collections.singletonMap(MAIL, email));
}
Also used : IPersonAttributes(org.apereo.services.persondir.IPersonAttributes) IPersonAttributeDao(org.apereo.services.persondir.IPersonAttributeDao) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Before(org.junit.Before)

Aggregations

List (java.util.List)5 IPersonAttributes (org.apereo.services.persondir.IPersonAttributes)5 IPersonAttributeDao (org.apereo.services.persondir.IPersonAttributeDao)3 ArrayList (java.util.ArrayList)2 Throwables (com.google.common.base.Throwables)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 IdPAttributeValue (net.shibboleth.idp.attribute.IdPAttributeValue)1 AttributeResolver (net.shibboleth.idp.attribute.resolver.AttributeResolver)1 ResolutionException (net.shibboleth.idp.attribute.resolver.ResolutionException)1 AttributeResolutionContext (net.shibboleth.idp.attribute.resolver.context.AttributeResolutionContext)1 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)1 Principal (org.apereo.cas.authentication.principal.Principal)1 CachingPrincipalAttributesRepository (org.apereo.cas.authentication.principal.cache.CachingPrincipalAttributesRepository)1 BasePersonAttributeDao (org.apereo.services.persondir.support.BasePersonAttributeDao)1 NamedPersonImpl (org.apereo.services.persondir.support.NamedPersonImpl)1 StubPersonAttributeDao (org.apereo.services.persondir.support.StubPersonAttributeDao)1