Search in sources :

Example 1 with GraphicalUserAuthenticationProperties

use of org.apereo.cas.configuration.model.support.gua.GraphicalUserAuthenticationProperties in project cas by apereo.

the class LdapUserGraphicalAuthenticationRepository method getGraphics.

@Override
public ByteSource getGraphics(final String username) {
    try {
        final GraphicalUserAuthenticationProperties gua = casProperties.getAuthn().getGua();
        final Response<SearchResult> response = searchForId(username);
        if (LdapUtils.containsResultEntry(response)) {
            final LdapEntry entry = response.getResult().getEntry();
            final LdapAttribute attribute = entry.getAttribute(gua.getLdap().getImageAttribute());
            if (attribute != null && attribute.isBinary()) {
                return ByteSource.wrap(attribute.getBinaryValue());
            }
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return ByteSource.empty();
}
Also used : LdapAttribute(org.ldaptive.LdapAttribute) SearchResult(org.ldaptive.SearchResult) LdapEntry(org.ldaptive.LdapEntry) GraphicalUserAuthenticationProperties(org.apereo.cas.configuration.model.support.gua.GraphicalUserAuthenticationProperties) LdapException(org.ldaptive.LdapException)

Example 2 with GraphicalUserAuthenticationProperties

use of org.apereo.cas.configuration.model.support.gua.GraphicalUserAuthenticationProperties in project cas by apereo.

the class LdapUserGraphicalAuthenticationRepository method searchForId.

private Response<SearchResult> searchForId(final String id) throws LdapException {
    final GraphicalUserAuthenticationProperties gua = casProperties.getAuthn().getGua();
    final SearchFilter filter = Beans.newLdaptiveSearchFilter(gua.getLdap().getUserFilter(), Beans.LDAP_SEARCH_FILTER_DEFAULT_PARAM_NAME, Arrays.asList(id));
    return LdapUtils.executeSearchOperation(Beans.newLdaptiveConnectionFactory(gua.getLdap()), gua.getLdap().getBaseDn(), filter, new String[] { gua.getLdap().getImageAttribute() }, ReturnAttributes.NONE.value());
}
Also used : SearchFilter(org.ldaptive.SearchFilter) GraphicalUserAuthenticationProperties(org.apereo.cas.configuration.model.support.gua.GraphicalUserAuthenticationProperties)

Example 3 with GraphicalUserAuthenticationProperties

use of org.apereo.cas.configuration.model.support.gua.GraphicalUserAuthenticationProperties in project cas by apereo.

the class StaticUserGraphicalAuthenticationRepository method getGraphics.

@Override
public ByteSource getGraphics(final String username) {
    try {
        final GraphicalUserAuthenticationProperties gua = casProperties.getAuthn().getGua();
        final Resource resource = resourceLoader.getResource(gua.getResource().getLocation());
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
        IOUtils.copy(resource.getInputStream(), bos);
        return ByteSource.wrap(bos.toByteArray());
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return ByteSource.empty();
}
Also used : Resource(org.springframework.core.io.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GraphicalUserAuthenticationProperties(org.apereo.cas.configuration.model.support.gua.GraphicalUserAuthenticationProperties)

Aggregations

GraphicalUserAuthenticationProperties (org.apereo.cas.configuration.model.support.gua.GraphicalUserAuthenticationProperties)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 LdapAttribute (org.ldaptive.LdapAttribute)1 LdapEntry (org.ldaptive.LdapEntry)1 LdapException (org.ldaptive.LdapException)1 SearchFilter (org.ldaptive.SearchFilter)1 SearchResult (org.ldaptive.SearchResult)1 Resource (org.springframework.core.io.Resource)1