Class ActiveDirectoryLdapAuthenticationProvider

java.lang.Object
com.codename1.backend.security.ldap.ActiveDirectoryLdapAuthenticationProvider
All Implemented Interfaces:
AuthenticationProvider

public final class ActiveDirectoryLdapAuthenticationProvider extends Object implements AuthenticationProvider

Signs users in against Active Directory, as Spring's provider of the same name: binds as user@domain, reads the user's entry by userPrincipalName, and makes each group in memberOf an authority named by the group's CN (Domain Admins, no prefix).

A refused bind is told apart by Active Directory's sub-error code: a locked account is a LockedException, an expired password a CredentialsExpiredException, a disabled account a DisabledException, an expired account an AccountExpiredException; the rest is a BadCredentialsException.

http.authenticationProvider(new ActiveDirectoryLdapAuthenticationProvider(
        "corp.example", "ldaps://dc1.corp.example"));
  • Constructor Details

    • ActiveDirectoryLdapAuthenticationProvider

      public ActiveDirectoryLdapAuthenticationProvider(String domain, String url)
    • ActiveDirectoryLdapAuthenticationProvider

      public ActiveDirectoryLdapAuthenticationProvider(String domain, String url, String rootDn)
      Parameters:
      rootDn - where users are searched; null for the domain's root (corp.example is dc=corp,dc=example)
  • Method Details

    • getContextSource

      public LdapContextSource getContextSource()
      The context source, for its timeouts and TLS settings.
    • setSearchFilter

      public void setSearchFilter(String searchFilter)
      The user filter; {0} is user@domain, {1} the name as typed.
    • setSearchNestedGroups

      public void setSearchNestedGroups(boolean nestedGroups)
      Whether a user's authorities include the groups their groups are in. Active Directory's memberOf lists direct groups only; with this on, one more search asks the directory for every group that contains the user through any chain (LDAP_MATCHING_RULE_IN_CHAIN). Off by default, as in Spring, since on a large forest that search is not cheap.
    • authenticate

      public Authentication authenticate(Authentication authentication)
      Description copied from interface: AuthenticationProvider

      The accepted authentication, or null when this provider cannot decide and the next one should be asked.

      Throws
      • AuthenticationException: when the token is refused
      Specified by:
      authenticate in interface AuthenticationProvider
    • supports

      public boolean supports(Class<?> authentication)
      Description copied from interface: AuthenticationProvider
      Whether this provider checks tokens of this class.
      Specified by:
      supports in interface AuthenticationProvider