Class LdapAuthenticationProvider

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

public final class LdapAuthenticationProvider extends Object implements AuthenticationProvider

Signs users in against an LDAP directory, for form login and HTTP Basic alike: an LdapAuthenticator checks the password, an LdapAuthoritiesPopulator answers the roles.

LdapContextSource directory = new LdapContextSource("ldaps://ldap.corp.example/dc=corp,dc=example");
BindAuthenticator bind = new BindAuthenticator(directory);
bind.setUserDnPatterns("uid={0},ou=people");
http.authenticationProvider(new LdapAuthenticationProvider(bind,
        new DefaultLdapAuthoritiesPopulator(directory, "ou=groups")))
    .formLogin(Customizer.withDefaults());

or from the configuration, fromConfig(Config). The principal of the authentication is an LdapUserDetails. For Active Directory see ActiveDirectoryLdapAuthenticationProvider.

  • Constructor Details

  • Method Details

    • fromConfig

      public static AuthenticationProvider fromConfig(Config config) throws IOException

      The provider the configuration describes, or null when cn1.ldap.urls is not set. Besides LdapContextSource's settings:

      • cn1.ldap.user-dn-patterns: uid={0},ou=people, several separated by ;
      • cn1.ldap.user-search-base and cn1.ldap.user-search-filter ((uid={0}) by default), used when no DN pattern is set
      • cn1.ldap.group-search-base: where the groups are; none, no roles but ROLE_USER
      • cn1.ldap.group-search-filter: (member={0}) by default
      • cn1.ldap.group-role-attribute: cn by default
      Throws:
      IOException
    • 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