Package netscape.ldap
Class LDAPUrl
- java.lang.Object
-
- netscape.ldap.LDAPUrl
-
- All Implemented Interfaces:
java.io.Serializable
public class LDAPUrl extends java.lang.Object implements java.io.SerializableRepresents an LDAP URL. The complete specification for LDAP URLs is in RFC 1959. In addition, the secure ldap (ldaps://) is also supported. LDAP URLs have the following format:"ldap[s]://" [ hostName [":" portNumber] ] "/" distinguishedName ["?" attributeList ["?" scope "?" filterString ] ]where- all text within double-quotes are literal
hostNameandportNumberidentify the location of the LDAP server.distinguishedNameis the name of an entry within the given directory (the entry represents the starting point of the search)attributeListcontains a list of attributes to retrieve (if null, fetch all attributes). This is a comma-delimited list of attribute names.scopeis one of the following:baseindicates that this is a search only for the specified entryoneindicates that this is a search for matching entries one level under the specified entry (and not including the entry itself)subindicates that this is a search for matching entries at all levels under the specified entry (including the entry itself)
If not specified,
scopeisbaseby default.filterStringis a human-readable representation of the search criteria. This value is used only for one-level or subtree searches.
Note that if
scopeandfilterStringare not specified, an LDAP URL identifies exactly one entry in the directory.The same encoding rules for other URLs (e.g. HTTP) apply for LDAP URLs. Specifically, any "illegal" characters are escaped with
%HH, whereHHrepresent the two hex digits which correspond to the ASCII value of the character. This encoding is only legal (or necessary) on the DN and filter portions of the URL.- Version:
- 1.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_SECURE_PORTThe default port number for secure LDAP connections.static java.lang.StringdefaultFilter
-
Constructor Summary
Constructors Constructor Description LDAPUrl(java.lang.String url)Constructs a URL object with the specified string as URL.LDAPUrl(java.lang.String host, int port, java.lang.String DN)Constructs with the specified host, port, and DN.LDAPUrl(java.lang.String host, int port, java.lang.String DN, java.lang.String[] attributes, int scope, java.lang.String filter)Constructs a full-blown LDAP URL to specify an LDAP search operation.LDAPUrl(java.lang.String host, int port, java.lang.String DN, java.lang.String[] attributes, int scope, java.lang.String filter, boolean secure)Constructs a full-blown LDAP URL to specify an LDAP search operation.LDAPUrl(java.lang.String host, int port, java.lang.String DN, java.util.Enumeration<java.lang.String> attributes, int scope, java.lang.String filter)Constructs a full-blown LDAP URL to specify an LDAP search operation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringdecode(java.lang.String URLEncoded)Decodes a URL-encoded string.static java.lang.Stringencode(java.lang.String toEncode)Encodes an arbitrary string.booleanequals(LDAPUrl url)Reports if the two objects represent the same URLjava.lang.String[]getAttributeArray()Return the collection of attributes specified in the URL, or null for "every attribute"java.util.Enumeration<java.lang.String>getAttributes()Return the collection of attributes specified in the URL, or null for "every attribute"java.lang.StringgetDN()Return the distinguished name encapsulated in the URLjava.lang.StringgetFilter()Returns the search filter (RFC 1558), or the default if none was specified.java.lang.StringgetHost()Return the host name of the LDAP serverintgetPort()Return the port number for the LDAP serverintgetScope()Returns the scope of the search, according to the values SCOPE_BASE, SCOPE_ONE, SCOPE_SUB as defined in LDAPv2.static LDAPSocketFactorygetSocketFactory()Gets the socket factory to be used for ldaps:// URLs.java.lang.StringgetUrl()Returns a valid string representation of this LDAP URL.booleanisSecure()Returns true if the secure ldap protocol is used.static voidsetSocketFactory(LDAPSocketFactory factory)Sets the socket factory to be used for ldaps:// URLs.java.lang.StringtoString()Returns the URL in String format
-
-
-
Constructor Detail
-
LDAPUrl
public LDAPUrl(java.lang.String url) throws java.net.MalformedURLExceptionConstructs a URL object with the specified string as URL.- Parameters:
url- LDAP search expression in URL form- Throws:
java.net.MalformedURLException- failed to parse URL
-
LDAPUrl
public LDAPUrl(java.lang.String host, int port, java.lang.String DN)Constructs with the specified host, port, and DN. This form is used to create URL references to a particular object in the directory.- Parameters:
host- host name of the LDAP server, or null for "nearest X.500/LDAP"port- port number of the LDAP server (use LDAPv2.DEFAULT_PORT for the default port)DN- distinguished name of the object
-
LDAPUrl
public LDAPUrl(java.lang.String host, int port, java.lang.String DN, java.lang.String[] attributes, int scope, java.lang.String filter)Constructs a full-blown LDAP URL to specify an LDAP search operation.- Parameters:
host- host name of the LDAP server, or null for "nearest X.500/LDAP"port- port number of the LDAP server (use LDAPv2.DEFAULT_PORT for the default port)DN- distinguished name of the objectattributes- list of attributes to return. Use null for "all attributes."scope- depth of search (in DN namespace). Use one of the LDAPv2 scopes: SCOPE_BASE, SCOPE_ONE, or SCOPE_SUB.filter- LDAP filter string (as defined in RFC 1558). Use null for no filter (this effectively makes the URL reference a single object).
-
LDAPUrl
public LDAPUrl(java.lang.String host, int port, java.lang.String DN, java.util.Enumeration<java.lang.String> attributes, int scope, java.lang.String filter)Constructs a full-blown LDAP URL to specify an LDAP search operation.- Parameters:
host- host name of the LDAP server, or null for "nearest X.500/LDAP"port- port number of the LDAP server (use LDAPv2.DEFAULT_PORT for the default port)DN- distinguished name of the objectattributes- list of the attributes to return. Use null for "all attributes."scope- depth of the search (in DN namespace). Use one of the LDAPv2 scopes: SCOPE_BASE, SCOPE_ONE, or SCOPE_SUB.filter- LDAP filter string (as defined in RFC 1558). Use null for no filter (this effectively makes the URL reference a single object).
-
LDAPUrl
public LDAPUrl(java.lang.String host, int port, java.lang.String DN, java.lang.String[] attributes, int scope, java.lang.String filter, boolean secure)Constructs a full-blown LDAP URL to specify an LDAP search operation.- Parameters:
host- host name of the LDAP server, or null for "nearest X.500/LDAP"port- port number of the LDAP server (use LDAPv2.DEFAULT_PORT for the default non-secure port or LDAPUrl.DEFAULT_SECURE_PORT for the default secure port)DN- distinguished name of the objectattributes- list of the attributes to return. Use null for "all attributes."scope- depth of the search (in DN namespace). Use one of the LDAPv2 scopes: SCOPE_BASE, SCOPE_ONE, or SCOPE_SUB.filter- LDAP filter string (as defined in RFC 1558). Use null for no filter (this effectively makes the URL reference a single object).secure- flag if secure ldap protocol (ldaps) is to be used.
-
-
Method Detail
-
getHost
public java.lang.String getHost()
Return the host name of the LDAP server- Returns:
- LDAP host.
-
getPort
public int getPort()
Return the port number for the LDAP server- Returns:
- port number.
-
getDN
public java.lang.String getDN()
Return the distinguished name encapsulated in the URL- Returns:
- target distinguished name.
-
getAttributes
public java.util.Enumeration<java.lang.String> getAttributes()
Return the collection of attributes specified in the URL, or null for "every attribute"- Returns:
- enumeration of attributes.
-
getAttributeArray
public java.lang.String[] getAttributeArray()
Return the collection of attributes specified in the URL, or null for "every attribute"- Returns:
- string array of attributes.
-
getScope
public int getScope()
Returns the scope of the search, according to the values SCOPE_BASE, SCOPE_ONE, SCOPE_SUB as defined in LDAPv2. This refers to how deep within the directory namespace the search will look- Returns:
- search scope.
-
getFilter
public java.lang.String getFilter()
Returns the search filter (RFC 1558), or the default if none was specified.- Returns:
- the search filter.
-
getUrl
public java.lang.String getUrl()
Returns a valid string representation of this LDAP URL.- Returns:
- the LDAP search expression in URL form.
-
isSecure
public boolean isSecure()
Returns true if the secure ldap protocol is used.- Returns:
- true if ldaps is used.
-
getSocketFactory
public static LDAPSocketFactory getSocketFactory()
Gets the socket factory to be used for ldaps:// URLs.If the factory is not explicitly specified with
LDAPUrl.setSocketFactory, the method will attempt the determine the default factory based on the available factories in the netscape.ldap.factory package.- Returns:
- the socket factory to be used for ldaps:// URLs
-
setSocketFactory
public static void setSocketFactory(LDAPSocketFactory factory)
Sets the socket factory to be used for ldaps:// URLs. Overrides the default factory assigned by the LDAPUrl class.- Parameters:
factory- the socket factory to be used for ldaps:// URLs- See Also:
getSocketFactory()
-
decode
public static java.lang.String decode(java.lang.String URLEncoded) throws java.net.MalformedURLExceptionDecodes a URL-encoded string. Any occurences of %HH are decoded to the hex value represented. However, this routine does NOT decode "+" into " ". See RFC 1738 for full details about URL encoding/decoding.- Parameters:
URLEncoded- a segment of a URL which was encoded using the URL encoding rules- Throws:
java.net.MalformedURLException- failed to parse URL
-
encode
public static java.lang.String encode(java.lang.String toEncode)
Encodes an arbitrary string. Any illegal characters are encoded as %HH. However, this routine does NOT decode "+" into " " (this is a HTTP thing, not a general URL thing). Note that, because Sun's URLEncoder does do this encoding, we can't use it. See RFC 1738 for full details about URL encoding/decoding.- Parameters:
toEncode- an arbitrary string to encode for embedding within a URL
-
toString
public java.lang.String toString()
Returns the URL in String format- Overrides:
toStringin classjava.lang.Object- Returns:
- the URL in String format
-
equals
public boolean equals(LDAPUrl url)
Reports if the two objects represent the same URL- Parameters:
url- the object to be compared to- Returns:
trueif the two are equivalent
-
-