Search in sources :

Example 26 with LdapAttribute

use of org.ldaptive.LdapAttribute in project cas by apereo.

the class LdapSpnegoKnownClientSystemsFilterAction method processSpnegoAttribute.

/**
 * Verify spnego attribute value.
 *
 * @param searchResult the search result
 * @return true if attribute value exists and has a value
 */
protected boolean processSpnegoAttribute(final Response<SearchResult> searchResult) {
    final SearchResult result = searchResult.getResult();
    if (result == null || result.getEntries().isEmpty()) {
        LOGGER.debug("Spnego attribute is not found in the search results");
        return false;
    }
    final LdapEntry entry = result.getEntry();
    final LdapAttribute attribute = entry.getAttribute(this.spnegoAttributeName);
    LOGGER.debug("Spnego attribute [{}] found as [{}] for [{}]", attribute.getName(), attribute.getStringValue(), entry.getDn());
    return verifySpnegoAttributeValue(attribute);
}
Also used : LdapAttribute(org.ldaptive.LdapAttribute) SearchResult(org.ldaptive.SearchResult) LdapEntry(org.ldaptive.LdapEntry)

Example 27 with LdapAttribute

use of org.ldaptive.LdapAttribute in project cas by apereo.

the class AbstractX509LdapTests method populateCertificateRevocationListAttribute.

/**
 * Populate certificate revocation list attribute.
 * Dynamically set the attribute value to the crl content.
 * Encode it as base64 first. Doing this in the code rather
 * than in the ldif file to ensure the attribute can be populated
 * without dependencies on the classpath and or filesystem.
 *
 * @throws Exception the exception
 */
private static void populateCertificateRevocationListAttribute(final int port) throws Exception {
    final Collection<LdapEntry> col = getLdapDirectory(port).getLdapEntries();
    for (final LdapEntry ldapEntry : col) {
        if (ldapEntry.getDn().equals(DN)) {
            final LdapAttribute attr = new LdapAttribute(true);
            byte[] value = new byte[1024];
            IOUtils.read(new ClassPathResource("userCA-valid.crl").getInputStream(), value);
            value = EncodingUtils.encodeBase64ToByteArray(value);
            attr.setName("certificateRevocationList");
            attr.addBinaryValue(value);
            LdapTestUtils.modifyLdapEntry(getLdapDirectory(port).getConnection(), ldapEntry, attr);
        }
    }
}
Also used : LdapAttribute(org.ldaptive.LdapAttribute) LdapEntry(org.ldaptive.LdapEntry) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

LdapAttribute (org.ldaptive.LdapAttribute)27 LdapEntry (org.ldaptive.LdapEntry)18 SearchResult (org.ldaptive.SearchResult)11 SearchFilter (org.ldaptive.SearchFilter)7 ArrayList (java.util.ArrayList)6 ConnectionFactory (org.ldaptive.ConnectionFactory)5 LinkedHashMap (java.util.LinkedHashMap)4 PasswordManagementProperties (org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties)4 MessageDescriptor (org.apereo.cas.authentication.MessageDescriptor)3 AbstractLdapProperties (org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties)3 Test (org.junit.Test)3 BindRequest (org.ldaptive.BindRequest)3 CompareRequest (org.ldaptive.CompareRequest)3 LdapException (org.ldaptive.LdapException)3 URI (java.net.URI)2 URL (java.net.URL)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 List (java.util.List)2