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;
}
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;
}
Aggregations