use of org.forgerock.opendj.ldap.requests.SimpleBindRequest in project OpenAM by OpenRock.
the class AMSetupDSConfig method getLDAPConnection.
/**
* Helper method to return Ldap connection
*
* @param ssl <code>true</code> if directory server is running SSL.
* @return Ldap connection
*/
private synchronized Connection getLDAPConnection(boolean ssl) {
try {
if (ld == null) {
ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
// All connections will use authentication
SimpleBindRequest request = LDAPRequests.newSimpleBindRequest(dsManager, dsAdminPwd.toCharArray());
Options options = Options.defaultOptions().set(REQUEST_TIMEOUT, new Duration((long) 3, TimeUnit.SECONDS)).set(AUTHN_BIND_REQUEST, request);
if (ssl) {
options = options.set(SSL_CONTEXT, new SSLContextBuilder().getSSLContext());
}
ld = new LDAPConnectionFactory(dsHostName, getPort(), options);
shutdownMan.addShutdownListener(new ShutdownListener() {
public void shutdown() {
disconnectDServer();
}
});
}
return ld.getConnection();
} catch (LdapException e) {
disconnectDServer();
dsConfigInstance = null;
ld = null;
} catch (Exception e) {
dsConfigInstance = null;
ld = null;
}
return null;
}
use of org.forgerock.opendj.ldap.requests.SimpleBindRequest in project OpenAM by OpenRock.
the class UserIdRepo method getLDAPConnection.
private Connection getLDAPConnection(Map userRepo) throws Exception {
String userSSLStore = (String) userRepo.get(SetupConstants.USER_STORE_SSL);
// All connections will use authentication.
SimpleBindRequest request = LDAPRequests.newSimpleBindRequest(getBindDN(userRepo), getBindPassword(userRepo).toCharArray());
Options options = Options.defaultOptions().set(REQUEST_TIMEOUT, new Duration((long) 3, TimeUnit.SECONDS)).set(AUTHN_BIND_REQUEST, request);
if (userSSLStore != null && userSSLStore.equals("SSL")) {
options = options.set(SSL_CONTEXT, SSLContext.getDefault());
}
return getConnectionFactory(getHost(userRepo), Integer.parseInt(getPort(userRepo)), options).getConnection();
}
use of org.forgerock.opendj.ldap.requests.SimpleBindRequest in project OpenAM by OpenRock.
the class AMCertStore method getConnection.
/**
* Return ldap connection for ldap certificate store, or null if an error occured when connecting.
*/
synchronized Connection getConnection() {
if (ldapconn == null) {
/*
* Setup the LDAP certificate directory service context for
* use in verification of the users certificates.
*/
String serverName = storeParam.getServerName();
int port = storeParam.getPort();
LDAPConnectionFactory factory;
// Regardless of SSL on connection, we will use authentication
SimpleBindRequest authenticatedRequest = LDAPRequests.newSimpleBindRequest(storeParam.getUser(), storeParam.getPassword().toCharArray());
Options options = Options.defaultOptions().set(AUTHN_BIND_REQUEST, authenticatedRequest);
if (storeParam.isSecure()) {
debug.message("AMCertStore.getConnection: initial connection factory using ssl.");
try {
options = options.set(SSL_CONTEXT, new SSLContextBuilder().getSSLContext());
ldapconn = new LDAPConnectionFactory(serverName, port, options);
debug.message("AMCertStore.getConnection: SSLSocketFactory called");
} catch (GeneralSecurityException e) {
debug.error("AMCertStore.getConnection: Error getting SSL Context", e);
return null;
}
} else {
// non-ssl
ldapconn = new LDAPConnectionFactory(serverName, port, options);
}
}
try {
return ldapconn.getConnection();
} catch (LdapException e) {
debug.error("AMCertStore.getConnection: Exception in connection to LDAP server", e);
return null;
}
}
use of org.forgerock.opendj.ldap.requests.SimpleBindRequest in project OpenAM by OpenRock.
the class DataLayer method changePassword.
/**
* Changes user password.
*
* @param guid globally unique identifier for the entry.
* @param attrName password attribute name
* @param oldPassword old password
* @param newPassword new password
* @exception AccessRightsException if insufficient access
* @exception EntryNotFoundException if the entry is not found.
* @exception UMSException if failure
*
* @supported.api
*/
public void changePassword(Guid guid, String attrName, String oldPassword, String newPassword) throws UMSException {
Modification modification = new Modification(ModificationType.REPLACE, Attributes.singletonAttribute(attrName, newPassword));
String id = guid.getDn();
try {
DSConfigMgr dsCfg = DSConfigMgr.getDSConfigMgr();
String hostAndPort = dsCfg.getHostName("default");
// All connections will use authentication
SimpleBindRequest bindRequest = LDAPRequests.newSimpleBindRequest(id, oldPassword.toCharArray());
Options options = Options.defaultOptions().set(AUTHN_BIND_REQUEST, bindRequest);
try (ConnectionFactory factory = new LDAPConnectionFactory(hostAndPort, 389, options)) {
Connection ldc = factory.getConnection();
ldc.modify(LDAPRequests.newModifyRequest(id).addModification(modification));
} catch (LdapException ldex) {
if (debug.warningEnabled()) {
debug.warning("DataLayer.changePassword:", ldex);
}
ResultCode errorCode = ldex.getResult().getResultCode();
if (ResultCode.NO_SUCH_OBJECT.equals(errorCode)) {
throw new EntryNotFoundException(id, ldex);
} else if (ResultCode.INSUFFICIENT_ACCESS_RIGHTS.equals(errorCode)) {
throw new AccessRightsException(id, ldex);
} else {
throw new UMSException(id, ldex);
}
}
} catch (LDAPServiceException ex) {
debug.error("DataLayer.changePassword:", ex);
throw new UMSException(id, ex);
}
}
Aggregations