Package org.ldaptive

Class LdapURL


  • public class LdapURL
    extends Object
    Class for parsing LDAP URLs. See RFC 4516. Expects URLs of the form scheme://hostname:port/baseDn?attrs?scope?filter. This implementation does not support URL extensions.
    • Field Detail

      • URL_PATTERN

        protected static final Pattern URL_PATTERN
        Pattern to match LDAP URL.
      • DEFAULT_LDAP_PORT

        protected static final int DEFAULT_LDAP_PORT
        Default LDAP port, value is 389.
        See Also:
        Constant Field Values
      • DEFAULT_LDAPS_PORT

        protected static final int DEFAULT_LDAPS_PORT
        Default LDAPS port, value is 636.
        See Also:
        Constant Field Values
      • DEFAULT_FILTER

        protected static final String DEFAULT_FILTER
        Default search filter value is '(objectClass=*)'.
        See Also:
        Constant Field Values
      • DEFAULT_ATTRIBUTES

        protected static final String[] DEFAULT_ATTRIBUTES
        Default return attributes, value is all user attributes.
      • HASH_CODE_SEED

        private static final int HASH_CODE_SEED
        hash code seed.
        See Also:
        Constant Field Values
      • scheme

        private String scheme
        Scheme of the ldap url.
      • hostname

        private String hostname
        Hostname of the ldap url.
      • port

        private int port
        Port of the ldap url.
      • baseDn

        private String baseDn
        Base DN of the ldap url.
      • attributes

        private String[] attributes
        Attributes of the ldap url.
      • scope

        private SearchScope scope
        Search scope of the ldap url.
      • filter

        private String filter
        Search filter of the ldap url.
      • retryMetadata

        private LdapURLRetryMetadata retryMetadata
        Metadata that describes connection failures on this URL.
      • active

        private boolean active
        False if the last connection attempt to this URL failed, which should result in updating retryMetadata, otherwise true.
      • inetAddress

        private InetAddress inetAddress
        IP address resolved for this URL.
    • Constructor Detail

      • LdapURL

        private LdapURL()
        Private constructor.
      • LdapURL

        public LdapURL​(String hostname,
                       int port)
        Creates a new ldap url.
        Parameters:
        hostname - LDAP server hostname
        port - TCP port the LDAP server is listening on
      • LdapURL

        public LdapURL​(String url)
        Creates a new ldap url.
        Parameters:
        url - LDAP url
      • LdapURL

        protected LdapURL​(String scheme,
                          String hostname,
                          int port,
                          String baseDn,
                          String[] attributes,
                          SearchScope scope,
                          String filter)
        Creates a new ldap url.
        Parameters:
        scheme - url scheme
        hostname - url hostname
        port - url port
        baseDn - base DN
        attributes - attributes
        scope - search scope
        filter - search filter
    • Method Detail

      • getScheme

        public String getScheme()
        Returns the scheme.
        Returns:
        scheme
      • getHostname

        public String getHostname()
        Returns the hostname.
        Returns:
        hostname
      • getPort

        public int getPort()
        Returns the port. If no port was supplied, returns the default port for the scheme.
        Returns:
        port
      • isDefaultPort

        public boolean isDefaultPort()
        Returns false if a port was supplied in this url.
        Returns:
        false if a port was supplied in this url
      • getBaseDn

        public String getBaseDn()
        Returns the base DN.
        Returns:
        baseDn
      • isDefaultBaseDn

        public boolean isDefaultBaseDn()
        Returns whether a base DN was supplied in this url.
        Returns:
        whether a base DN was supplied in this url
      • getAttributes

        public String[] getAttributes()
        Returns the attributes.
        Returns:
        attributes
      • isDefaultAttributes

        public boolean isDefaultAttributes()
        Returns whether attributes were supplied in this url.
        Returns:
        whether an attributes were supplied in this url
      • getScope

        public SearchScope getScope()
        Returns the scope.
        Returns:
        scope
      • isDefaultScope

        public boolean isDefaultScope()
        Returns whether a scope was supplied in this url.
        Returns:
        whether a scope was supplied in this url
      • getFilter

        public String getFilter()
        Returns the filter.
        Returns:
        filter
      • isDefaultFilter

        public boolean isDefaultFilter()
        Returns whether a filter was supplied in this url.
        Returns:
        whether a filter was supplied in this url
      • getUrl

        public String getUrl()
        Returns the formatted URL as scheme://hostname:port/baseDn?attrs?scope?filter.
        Returns:
        url
      • getHostnameWithPort

        public String getHostnameWithPort()
        Returns the hostname:port.
        Returns:
        hostname:port
      • getHostnameWithSchemeAndPort

        public String getHostnameWithSchemeAndPort()
        Returns the scheme://hostname:port.
        Returns:
        scheme://hostname:port
      • getRetryMetadata

        LdapURLRetryMetadata getRetryMetadata()
        Returns the retry metadata.
        Returns:
        metadata describing retry attempts for connections made this URL.
      • setRetryMetadata

        void setRetryMetadata​(LdapURLRetryMetadata metadata)
        Sets the retry metadata.
        Parameters:
        metadata - retry metadata
      • isActive

        boolean isActive()
        Returns whether this URL is currently active.
        Returns:
        true if this URL can be connected to, false otherwise.
      • activate

        void activate()
        Marks this URL as active.
      • deactivate

        void deactivate()
        Marks this URL as inactive.
      • getInetAddress

        public InetAddress getInetAddress()
        Returns the resolved IP address.
        Returns:
        resolved IP address for this URL.
      • setInetAddress

        void setInetAddress​(InetAddress address)
        Sets the resolved IP address.
        Parameters:
        address - IP address for this URL
      • copy

        public static LdapURL copy​(LdapURL ldapURL)
        Returns a new ldap URL initialized with the supplied URL.
        Parameters:
        ldapURL - ldap URL to read properties from
        Returns:
        ldap URL
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • parseURL

        protected void parseURL​(String url)
        Matches the supplied url against a pattern and reads its components.
        Parameters:
        url - to parse