Package org.ldaptive
Class LdapURL
- java.lang.Object
-
- org.ldaptive.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 Summary
Fields Modifier and Type Field Description private boolean
active
False if the last connection attempt to this URL failed, which should result in updatingretryMetadata
, otherwise true.private String[]
attributes
Attributes of the ldap url.private String
baseDn
Base DN of the ldap url.protected static String[]
DEFAULT_ATTRIBUTES
Default return attributes, value is all user attributes.protected static String
DEFAULT_BASE_DN
Default base DN, value is "".protected static String
DEFAULT_FILTER
Default search filter value is '(objectClass=*)'.protected static int
DEFAULT_LDAP_PORT
Default LDAP port, value is 389.protected static int
DEFAULT_LDAPS_PORT
Default LDAPS port, value is 636.protected static SearchScope
DEFAULT_SCOPE
Default scope, value isSearchScope.OBJECT
.private String
filter
Search filter of the ldap url.private static int
HASH_CODE_SEED
hash code seed.private String
hostname
Hostname of the ldap url.private InetAddress
inetAddress
IP address resolved for this URL.private int
port
Port of the ldap url.private LdapURLRetryMetadata
retryMetadata
Metadata that describes connection failures on this URL.private String
scheme
Scheme of the ldap url.private SearchScope
scope
Search scope of the ldap url.protected static Pattern
URL_PATTERN
Pattern to match LDAP URL.
-
Constructor Summary
Constructors Modifier Constructor Description private
LdapURL()
Private constructor.LdapURL(String url)
Creates a new ldap url.LdapURL(String hostname, int port)
Creates a new ldap url.protected
LdapURL(String scheme, String hostname, int port, String baseDn, String[] attributes, SearchScope scope, String filter)
Creates a new ldap url.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
activate()
Marks this URL as active.static LdapURL
copy(LdapURL ldapURL)
Returns a new ldap URL initialized with the supplied URL.(package private) void
deactivate()
Marks this URL as inactive.boolean
equals(Object o)
String[]
getAttributes()
Returns the attributes.String
getBaseDn()
Returns the base DN.String
getFilter()
Returns the filter.String
getHostname()
Returns the hostname.String
getHostnameWithPort()
Returns the hostname:port.String
getHostnameWithSchemeAndPort()
Returns the scheme://hostname:port.InetAddress
getInetAddress()
Returns the resolved IP address.int
getPort()
Returns the port.(package private) LdapURLRetryMetadata
getRetryMetadata()
Returns the retry metadata.String
getScheme()
Returns the scheme.SearchScope
getScope()
Returns the scope.String
getUrl()
Returns the formatted URL as scheme://hostname:port/baseDn?attrs?scope?filter.int
hashCode()
(package private) boolean
isActive()
Returns whether this URL is currently active.boolean
isDefaultAttributes()
Returns whether attributes were supplied in this url.boolean
isDefaultBaseDn()
Returns whether a base DN was supplied in this url.boolean
isDefaultFilter()
Returns whether a filter was supplied in this url.boolean
isDefaultPort()
Returns false if a port was supplied in this url.boolean
isDefaultScope()
Returns whether a scope was supplied in this url.protected void
parseURL(String url)
Matches the supplied url against a pattern and reads its components.(package private) void
setInetAddress(InetAddress address)
Sets the resolved IP address.(package private) void
setRetryMetadata(LdapURLRetryMetadata metadata)
Sets the retry metadata.String
toString()
-
-
-
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_BASE_DN
protected static final String DEFAULT_BASE_DN
Default base DN, value is "".- 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_SCOPE
protected static final SearchScope DEFAULT_SCOPE
Default scope, value isSearchScope.OBJECT
.
-
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 updatingretryMetadata
, 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 hostnameport
- 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 schemehostname
- url hostnameport
- url portbaseDn
- base DNattributes
- attributesscope
- search scopefilter
- 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
-
parseURL
protected void parseURL(String url)
Matches the supplied url against a pattern and reads its components.- Parameters:
url
- to parse
-
-