Class LdapContextSource

java.lang.Object
com.codename1.backend.security.ldap.LdapContextSource

public final class LdapContextSource extends Object

Where the directory is and how to reach it: the server URLs, tried in order, the base every name is under, the account searches run as, and the TLS settings. Spring's LdapContextSource, from the same settings Spring Boot reads (spring.ldap.* there, cn1.ldap.* here):

cn1.ldap.urls=ldaps://ldap1.corp.example,ldaps://ldap2.corp.example
cn1.ldap.base=dc=corp,dc=example
cn1.ldap.username=cn=reader,dc=corp,dc=example
cn1.ldap.password=${LDAP_READER_PASSWORD}

plus cn1.ldap.starttls (upgrade ldap:// URLs), cn1.ldap.ca-file (PEM of the authorities to trust), cn1.ldap.connect-timeout-millis and cn1.ldap.read-timeout-millis (both 10 seconds by default).

Connections are not pooled: each sign-in opens its own and closes it, so a directory that is down costs one connect timeout per attempt and nothing stays open between sign-ins.

  • Field Details

  • Constructor Details

    • LdapContextSource

      public LdapContextSource(String... urls)
      Parameters:
      urls - ldap://host[:port][/base] or ldaps://...; the base of the first is used when setBase(String) is not called
  • Method Details

    • fromConfig

      public static LdapContextSource fromConfig(Config config) throws IOException
      The context source the cn1.ldap.* settings describe, or null when cn1.ldap.urls is not set.
      Throws:
      IOException
    • getUrls

      public List<String> getUrls()
    • getBase

      public String getBase()
    • setBase

      public void setBase(String base)
    • setUserDn

      public void setUserDn(String userDn)
      The account searches run as; empty for anonymous searches.
    • setPassword

      public void setPassword(String password)
    • setStartTls

      public void setStartTls(boolean startTls)
    • setCaFile

      public void setCaFile(String caFile)
    • setConnectTimeoutMillis

      public void setConnectTimeoutMillis(int millis)
    • setReadTimeoutMillis

      public void setReadTimeoutMillis(int millis)
    • absolute

      public String absolute(String name)
      name under the base: uid=ada,ou=people becomes uid=ada,ou=people,dc=corp,dc=example.
    • connect

      public LdapConnection connect() throws IOException
      A connection to the first server that answers, not bound.
      Throws:
      IOException
    • readOnly

      public LdapConnection readOnly() throws IOException
      A connection bound as the search account, or anonymous when none is set.
      Throws:
      IOException