use of com.novell.ldap.LDAPConstraints in project ldapchai by ldapchai.
the class JLDAPProviderImpl method writeBinaryAttribute.
@ChaiProvider.LdapOperation
@ChaiProvider.ModifyOperation
public void writeBinaryAttribute(final String entryDN, final String attribute, final byte[][] values, final boolean overwrite, final ChaiRequestControl[] controls) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().writeBinaryAttribute(entryDN, attribute, values, overwrite);
final LDAPAttribute ldapAttr = new LDAPAttribute(attribute);
for (final byte[] value : values) {
ldapAttr.addValue(value);
}
final LDAPModification mod = new LDAPModification(overwrite ? LDAPModification.REPLACE : LDAPModification.ADD, ldapAttr);
try {
if (controls != null && controls.length > 0) {
final LDAPConstraints constraints = new LDAPConstraints();
constraints.setControls(convertControls(controls));
ldapConnection.modify(entryDN, mod, constraints);
} else {
ldapConnection.modify(entryDN, mod);
}
} catch (LDAPException e) {
throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
}
}
use of com.novell.ldap.LDAPConstraints in project ldapchai by ldapchai.
the class JLDAPProviderImpl method init.
public void init(final ChaiConfiguration chaiConfig, final ChaiProviderFactory providerFactory) throws ChaiUnavailableException, IllegalStateException {
super.init(chaiConfig, providerFactory);
try {
// grab the first URL from the list.
final URI ldapURL = URI.create(chaiConfig.bindURLsAsList().get(0));
if (ldapURL.getScheme().equalsIgnoreCase("ldaps")) {
final boolean usePromiscuousSSL = Boolean.parseBoolean(chaiConfig.getSetting(ChaiSetting.PROMISCUOUS_SSL));
if (usePromiscuousSSL) {
try {
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new X509TrustManager[] { new PromiscuousTrustManager() }, new java.security.SecureRandom());
ldapConnection = new LDAPConnection(new LDAPJSSESecureSocketFactory(sc.getSocketFactory()));
} catch (Exception e) {
LOGGER.error("error creating promiscuous ssl ldap socket factory: " + e.getMessage());
}
} else if (chaiConfig.getTrustManager() != null) {
try {
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, chaiConfig.getTrustManager(), new java.security.SecureRandom());
ldapConnection = new LDAPConnection(new LDAPJSSESecureSocketFactory(sc.getSocketFactory()));
} catch (Exception e) {
LOGGER.error("error creating configured ssl ldap socket factory: " + e.getMessage());
}
} else {
ldapConnection = new LDAPConnection(new LDAPJSSESecureSocketFactory());
}
} else {
ldapConnection = new LDAPConnection();
}
ldapConnection.connect(ldapURL.getHost(), ldapURL.getPort());
if (chaiConfig.getBooleanSetting(ChaiSetting.LDAP_FOLLOW_REFERRALS)) {
final LDAPConstraints ldapConstraints = new LDAPConstraints();
ldapConstraints.setReferralFollowing(true);
ldapConnection.setConstraints(ldapConstraints);
}
final String characterEncoding = chaiConfig.getSetting(ChaiSetting.LDAP_CHARACTER_ENCODING);
final byte[] bindPassword = chaiConfig.getSetting(ChaiSetting.BIND_PASSWORD).getBytes(Charset.forName(characterEncoding));
final String bindDN = chaiConfig.getSetting(ChaiSetting.BIND_DN);
ldapConnection.bind(LDAPConnection.LDAP_V3, bindDN, bindPassword);
} catch (LDAPException e) {
final String message = e.getMessage();
if (message.contains("Connect Error")) {
throw new ChaiUnavailableException(message, ChaiError.COMMUNICATION, false, false);
}
throw ChaiUnavailableException.forErrorMessage(message);
}
}
Aggregations