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 |
baseDN |
protected String |
baseFilter |
protected String |
bindCredential |
protected String |
bindDN |
protected String |
distinguishedNameAttribute |
protected boolean |
isPasswordValidated |
protected static org.jboss.logging.Logger |
log |
protected Map<String,String> |
options |
protected boolean |
parseUsername |
protected String |
passwordAttributeID |
protected int |
recursion |
protected int |
searchScope |
protected int |
searchTimeLimit |
protected boolean |
trace |
protected String |
usernameBeginString |
protected String |
usernameEndString |
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) |
getUserName
protected static org.jboss.logging.Logger log
protected boolean trace
protected String bindDN
protected String bindCredential
protected String baseDN
protected String baseFilter
protected String passwordAttributeID
protected int recursion
protected int searchTimeLimit
protected int searchScope
protected String distinguishedNameAttribute
protected boolean parseUsername
protected String usernameBeginString
protected String usernameEndString
protected boolean isPasswordValidated
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
handle
in interface CallbackHandler
IOException
UnsupportedCallbackException
protected void handleCallBack(Callback c) throws UnsupportedCallbackException, NamingException
Callback
c
- callbackUnsupportedCallbackException
- If the callback is not supported by this handlerNamingException
protected void verifyPassword(VerifyPasswordCallback vpc) throws NamingException
NamingException
protected 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 stringNamingException
protected void safeClose(NamingEnumeration results)
protected void safeClose(InitialLdapContext ic)
Copyright © 2012 JBoss Inc.. All Rights Reserved.