Class LdapUrl
java.lang.Object
org.apache.directory.api.ldap.model.url.LdapUrl
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn inner bean to hold extension information. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbyte[]byte[]getDn()getExtension(String type) Gets the extension.getExtensionValue(String type) Gets the extension value.getHost()intintgetPort()getScope()inthashCode()booleanisValidInet4Address(String inet4Address) Validates an IPv4 address.booleanisValidInet6Address(String inet6Address) This code source was taken from commons.validator 1.5.0 Validates an IPv6 address.voidsetAttributes(List<String> attributes) Sets the attributes, null removes all existing attributes.voidSets the dn.voidSets the filter.voidsetForceScopeRendering(boolean forceScopeRendering) If set to true forces the toString method to render the scope regardless of optional nature.voidSets the host.voidsetPort(int port) Sets the port.voidSets the scheme.voidsetScope(int scope) Sets the scope.voidsetScope(SearchScope scope) Sets the scope.toString()Get a string representation of a LdapUrl.static StringEncode a String to avoid special characters.
-
Field Details
-
LDAPS_SCHEME
-
LDAP_SCHEME
-
EMPTY_URL
A null LdapUrl
-
-
Constructor Details
-
LdapUrl
public LdapUrl()Construct an empty LdapUrl -
LdapUrl
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
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
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
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 encodedoubleEncode- Set if we need to encode the comma- Returns:
- An encoded string
-
toString
-
getAttributes
-
getDn
- Returns:
- Returns the dn.
-
getExtensions
- Returns:
- Returns the extensions.
-
getExtension
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
-
getFilter
- Returns:
- Returns the filter.
-
getHost
- Returns:
- Returns the host.
-
getPort
public int getPort()- Returns:
- Returns the port.
-
getScope
- Returns:
- Returns the scope.
-
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
- Returns:
- the LdapUrl as a String
-
hashCode
-
equals
-
setScheme
Sets the scheme. Must be "ldap://" or "ldaps://", otherwise "ldap://" is assumed as default.- Parameters:
scheme- the new scheme
-
setHost
-
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
-
setAttributes
-
setScope
public void setScope(int scope) Sets the scope. Must be one ofSearchScope.OBJECT,SearchScope.ONELEVELorSearchScope.SUBTREE, otherwiseSearchScope.OBJECTis assumed as default.- Parameters:
scope- the new scope
-
setScope
Sets the scope. Must be one ofSearchScope.OBJECT,SearchScope.ONELEVELorSearchScope.SUBTREE, otherwiseSearchScope.OBJECTis assumed as default.- Parameters:
scope- the new scope
-
setFilter
-
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
-