Package com.carfey.suite.security
Class LdapAuthenticator
- java.lang.Object
-
- com.carfey.suite.security.LdapAuthenticator
-
- All Implemented Interfaces:
Authenticator,Authenticator
public class LdapAuthenticator extends java.lang.Object implements Authenticator
LdapAuthenticator class provides basic authentication against the configured ldap instance using the provided url, dn base and optional groupDN for membership verification.
When the JavaDoc refers to supported delimiter, it is always 3 tildes or ~~~
The following are the config keys that are used.
- com.carfey.suite.security.LdapAuthenticator.url
- com.carfey.suite.security.LdapAuthenticator.dn.base
- com.carfey.suite.security.LdapAuthenticator.dn.attribute
- com.carfey.suite.security.LdapAuthenticator.accessDN
- com.carfey.suite.security.LdapAuthenticator.role.ROLENAME.cn
- com.carfey.suite.security.LdapAuthenticator.role.ROLENAME.roleName
- com.carfey.suite.security.LdapAuthenticator.securityAuthentication
- com.carfey.suite.security.LdapAuthenticator.lookupDnAttribute
- com.carfey.suite.security.LdapAuthenticator.loginAttribute
- com.carfey.suite.security.LdapAuthenticator.anonymousEnabled
- com.carfey.suite.security.LdapAuthenticator.searchUserFullDn
- com.carfey.suite.security.LdapAuthenticator.searchPassword
- com.carfey.suite.security.LdapAuthenticator.searchUserDnBase
- com.carfey.suite.security.LdapAuthenticator.groupMembershipAttribute
- com.carfey.suite.security.LdapAuthenticator.dynamicRole.prefix
- com.carfey.suite.security.LdapAuthenticator.dynamicRole.suffix
- com.carfey.suite.security.LdapAuthenticator.checkActiveAttribute
urlis a fully qualified url with protocol - e.g. ldap://ldap.carfey.com:389 or ldaps://ldap.carfey.com:636
dn.baseis the base to which the authenticated user's cn, uuid or other will be prepended - e.g. ou=people,o=CarfeySoftware. May be a delimited list of values.
dn.attributeis attribute type used in building up the user string - e.g. cn or uuid. It will result in a Bind request with the Security Principal set as {dn.attribute}={username},{dn.base}
accessDNis the group against which to verify access - e.g. cn=SchedulerAccess,ou=groups,o=CarfeySoftware. May be a delimited list of values.
role.ROLENAME.dnis used to determine membership in custom group - e.g. com.carfey.suite.security.LdapAuthenticator.role.WRITE.dn=SchedulerWrite,ou=groups,o=CarfeySoftware. May be a delimited list of values.
role.ROLENAME.roleNameis used to specify the role that will be assigned to the user when membership is verified - e.g. com.carfey.suite.security.LdapAuthenticator.role.WRITE.roleName.MyWriteRole
securityAuthenticationis optional SECURITY_AUTHENTICATION mechanism. Defaults to simple
lookupDnAttributedefaults to false and is only used when you wish to login via an LDAP attribute that is not part of the dn. A matching entry is found in the LDAP Directory (using anonymous or a fixed lookup account). The next 4 attributes are only used when this attribute is set to true
loginAttributeis the name of the attribute to build the dn for eventual authentication.
anonymousEnableddefaults to false and is used to perform the dn attribute lookups anonymously (without a session authenticated by user/password).
searchUserFullDn,searchPasswordandsearchUserDnBaseare used to authenticate the dn attribute search request.
groupMembershipAttributeis an optional attribute used to specify usage of additional group membership attribute(s), delimited values supported, in addition to the default supported attributes,"uniquemember","uniqueMember","member","roleOccupant","memberOf","MemberOf"
Membership failures will result in a non-specific AuthenticationException being thrown.
dynamicRole.prefixanddynamicRole.suffixare used to provide a convention that is used for dynamic role DNs. For example, if your convention for dynamic role DNs is cn=Scheduler<RoleName>,ou=groups,o=MyOrgHere, you would configured prefix and suffix asdynamicRole.prefix="cn=Scheduler"anddynamicRole.suffix=",ou=groups,o=MyOrgHere".
checkActiveAttributeis used to disable active attribute checking (enabled by default). Support for ActiveDirectory is via the userAccountControl attribute (NOT Bit 2), OpenLDAP supported by shadowExpire (if -1, meaning never expires, or expires in future) or accountStatus attribute equals "active" ignoring case.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.carfey.suite.security.Authenticator
Authenticator.AuthenticationFailedException, Authenticator.AuthenticationMembershipFailedException, Authenticator.AuthenticatorException
-
-
Constructor Summary
Constructors Constructor Description LdapAuthenticator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Userauthenticate(java.lang.String user, java.lang.String pass)User provided must be valid in building the distinguished name as follows:
mAttribute + "=" + user + "," + mBase.
mAttribute and mBase are defined above.protected voidbuildUpContextEnvironment(java.lang.String pass, java.lang.String dn, java.util.Hashtable<java.lang.String,java.lang.String> environment)Stores needed environment attributes.protected booleanisMemberOfGroup(javax.naming.directory.DirContext authContext, java.lang.String groupNamesConfig, java.lang.String dn)Checks for membership of group/role trying attributes "uniquemember","uniqueMember","member","roleOccupant","memberOf" Requires browse/read permission of group or role in question.protected booleanisUserActive(javax.naming.directory.DirContext authContext, java.lang.String dn)Overridable method to determine if a given authenticated user is active or not.booleansupportsRememberMe()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.carfey.suite.security.Authenticator
authenticateREST
-
-
-
-
Constructor Detail
-
LdapAuthenticator
public LdapAuthenticator() throws ValidationException- Throws:
ValidationException
-
-
Method Detail
-
authenticate
public User authenticate(java.lang.String user, java.lang.String pass) throws Authenticator.AuthenticationFailedException
User provided must be valid in building the distinguished name as follows:
mAttribute + "=" + user + "," + mBase.
mAttribute and mBase are defined above.- Specified by:
authenticatein interfaceAuthenticator- Throws:
Authenticator.AuthenticationFailedException
-
buildUpContextEnvironment
protected void buildUpContextEnvironment(java.lang.String pass, java.lang.String dn, java.util.Hashtable<java.lang.String,java.lang.String> environment)Stores needed environment attributes. Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" Context.PROVIDER_URL, {{ldap_url}} Context.SECURITY_AUTHENTICATION, "simple" or overridden securityAuthentication by configuration com.carfey.suite.security.LdapAuthenticator.securityAuthentication Context.SECURITY_PRINCIPAL, {{user_dn}} Context.SECURITY_CREDENTIALS, {{user_pass}}
-
isMemberOfGroup
protected boolean isMemberOfGroup(javax.naming.directory.DirContext authContext, java.lang.String groupNamesConfig, java.lang.String dn) throws javax.naming.NamingExceptionChecks for membership of group/role trying attributes "uniquemember","uniqueMember","member","roleOccupant","memberOf" Requires browse/read permission of group or role in question.- Throws:
javax.naming.NamingException
-
isUserActive
protected boolean isUserActive(javax.naming.directory.DirContext authContext, java.lang.String dn)Overridable method to determine if a given authenticated user is active or not.
- ActiveDirectory: userAccountControl attribute if present is NOT Bit 2 = active
- OpenLDAP: shadowExpire attribute if present is -1 (never expires) or is an epoch millis value in the future, in other words greater than
System.currentTimeMillis() - Other: accountStatus attribute if present equals "active" ignoring case.
- If none of the above attributes is set, assumes the user is active.
Any LDAP attribute check failure is logged and assumes user is inactive.- Since:
- 6.3.3 method is protected and overridable
-
supportsRememberMe
public boolean supportsRememberMe()
- Specified by:
supportsRememberMein interfaceAuthenticator
-
-