Search in sources :

Example 1 with AddOperation

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

the class LdapUserGraphicalAuthenticationRepositoryTests method createLdapEntry.

private static String createLdapEntry(final ConnectionFactory factory) throws Exception {
    val photo = IOUtils.toByteArray(new ClassPathResource("image.jpg").getInputStream());
    val cn = RandomUtils.randomAlphabetic(6).toLowerCase();
    val request = AddRequest.builder().attributes(List.of(new LdapAttribute("objectclass", "top", "person", "inetOrgPerson"), new LdapAttribute("cn", cn), new LdapAttribute("jpegPhoto", photo), new LdapAttribute("sn", cn))).dn("cn=" + cn + ",ou=People,dc=example,dc=org").build();
    val operation = new AddOperation(factory);
    operation.execute(request);
    return cn;
}
Also used : lombok.val(lombok.val) LdapAttribute(org.ldaptive.LdapAttribute) AddOperation(org.ldaptive.AddOperation) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 2 with AddOperation

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

the class LdapUtils method executeAddOperation.

/**
 * Execute add operation boolean.
 *
 * @param connectionFactory the connection factory
 * @param entry             the entry
 * @return true/false
 */
public static boolean executeAddOperation(final ConnectionFactory connectionFactory, final LdapEntry entry) {
    try {
        val operation = new AddOperation(connectionFactory);
        val response = operation.execute(new AddRequest(entry.getDn(), entry.getAttributes()));
        LOGGER.debug("Result code [{}], message: [{}]", response.getResultCode(), response.getDiagnosticMessage());
        return response.getResultCode() == ResultCode.SUCCESS;
    } catch (final Exception e) {
        LoggingUtils.error(LOGGER, e);
    }
    return false;
}
Also used : lombok.val(lombok.val) AddRequest(org.ldaptive.AddRequest) AddOperation(org.ldaptive.AddOperation) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) LdapException(org.ldaptive.LdapException)

Aggregations

lombok.val (lombok.val)2 AddOperation (org.ldaptive.AddOperation)2 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 AddRequest (org.ldaptive.AddRequest)1 LdapAttribute (org.ldaptive.LdapAttribute)1 LdapException (org.ldaptive.LdapException)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1