public class ConnectionUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
canConnectAsAdministrativeUser(String ldapUrl,
String dn,
String pwd,
int timeout)
Method used to know if we can connect as administrator in a server with a
given password and dn.
|
static InitialLdapContext |
cloneInitialLdapContext(InitialLdapContext ctx,
int timeout,
TrustManager trustManager,
KeyManager keyManager)
Clones the provided InitialLdapContext and returns a connection using
the same parameters.
|
static boolean |
connectedAsAdministrativeUser(InitialLdapContext ctx)
Method used to know if we are connected as administrator in a server with a
given InitialLdapContext.
|
static InitialLdapContext |
createLdapContext(String ldapURL,
String dn,
String pwd,
int timeout,
Hashtable<String,String> env)
Creates a clear LDAP connection and returns the corresponding LdapContext.
|
static InitialLdapContext |
createLdapsContext(String ldapsURL,
String dn,
String pwd,
int timeout,
Hashtable<String,String> env,
TrustManager trustManager,
KeyManager keyManager)
Creates an LDAPS connection and returns the corresponding LdapContext.
|
static InitialLdapContext |
createStartTLSContext(String ldapURL,
String dn,
String pwd,
int timeout,
Hashtable<String,String> env,
TrustManager trustManager,
KeyManager keyManager,
HostnameVerifier verifier)
Creates an LDAP+StartTLS connection and returns the corresponding
LdapContext.
|
static String |
getBindDN(InitialLdapContext ctx)
Returns the bind DN used in the provided InitialLdapContext.
|
static String |
getBindPassword(InitialLdapContext ctx)
Returns the password used in the provided InitialLdapContext.
|
static String |
getFirstValue(SearchResult entry,
String attrName)
Returns the String representation of the first value of an attribute in a
LDAP entry.
|
static String |
getHostName(InitialLdapContext ctx)
Returns the host name used in the provided InitialLdapContext.
|
static String |
getHostPort(InitialLdapContext ctx)
Returns the host port representation of the server to which this
context is connected.
|
static String |
getLdapUrl(InitialLdapContext ctx)
Returns the LDAP URL used in the provided InitialLdapContext.
|
static String |
getLDAPUrl(String host,
int port,
boolean useSSL)
Returns the LDAP URL for the provided parameters.
|
static int |
getPort(InitialLdapContext ctx)
Returns the port number used in the provided InitialLdapContext.
|
static Set<String> |
getValues(SearchResult entry,
String attrName)
Returns a Set with the String representation of the values of an attribute
in a LDAP entry.
|
static boolean |
isSSL(InitialLdapContext ctx)
Tells whether we are using SSL in the provided InitialLdapContext.
|
static boolean |
isStartTLS(InitialLdapContext ctx)
Tells whether we are using StartTLS in the provided InitialLdapContext.
|
public static InitialLdapContext createLdapContext(String ldapURL, String dn, String pwd, int timeout, Hashtable<String,String> env) throws NamingException
ldapURL - the target LDAP URLdn - passed as Context.SECURITY_PRINCIPAL if not nullpwd - passed as Context.SECURITY_CREDENTIALS if not nulltimeout - passed as com.sun.jndi.ldap.connect.timeout if > 0env - null or additional environment propertiesNamingException - the exception thrown when instantiating InitialLdapContextContext,
InitialLdapContextpublic static InitialLdapContext createLdapsContext(String ldapsURL, String dn, String pwd, int timeout, Hashtable<String,String> env, TrustManager trustManager, KeyManager keyManager) throws NamingException
ldapsURL - the target *LDAPS* URL.dn - passed as Context.SECURITY_PRINCIPAL if not null.pwd - passed as Context.SECURITY_CREDENTIALS if not null.timeout - passed as com.sun.jndi.ldap.connect.timeout if > 0.env - null or additional environment properties.trustManager - null or the trust manager to be invoked during SSL
negotiation.keyManager - null or the key manager to be invoked during SSL
negotiation.NamingException - the exception thrown when instantiating
InitialLdapContext.Context,
InitialLdapContext,
TrustedSocketFactorypublic static InitialLdapContext cloneInitialLdapContext(InitialLdapContext ctx, int timeout, TrustManager trustManager, KeyManager keyManager) throws NamingException
ctx - the connection to be cloned.timeout - the timeout to establish the connection in milliseconds.
Use 0 to express no timeout.trustManager - the trust manager to be used to connect.keyManager - the key manager to be used to connect.NamingException - if there was an error creating the new connection.public static InitialLdapContext createStartTLSContext(String ldapURL, String dn, String pwd, int timeout, Hashtable<String,String> env, TrustManager trustManager, KeyManager keyManager, HostnameVerifier verifier) throws NamingException
ldapURL - the target *LDAP* URL.dn - passed as Context.SECURITY_PRINCIPAL if not null.pwd - passed as Context.SECURITY_CREDENTIALS if not null.timeout - passed as com.sun.jndi.ldap.connect.timeout if > 0.env - null or additional environment properties.trustManager - null or the trust manager to be invoked during SSL
negotiation.keyManager - null or the key manager to be invoked during SSL
negotiation.verifier - null or the hostname verifier to be setup in the
StartTlsResponse.NamingException - the exception thrown when instantiating
InitialLdapContext.Context,
InitialLdapContext,
StartTlsRequest,
StartTlsResponse,
TrustedSocketFactorypublic static String getLdapUrl(InitialLdapContext ctx)
ctx - the context to analyze.public static String getHostName(InitialLdapContext ctx)
ctx - the context to analyze.public static int getPort(InitialLdapContext ctx)
ctx - the context to analyze.public static String getHostPort(InitialLdapContext ctx)
ctx - the context to analyze.public static String getBindDN(InitialLdapContext ctx)
ctx - the context to analyze.public static String getBindPassword(InitialLdapContext ctx)
ctx - the context to analyze.public static boolean isSSL(InitialLdapContext ctx)
ctx - the context to analyze.true if we are using SSL and false
otherwise.public static boolean isStartTLS(InitialLdapContext ctx)
ctx - the context to analyze.true if we are using StartTLS and false
otherwise.public static boolean canConnectAsAdministrativeUser(String ldapUrl, String dn, String pwd, int timeout)
ldapUrl - the LDAP URL of the server.dn - the dn to be used.pwd - the password to be used.timeout - the timeout to establish the connection in milliseconds.
Use 0 to express no timeout.true if we can connect and read the configuration and
false otherwise.public static boolean connectedAsAdministrativeUser(InitialLdapContext ctx)
ctx - the context.true if we are connected and read the configuration
and false otherwise.public static String getLDAPUrl(String host, int port, boolean useSSL)
host - the host name.port - the LDAP port.useSSL - whether to use SSL or not.public static String getFirstValue(SearchResult entry, String attrName) throws NamingException
entry - the entry.attrName - the attribute name.NamingException - if there is an error processing the entry.public static Set<String> getValues(SearchResult entry, String attrName) throws NamingException
entry - the entry.attrName - the attribute name.NamingException - if there is an error processing the entry.Copyright © 2010-2015 ForgeRock AS. All Rights Reserved.