public class LdapCallbackHandler extends AbstractCallbackHandler implements CallbackHandler
A CallbackHandler using the LDAP to match the passed password.
There are two callbacks that can be passed to this handler.
PasswordCallback: Passing this callback will get the password for the user.
The returned password will not be in clear text. It will
be in the hashed form the ldap server has stored.
VerifyPasswordCallback Passing this callback with a value will make the handler
to do a ldap bind to verify the user password.
The main method is #setConfiguration(Map) which takes in a map of String key/value pairs.
The possible pairs are:
NameCallback
will be substituted into the filter anywhere a "{0}" expression is seen.
This substitution behavior comes from the standard.Example Usages:
LdapCallbackHandler cbh = new LdapCallbackHandler(); Mapmap = new HashMap (); map.put("bindDN", "cn=Directory Manager"); map.put("bindCredential", "password"); map.put("baseFilter", "(uid={0})"); map.put("java.naming.factory.initial", "com.sun.jndi.ldap.LdapCtxFactory"); map.put("java.naming.provider.url", "ldap://localhost:10389"); map.put("baseCtxDN", "ou=People,dc=jboss,dc=org"); cbh.setConfiguration(map); NameCallback ncb = new NameCallback("Enter"); ncb.setName("jduke"); VerifyPasswordCallback vpc = new VerifyPasswordCallback(); vpc.setValue("theduke"); cbh.handle(new Callback[] {ncb,vpc} ); assertTrue(vpc.isVerified());
| Modifier and Type | Field and Description |
|---|---|
protected String |
bindCredential |
protected String |
bindDN |
protected String |
distinguishedNameAttribute |
protected boolean |
isPasswordValidated |
protected Map<String,String> |
options |
protected String |
passwordAttributeID |
protected int |
searchTimeLimit |
userName| Constructor and Description |
|---|
LdapCallbackHandler() |
| Modifier and Type | Method and Description |
|---|---|
protected String |
bindDNAuthentication(InitialLdapContext ctx,
String user,
Object credential,
String baseDN,
String filter) |
protected String |
getBindCredential() |
protected String |
getBindDN() |
void |
handle(Callback[] callbacks) |
protected void |
handleCallBack(Callback c)
Handle a
Callback |
protected void |
safeClose(InitialLdapContext ic) |
protected void |
safeClose(NamingEnumeration results) |
void |
setConfiguration(Map<String,String> config) |
protected void |
setPasswordCallbackValue(Object thePass,
PasswordCallback passwdCallback) |
protected void |
verifyPassword(VerifyPasswordCallback vpc) |
getUserNameprotected String bindDN
protected String bindCredential
protected String passwordAttributeID
protected int searchTimeLimit
protected String distinguishedNameAttribute
protected boolean isPasswordValidated
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
handle in interface CallbackHandlerIOExceptionUnsupportedCallbackExceptionprotected void handleCallBack(Callback c) throws UnsupportedCallbackException, NamingException
Callbackc - callbackUnsupportedCallbackException - If the callback is not supported by this handlerNamingExceptionprotected void verifyPassword(VerifyPasswordCallback vpc) throws NamingException
NamingExceptionprotected String getBindDN()
protected String getBindCredential()
protected void setPasswordCallbackValue(Object thePass, PasswordCallback passwdCallback)
protected String bindDNAuthentication(InitialLdapContext ctx, String user, Object credential, String baseDN, String filter) throws NamingException
ctx - - the context to search fromuser - - the input usernamecredential - - the bind credentialbaseDN - - base DN to search the ctx fromfilter - - the search filter stringNamingExceptionprotected void safeClose(NamingEnumeration results)
protected void safeClose(InitialLdapContext ic)
Copyright © 2017 JBoss by Red Hat. All rights reserved.