Class LdapUrl

java.lang.Object
org.apache.directory.api.ldap.model.url.LdapUrl

public class LdapUrl extends Object
Decodes a LdapUrl, and checks that it complies with the RFC 4516. The grammar is the following :
ldapurl    = scheme "://" [host [ ":" port]] ["/"
                  dn ["?" [attributes] ["?" [scope]
                  ["?" [filter] ["?" extensions]]]]]
scheme     = "ldap" | "ldaps"                        Note: the RFC 4516 does not say that 'ldaps' is valid...
dn         = Dn
attributes = attrdesc ["," attrdesc]*
attrdesc   = selector ["," selector]*
selector   = attributeSelector (from Section 4.5.1 of RFC4511)
scope      = "base" / "one" / "sub"
extensions = extension ["," extension]*
extension  = ["!"] extype ["=" exvalue]
extype     = oid (from Section 1.4 of RFC4512)
exvalue    = LDAPString (from Section 4.1.2 of RFC4511)
host       = host from Section 3.2.2 of RFC3986
port       = port from Section 3.2.3 of RFC3986
filter     = filter from Section 3 of RFC 4515
From Section 3.2.1/2 of RFC3986
host        = IP-literal / IPv4address / reg-name
port        = *DIGIT
IP-literal  = "[" ( IPv6address / IPvFuture  ) "]"
IPvFuture   = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
IPv6address = 6( h16 ":" ) ls32 
              | "::" 5( h16 ":" ) ls32
              | [               h16 ] "::" 4( h16 ":" ) ls32
              | [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
              | [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
              | [ *3( h16 ":" ) h16 ] "::"    h16 ":"   ls32
              | [ *4( h16 ":" ) h16 ] "::"              ls32
              | [ *5( h16 ":" ) h16 ] "::"              h16
              | [ *6( h16 ":" ) h16 ] "::"
IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
dec-octet   = DIGIT | [1-9] DIGIT | "1" 2DIGIT | "2" [0-4] DIGIT | "25" [0-5]
reg-name    = *( unreserved / pct-encoded / sub-delims )
unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims  = "!" | "$" | "&" | "'" | "(" | ")" | "*" | "+" | "," | ";" | "="
h16         = 1*4HEXDIG
ls32        = ( h16 ":" h16 ) / IPv4address
DIGIT       = 0..9
ALPHA       = A-Z / a-z
HEXDIG      = DIGIT / A-F / a-f
Author:
Apache Directory Project
  • Field Details

    • LDAPS_SCHEME

      public static final String LDAPS_SCHEME
      The constant for "ldaps://" scheme.
      See Also:
    • LDAP_SCHEME

      public static final String LDAP_SCHEME
      The constant for "ldap://" scheme.
      See Also:
    • EMPTY_URL

      public static final LdapUrl EMPTY_URL
      A null LdapUrl
  • Constructor Details

    • LdapUrl

      public LdapUrl()
      Construct an empty LdapUrl
    • LdapUrl

      public LdapUrl(String stringUrl) throws LdapURLEncodingException
      Create a new LdapUrl from a String after having parsed it.
      Parameters:
      stringUrl - TheString that contains the LdapUrl
      Throws:
      LdapURLEncodingException - If the String does not comply with RFC 2255
  • Method Details

    • isValidInet4Address

      public boolean isValidInet4Address(String inet4Address)
      Validates an IPv4 address. Returns true if valid.
      Parameters:
      inet4Address - the IPv4 address to validate
      Returns:
      true if the argument contains a valid IPv4 address
    • isValidInet6Address

      public boolean isValidInet6Address(String inet6Address)
      This code source was taken from commons.validator 1.5.0 Validates an IPv6 address. Returns true if valid.
      Parameters:
      inet6Address - the IPv6 address to validate
      Returns:
      true if the argument contains a valid IPv6 address
      Since:
      1.4.1
    • urlEncode

      public static String urlEncode(String url, boolean doubleEncode)
      Encode a String to avoid special characters.
      RFC 4516, section 2.1. (Percent-Encoding)
      
      A generated LDAP URL MUST consist only of the restricted set of
      characters included in one of the following three productions defined
      in [RFC3986]:
      
        <reserved>
        <unreserved>
        <pct-encoded>
      
      Implementations SHOULD accept other valid UTF-8 strings [RFC3629] as
      input.  An octet MUST be encoded using the percent-encoding mechanism
      described in section 2.1 of [RFC3986] in any of these situations:
      
       The octet is not in the reserved set defined in section 2.2 of
       [RFC3986] or in the unreserved set defined in section 2.3 of
       [RFC3986].
      
       It is the single Reserved character '?' and occurs inside a <dn>,
       <filter>, or other element of an LDAP URL.
      
       It is a comma character ',' that occurs inside an <exvalue>.
      
      RFC 3986, section 2.2 (Reserved Characters)
      
      reserved    = gen-delims / sub-delims
      gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"
      sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
                   / "*" / "+" / "," / ";" / "="
      
      RFC 3986, section 2.3 (Unreserved Characters)
      
      unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
      
      Parameters:
      url - The String to encode
      doubleEncode - Set if we need to encode the comma
      Returns:
      An encoded string
    • toString

      public String toString()
      Get a string representation of a LdapUrl.
      Overrides:
      toString in class Object
      Returns:
      A LdapUrl string
    • getAttributes

      public List<String> getAttributes()
      Returns:
      Returns the attributes.
    • getDn

      public Dn getDn()
      Returns:
      Returns the dn.
    • getExtensions

      public List<LdapUrl.Extension> getExtensions()
      Returns:
      Returns the extensions.
    • getExtension

      public LdapUrl.Extension getExtension(String type)
      Gets the extension.
      Parameters:
      type - the extension type, case-insensitive
      Returns:
      Returns the extension, null if this URL does not contain such an extension.
    • getExtensionValue

      public String getExtensionValue(String type)
      Gets the extension value.
      Parameters:
      type - the extension type, case-insensitive
      Returns:
      Returns the extension value, null if this URL does not contain such an extension or if the extension value is null.
    • getFilter

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

      public String getHost()
      Returns:
      Returns the host.
    • getPort

      public int getPort()
      Returns:
      Returns the port.
    • getScope

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

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

      public int getNbBytes()
      Returns:
      the number of bytes for this LdapUrl
    • getBytesReference

      public byte[] getBytesReference()
      Returns:
      a reference on the interned bytes representing this LdapUrl
    • getBytesCopy

      public byte[] getBytesCopy()
      Returns:
      a copy of the bytes representing this LdapUrl
    • getString

      public String getString()
      Returns:
      the LdapUrl as a String
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • setScheme

      public void setScheme(String scheme)
      Sets the scheme. Must be "ldap://" or "ldaps://", otherwise "ldap://" is assumed as default.
      Parameters:
      scheme - the new scheme
    • setHost

      public void setHost(String host)
      Sets the host.
      Parameters:
      host - the new host
    • setPort

      public void setPort(int port)
      Sets the port. Must be between 1 and 65535, otherwise -1 is assumed as default.
      Parameters:
      port - the new port
    • setDn

      public void setDn(Dn dn)
      Sets the dn.
      Parameters:
      dn - the new dn
    • setAttributes

      public void setAttributes(List<String> attributes)
      Sets the attributes, null removes all existing attributes.
      Parameters:
      attributes - the new attributes
    • setScope

      public void setScope(int scope)
      Sets the scope. Must be one of SearchScope.OBJECT, SearchScope.ONELEVEL or SearchScope.SUBTREE, otherwise SearchScope.OBJECT is assumed as default.
      Parameters:
      scope - the new scope
    • setScope

      public void setScope(SearchScope scope)
      Sets the scope. Must be one of SearchScope.OBJECT, SearchScope.ONELEVEL or SearchScope.SUBTREE, otherwise SearchScope.OBJECT is assumed as default.
      Parameters:
      scope - the new scope
    • setFilter

      public void setFilter(String filter)
      Sets the filter.
      Parameters:
      filter - the new filter
    • setForceScopeRendering

      public void setForceScopeRendering(boolean forceScopeRendering)
      If set to true forces the toString method to render the scope regardless of optional nature. Use this when you want explicit search URL scope rendering.
      Parameters:
      forceScopeRendering - the forceScopeRendering to set