org.jboss.security.auth.spi
public class: LdapLoginModule [javadoc |
source]
java.lang.Object
org.jboss.security.auth.spi.AbstractServerLoginModule
org.jboss.security.auth.spi.UsernamePasswordLoginModule
org.jboss.security.auth.spi.LdapLoginModule
All Implemented Interfaces:
LoginModule
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:
Context.INITIAL_CONTEXT_FACTORY = "java.naming.factory.initial"
Context.SECURITY_PROTOCOL = "java.naming.security.protocol"
Context.PROVIDER_URL = "java.naming.provider.url"
Context.SECURITY_AUTHENTICATION = "java.naming.security.authentication"
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
};
- author:
Scott.Stark - @jboss.org
- version:
$ - Revision: 1.7.4.5 $
| Method from org.jboss.security.auth.spi.LdapLoginModule Detail: |
protected Group[] getRoleSets() throws LoginException {
Group[] roleSets = {userRoles};
return roleSets;
}
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. |
protected String getUsersPassword() throws LoginException {
return "";
}
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. |
protected boolean validatePassword(String inputPassword,
String expectedPassword) {
boolean isValid = false;
if( inputPassword != null )
{
// See if this is an empty password that should be disallowed
if( inputPassword.length() == 0 )
{
// Check for an allowEmptyPasswords option
boolean allowEmptyPasswords = true;
String flag = (String) options.get("allowEmptyPasswords");
if( flag != null )
allowEmptyPasswords = Boolean.valueOf(flag).booleanValue();
if( allowEmptyPasswords == false )
{
super.log.trace("Rejecting empty password due to allowEmptyPasswords");
return false;
}
}
try
{
// Validate the password by trying to create an initial context
String username = getUsername();
createLdapInitContext(username, inputPassword);
isValid = true;
}
catch(NamingException e)
{
super.log.debug("Failed to validate password", e);
}
}
return isValid;
}
Validate the inputPassword by creating a ldap InitialContext with the
SECURITY_CREDENTIALS set to the password. |