org.jboss.security.auth.spi
Class LdapLoginModule

java.lang.Object
  extended by org.jboss.security.auth.spi.AbstractServerLoginModule
      extended by org.jboss.security.auth.spi.UsernamePasswordLoginModule
          extended by org.jboss.security.auth.spi.LdapLoginModule
All Implemented Interfaces:
LoginModule

public class LdapLoginModule
extends UsernamePasswordLoginModule

An implementation of LoginModule that authenticates against an LDAP server using JNDI, based on the configuration properties.

The LoginModule options include whatever options your LDAP JNDI provider supports. Examples of standard property names are:

The Context.SECURITY_PRINCIPAL is set to the distinguished name of the user as obtained by the callback handler and the Context.SECURITY_CREDENTIALS property is either set to the String password or Object credential depending on the useObjectCredential option.

Additional module properties include:

A sample login config:

 testLdap {
 org.jboss.security.auth.spi.LdapLoginModule required
 java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory
 java.naming.provider.url="ldap://ldaphost.jboss.org:1389/"
 java.naming.security.authentication=simple
 principalDNPrefix=uid=
 uidAttributeID=userid
 roleAttributeID=roleName
 principalDNSuffix=,ou=People,o=jboss.org
 rolesCtxDN=cn=JBossSX Tests,ou=Roles,o=jboss.org
 };

 testLdap2 {
 org.jboss.security.auth.spi.LdapLoginModule required
 java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory
 java.naming.provider.url="ldap://ldaphost.jboss.org:1389/"
 java.naming.security.authentication=simple
 principalDNPrefix=uid=
 uidAttributeID=userid
 roleAttributeID=roleName
 principalDNSuffix=,ou=People,o=jboss.org
 userRolesCtxDNAttributeName=ou=Roles,dc=user1,dc=com
 };

 testLdapToActiveDirectory {
 org.jboss.security.auth.spi.LdapLoginModule required
 java.naming.factory.initial=com.sun.jndi.ldap.LdapCtxFactory
 java.naming.provider.url="ldap://ldaphost.jboss.org:1389/"
 java.naming.security.authentication=simple
 rolesCtxDN=cn=Users,dc=ldaphost,dc=jboss,dc=org
 uidAttributeID=userPrincipalName
 roleAttributeID=memberOf
 roleAttributeIsDN=true
 roleNameAttributeID=name
 };
 

Version:
$Revision: 1.14.6.9 $
Author:
Scott.Stark@jboss.org

Field Summary
 
Fields inherited from class org.jboss.security.auth.spi.AbstractServerLoginModule
callbackHandler, log, loginOk, options, principalClassName, sharedState, subject, unauthenticatedIdentity, useFirstPass
 
Constructor Summary
LdapLoginModule()
           
 
Method Summary
protected  Group[] getRoleSets()
          Overriden by subclasses to return the Groups that correspond to the to the role sets assigned to the user.
protected  String getUsersPassword()
          Overriden to return an empty password string as typically one cannot obtain a user's password.
protected  boolean validatePassword(String inputPassword, String expectedPassword)
          Validate the inputPassword by creating a ldap InitialContext with the SECURITY_CREDENTIALS set to the password.
 
Methods inherited from class org.jboss.security.auth.spi.UsernamePasswordLoginModule
createPasswordHash, getCredentials, getIdentity, getUnauthenticatedIdentity, getUsername, getUsernameAndPassword, getValidateError, initialize, login, setValidateError
 
Methods inherited from class org.jboss.security.auth.spi.AbstractServerLoginModule
abort, commit, createGroup, createIdentity, getUseFirstPass, logout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LdapLoginModule

public LdapLoginModule()
Method Detail

getUsersPassword

protected String getUsersPassword()
                           throws LoginException
Overriden to return an empty password string as typically one cannot obtain a user's password. We also override the validatePassword so this is ok.

Specified by:
getUsersPassword in class UsernamePasswordLoginModule
Returns:
and empty password String
Throws:
LoginException

getRoleSets

protected Group[] getRoleSets()
                       throws LoginException
Overriden by subclasses to return the Groups that correspond to the to the role sets assigned to the user. Subclasses should create at least a Group named "Roles" that contains the roles assigned to the user. A second common group is "CallerPrincipal" that provides the application identity of the user rather than the security domain identity.

Specified by:
getRoleSets in class AbstractServerLoginModule
Returns:
Group[] containing the sets of roles
Throws:
LoginException

validatePassword

protected boolean validatePassword(String inputPassword,
                                   String expectedPassword)
Validate the inputPassword by creating a ldap InitialContext with the SECURITY_CREDENTIALS set to the password.

Overrides:
validatePassword in class UsernamePasswordLoginModule
Parameters:
inputPassword - the password to validate.
expectedPassword - ignored
Returns:
true if the inputPassword is valid, false otherwise.


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.