Class LdapManager
getInstance() method
should be used to get an instance. The following properties configure this manager:
- ldap.host
- ldap.port
- ldap.baseDN
- ldap.alternateBaseDN
- ldap.adminDN
- ldap.adminPassword
- ldap.usernameField -- default value is "uid".
- ldap.usernameSuffix -- default value is "".
- ldap.nameField -- default value is "cn".
- ldap.emailField -- default value is "mail".
- ldap.searchFilter -- the filter used to load the list of users. When defined, it will be used with the default filter, which is "([usernameField]={0})" where [usernameField] is the value of ldap.usernameField.
- ldap.groupNameField
- ldap.groupMemberField
- ldap.groupDescriptionField
- ldap.posixMode
- ldap.groupSearchFilter
- ldap.flattenNestedGroups
- ldap.debugEnabled
- ldap.sslEnabled
- ldap.startTlsEnabled
- ldap.autoFollowReferrals
- ldap.autoFollowAliasReferrals
- ldap.initialContextFactory -- if this value is not specified, "com.sun.jndi.ldap.LdapCtxFactory" will be used.
- ldap.connectionPoolEnabled -- true if an LDAP connection pool should be used. False if not set.
- ldap.findUsersFromGroupsEnabled -- If true then Openfire users will be identified from the members of Openfire groups instead of from the list of all users in LDAP. This option is only useful if you wish to restrict the users of Openfire to those in certain groups. Normally this is done by applying an appropriate ldap.searchFilter, but there are a number of reasons why you may wish to enable this option instead:
- If group members cannot be identified by the attributes of the user in LDAP (typically the memberOf attribute) then users cannot be filtered using ldap.searchFilter
- If the number of Openfire users is small compared to the total number of users in LDAP then it may be more performant to identify these users from the groups to which they belong instead of applying an ldap.searchFilter. Note that if this is not the case, enabling this option may significantly decrease performance.
- Author:
- Matt Tucker
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic Instantstatic final SystemProperty<Integer>static final SystemProperty<Duration>Openfire will log a warning when interacting with LDAP using an unencrypted connection. -
Constructor Summary
ConstructorsConstructorDescriptionLdapManager(Map<String, String> properties) Constructs a new LdapManager instance.LdapManager(Map<String, String> properties, String propertyPrefix) -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckAuthentication(Rdn[] userRDN, String password) Returns true if the user is able to successfully authenticate against the LDAP server.static LdapNamecreateNewAbsolute(LdapName base, Rdn[] relative) static LdapNameescapeForJNDI(Rdn... rdn) Returns a JNDI Name for an array of RDNs that is suitable to use to access LDAP through JNDI.findGroupAbsoluteDN(String groupname) LikefindGroupRDN(String)but returns the absolute DN of a groupRdn[]findGroupRDN(String groupname) Finds a groups's RDN using it's group name.Rdn[]findGroupRDN(String groupname, LdapName baseDN) Finds a groups's dn using it's group name.Rdn[]findUserRDN(String username) Finds a user's RDN using their username.Rdn[]findUserRDN(String username, LdapName baseDN) Finds a user's RDN using their username in the specified baseDN.Returns the starting admin DN that searches for admins will performed with.Returns the starting admin DN that searches for admins will performed with.Returns the alternate starting DN that searches for users will performed with.Returns the starting DN that searches for users will performed with.Returns a DirContext for the LDAP server that can be used to perform lookups and searches using the default base DN.getContext(LdapName baseDN) Returns a DirContext for the LDAP server that can be used to perform lookups and searches using the specified base DN.Returns the LDAP field name that the user's email address is stored in.Return the field used to describe a group.Return the field used to list members within a group.Returns the field name used for groups.getGroupsBaseDN(String groupname) Returns the BaseDN for the given groupname.Returns the filter used for searching the directory for groups, which includes the default filter plus any custom-defined search filter.getHosts()Returns the LDAP servers hosts; e.g.static LdapManagerProvides singleton access to an instance of the LdapManager class.static LdapManagergetInstance(String name) Provides singleton access to a named instance of the LdapManager class.Returns the LDAP field name that the user's name is stored in.intgetPort()Returns the LDAP server port number.Rdn[]getRelativeDNFromResult(SearchResult answer) Returns a RDN from the search result answer.Returns the filter used for searching the directory for users, which includes the default filter (username field search) plus any custom-defined search filter.Returns the LDAP field name that the lookup for an authorization identity (username to act as) will be performed on.Returns the suffix appended to the username when LDAP lookups are performed.getUsersBaseDN(String username) Returns the BaseDN for the given username.booleanReturns whether an LDAP connection pool should be used or not.booleanReturns true if LDAP connection debugging is turned on.booleanbooleanReturns true if nested / complex / hierarchic groups should be should be flattened.booleanReturns true if LDAP alias referrals will automatically be followed when found.booleanReturns true if LDAP referrals will automatically be followed when found.booleanCheck if the given DN matches the group search filterbooleanReturn true if the LDAP server is operating in Posix mode.booleanReturns true if LDAP connection is via SSL or not.booleanReturns true if LDAP connection is via START or not.booleanReturns true if the entire tree under the base DN will be searched (recursive search) when doing LDAP queries (finding users, groups, etc).static StringjoinFilter(char operator, List<String> parts) Joins individual strings into one, formatted as an LDAP filter, such as(&(part-a)(part-b)(part-c)).parseAsLdapNameOrLog(String value) Attempts to parse a string value as an LdapName.retrieveAttributeOf(String attributeName, LdapName dn) Reads the attribute values of an entry with the given DN.retrieveList(String attribute, String searchFilter, int startIndex, int numResults, String suffixToTrim) Generic routine for retrieving a list of results from the LDAP server.retrieveList(String attribute, String searchFilter, int startIndex, int numResults, String suffixToTrim, boolean escapeJIDs) Generic routine for retrieving a list of results from the LDAP server.retrieveListCount(String attribute, String searchFilter) Generic routine for retrieving the number of available results from the LDAP server that match the passed search filter.retrieveSingle(String attribute, String searchFilter, boolean failOnMultipleResults) Generic routine for retrieving a single element from the LDAP server.retrieveSingle(String attribute, String searchFilter, boolean failOnMultipleResults, LdapName baseDN) Generic routine for retrieving a single element from the LDAP server.static StringsanitizeSearchFilter(String value) Escapes any special chars (RFC 4515) from a string representing a search filter assertion value.static StringsanitizeSearchFilter(String value, boolean acceptWildcard) Escapes any special chars (RFC 4514/4515) from a string representing a search filter assertion value, with the exception of the '*' wildcard signvoidsetAdminDN(String adminDN) Sets the starting admin DN that searches for admins will performed with.voidsetAdminPassword(String adminPassword) Sets the admin password for the LDAP server we're connecting to.voidsetAlternateBaseDN(LdapName alternateBaseDN) Sets the alternate starting DN that searches for users will performed with.voidSets the starting DN that searches for users will performed with.voidsetConnectionPoolEnabled(boolean connectionPoolEnabled) Sets whether an LDAP connection pool should be used or not.voidsetDebugEnabled(boolean debugEnabled) Sets whether LDAP connection debugging is turned on.voidsetEmailField(String emailField) Sets the LDAP field name that the user's email address is stored in.voidsetFlattenNestedGroups(boolean flattenNestedGroups) Set whether nested / complex / hierarchic groups should be should be flattened.voidsetFollowAliasReferralsEnabled(boolean followAliasReferrals) Sets whether LDAP alias referrals should be automatically followed.voidsetFollowReferralsEnabled(boolean followReferrals) Sets whether LDAP referrals should be automatically followed.voidsetGroupDescriptionField(String groupDescriptionField) Sets the field used to describe a group.voidsetGroupMemberField(String groupMemberField) Sets the field used to list members within a group.voidsetGroupNameField(String groupNameField) Sets the field name used for groups.voidsetGroupSearchFilter(String groupSearchFilter) Sets the search filter appended to the default filter when searching for groups.voidsetHosts(Collection<String> hosts) Sets the list of LDAP servers host; e.g.,localhostormachine.example.com, etc.voidsetNameField(LdapUserTester.PropertyMapping nameField) Sets the LDAP field name that the user's name is stored in.voidsetPort(int port) Sets the LDAP server port number.voidsetPosixMode(boolean posixMode) Sets whether the LDAP server is operating in Posix mode.voidsetSearchFilter(String searchFilter) Sets the search filter appended to the default filter when searching for users.voidsetSslEnabled(boolean sslEnabled) Sets whether the connection to the LDAP server should be made via ssl or not.voidsetStartTlsEnabled(boolean startTlsEnabled) Sets whether the connection to the LDAP server should be made via StartTLS or not.voidsetSubTreeSearch(boolean subTreeSearch) Sets whether the entire tree under the base DN will be searched (recursive search) when doing LDAP queries (finding users, groups, etc).voidsetUsernameField(String usernameField) Sets the LDAP field name that the username lookup will be performed on.voidsetUsernameSuffix(String usernameSuffix) Set the suffix appended to the username whenever LDAP lookups are performed.splitFilter(String input) Splits a string formatted as an LDAP filter, such as(&(part-a)(part-b)(part-c)), in separate parts.
-
Field Details
-
LDAP_PAGE_SIZE
-
UNENCRYPTED_WARNING_SUPPRESSION
Openfire will log a warning when interacting with LDAP using an unencrypted connection. To prevent flooding of the logfiles, subsequent warnings are suppressed for the duration configured by this property. -
lastUnencryptedWarning
-
-
Constructor Details
-
LdapManager
Constructs a new LdapManager instance. Typically,getInstance()should be called instead of this method. LdapManager instances should only be created directly for testing purposes.- Parameters:
properties- the Map that contains properties used by the LDAP manager, such as LDAP host and base DN.
-
LdapManager
-
-
Method Details
-
getInstance
Provides singleton access to an instance of the LdapManager class.- Returns:
- an LdapManager instance.
-
getInstance
Provides singleton access to a named instance of the LdapManager class. This constructor is useful when several, different LDAP configurations are used (eg: A Hybrid Provider that uses more than one LDAP server).- Parameters:
name- The name of the ldap instance.- Returns:
- an LdapManager instance.
-
splitFilter
Splits a string formatted as an LDAP filter, such as(&(part-a)(part-b)(part-c)), in separate parts. When the provided input cannot be parsed as an LDAP filter, the returned collection contains one element: the original input.- Parameters:
input- The value to be split.- Returns:
- The splitted value.
-
joinFilter
Joins individual strings into one, formatted as an LDAP filter, such as(&(part-a)(part-b)(part-c)).- Parameters:
operator- the second character of the resulting string.parts- The parts to be joined into one string.- Returns:
- The joined string value.
-
parseAsLdapNameOrLog
Attempts to parse a string value as an LdapName. This method returns null (and logs an error) if the value was non-null and non-empty and the parsing fails. This method returns null if the provided value was null or empty.- Parameters:
value- The value to be parsed (can be null or empty).- Returns:
- The parsed value, possibly null.
-
getRelativeDNFromResult
Returns a RDN from the search result answer. The return value consists of one or more Rdn instances, that, when combined, are relative to the base DN that was used for the search.- Parameters:
answer- The result of the search (cannot be null).- Returns:
- A relative distinguished name from the answer.
- Throws:
NamingException- When the search result value cannot be used to form a valid RDN value.
-
getContext
Returns a DirContext for the LDAP server that can be used to perform lookups and searches using the default base DN. The alternate DN will be used in case there is aNamingExceptionusing base DN. The context uses the admin login that is defined byadminDNandadminPassword.- Returns:
- a connection to the LDAP server.
- Throws:
NamingException- if there is an error making the LDAP connection.
-
getContext
Returns a DirContext for the LDAP server that can be used to perform lookups and searches using the specified base DN. The context uses the admin login that is defined byadminDNandadminPassword.- Parameters:
baseDN- the base DN to use for the context.- Returns:
- a connection to the LDAP server.
- Throws:
NamingException- if there is an error making the LDAP connection.
-
checkAuthentication
Returns true if the user is able to successfully authenticate against the LDAP server. The "simple" authentication protocol is used.- Parameters:
userRDN- the user's rdn to authenticate (relative tobaseDN).password- the user's password.- Returns:
- true if the user successfully authenticates.
-
isFindUsersFromGroupsEnabled
public boolean isFindUsersFromGroupsEnabled() -
createNewAbsolute
-
findUserRDN
Finds a user's RDN using their username. Normally, this search will be performed using the field "uid", but this can be changed by setting theusernameFieldproperty.Searches are performed over all subtrees relative to the
baseDN. If the search fails in thebaseDNthen another search will be performed in thealternateBaseDN. For example, if thebaseDNis "o=jivesoftware, o=com" and we do a search for "mtucker", then we might find a userDN of "uid=mtucker,ou=People". This kind of searching is a good thing since it doesn't make the assumption that all user records are stored in a flat structure. However, it does add the requirement that "uid" field (or the other field specified) must be unique over the entire subtree from thebaseDN. For example, it's entirely possible to create two dn's in your LDAP directory with the same uid: "uid=mtucker,ou=People" and "uid=mtucker,ou=Administrators". In such a case, it's not possible to uniquely identify a user, so this method will throw an error.The dn that's returned is relative to the default
baseDN.- Parameters:
username- the username to lookup the dn for.- Returns:
- the dn associated with
username. - Throws:
Exception- if the search for the dn fails.
-
findUserRDN
Finds a user's RDN using their username in the specified baseDN. Normally, this search will be performed using the field "uid", but this can be changed by setting theusernameFieldproperty. Searches are performed over all sub-trees relative to thebaseDNunless sub-tree searching has been disabled. For example, if thebaseDNis "o=jivesoftware, o=com" and we do a search for "mtucker", then we might find a userDN of "uid=mtucker,ou=People". This kind of searching is a good thing since it doesn't make the assumption that all user records are stored in a flat structure. However, it does add the requirement that "uid" field (or the other field specified) must be unique over the entire subtree from thebaseDN. For example, it's entirely possible to create two dn's in your LDAP directory with the same uid: "uid=mtucker,ou=People" and "uid=mtucker,ou=Administrators". In such a case, it's not possible to uniquely identify a user, so this method will throw an error.The RDN that's returned is relative to the
baseDN.- Parameters:
username- the username to lookup the dn for.baseDN- the base DN to use for this search.- Returns:
- the RDN associated with
username. - Throws:
Exception- if the search for the RDN fails.- See Also:
-
findGroupRDN
Finds a groups's RDN using it's group name. Normally, this search will be performed using the field "cn", but this can be changed by setting thegroupNameFieldproperty.Searches are performed over all subtrees relative to the
baseDN. If the search fails in thebaseDNthen another search will be performed in thealternateBaseDN. For example, if thebaseDNis "o=jivesoftware, o=com" and we do a search for "managers", then we might find a groupDN of "uid=managers,ou=Groups". This kind of searching is a good thing since it doesn't make the assumption that all user records are stored in a flat structure. However, it does add the requirement that "cn" field (or the other field specified) must be unique over the entire subtree from thebaseDN. For example, it's entirely possible to create two dn's in your LDAP directory with the same cn: "cn=managers,ou=Financial" and "cn=managers,ou=Engineers". In such a case, it's not possible to uniquely identify a group, so this method will throw an error.The RDN that's returned is relative to the default
baseDN.- Parameters:
groupname- the groupname to lookup the RDN for.- Returns:
- the RDN associated with
groupname. - Throws:
Exception- if the search for the RDN fails.
-
findGroupAbsoluteDN
LikefindGroupRDN(String)but returns the absolute DN of a group- Throws:
Exception
-
findGroupRDN
Finds a groups's dn using it's group name. Normally, this search will be performed using the field "cn", but this can be changed by setting thegroupNameFieldproperty.Searches are performed over all subtrees relative to the
baseDN. If the search fails in thebaseDNthen another search will be performed in thealternateBaseDN. For example, if thebaseDNis "o=jivesoftware, o=com" and we do a search for "managers", then we might find a groupDN of "uid=managers,ou=Groups". This kind of searching is a good thing since it doesn't make the assumption that all user records are stored in a flat structure. However, it does add the requirement that "cn" field (or the other field specified) must be unique over the entire subtree from thebaseDN. For example, it's entirely possible to create two dn's in your LDAP directory with the same cn: "cn=managers,ou=Financial" and "cn=managers,ou=Engineers". In such a case, it's not possible to uniquely identify a group, so this method will throw an error.The dn that's returned is relative to the default
baseDN.- Parameters:
groupname- the groupname to lookup the dn for.baseDN- the base DN to use for this search.- Returns:
- the dn associated with
groupname. - Throws:
Exception- if the search for the dn fails.- See Also:
-
isGroupDN
Check if the given DN matches the group search filter- Parameters:
dn- the absolute DN of the node to check- Returns:
- true if the given DN is matching the group filter. false oterwise.
- Throws:
NamingException- if the search for the dn fails.
-
getHosts
Returns the LDAP servers hosts; e.g.localhostormachine.example.com, etc. This value is stored as the Jive Propertyldap.host.- Returns:
- the LDAP server host name.
-
setHosts
Sets the list of LDAP servers host; e.g.,localhostormachine.example.com, etc. This value is store as the Jive Propertyldap.hostusing a comma as a delimiter for each host.Note that all LDAP servers have to share the same configuration.
- Parameters:
hosts- the LDAP servers host names.
-
getPort
public int getPort()Returns the LDAP server port number. The default is 389. This value is stored as the Jive Propertyldap.port.- Returns:
- the LDAP server port number.
-
setPort
public void setPort(int port) Sets the LDAP server port number. The default is 389. This value is stored as the Jive propertyldap.port.- Parameters:
port- the LDAP server port number.
-
isDebugEnabled
public boolean isDebugEnabled()Returns true if LDAP connection debugging is turned on. When on, trace information about BER buffers sent and received by the LDAP provider is written to System.out. Debugging is turned off by default.- Returns:
- true if LDAP debugging is turned on.
-
setDebugEnabled
public void setDebugEnabled(boolean debugEnabled) Sets whether LDAP connection debugging is turned on. When on, trace information about BER buffers sent and received by the LDAP provider is written to System.out. Debugging is turned off by default.- Parameters:
debugEnabled- true if debugging should be turned on.
-
isSslEnabled
public boolean isSslEnabled()Returns true if LDAP connection is via SSL or not. SSL is turned off by default.- Returns:
- true if SSL connections are enabled or not.
-
setSslEnabled
public void setSslEnabled(boolean sslEnabled) Sets whether the connection to the LDAP server should be made via ssl or not.- Parameters:
sslEnabled- true if ssl should be enabled, false otherwise.
-
isStartTlsEnabled
public boolean isStartTlsEnabled()Returns true if LDAP connection is via START or not. TLS is turned off by default.- Returns:
- true if StartTLS connections are enabled or not.
-
setStartTlsEnabled
public void setStartTlsEnabled(boolean startTlsEnabled) Sets whether the connection to the LDAP server should be made via StartTLS or not.- Parameters:
startTlsEnabled- true if StartTLS should be used, false otherwise.
-
getUsernameField
Returns the LDAP field name that the lookup for an authorization identity (username to act as) will be performed on. By default, this is "uid".- Returns:
- the LDAP field that the authorization identity (username to act as) lookup will be performed on.
-
getUsernameSuffix
Returns the suffix appended to the username when LDAP lookups are performed. By default this is "".- Returns:
- the suffix appened to usernames when LDAP lookups are performed.
-
setUsernameField
Sets the LDAP field name that the username lookup will be performed on. By default this is "uid".- Parameters:
usernameField- the LDAP field that the username lookup will be performed on.
-
setUsernameSuffix
Set the suffix appended to the username whenever LDAP lookups are performed.- Parameters:
usernameSuffix- the String to append to usernames for lookups
-
getNameField
Returns the LDAP field name that the user's name is stored in. By default this is "cn". Another common value is "displayName".- Returns:
- the LDAP field that that corresponds to the user's name.
-
setNameField
Sets the LDAP field name that the user's name is stored in. By default this is "cn". Another common value is "displayName".- Parameters:
nameField- the LDAP field that that corresponds to the user's name.
-
getEmailField
Returns the LDAP field name that the user's email address is stored in. By default this is "mail".- Returns:
- the LDAP field that that corresponds to the user's email address.
-
setEmailField
Sets the LDAP field name that the user's email address is stored in. By default this is "mail".- Parameters:
emailField- the LDAP field that that corresponds to the user's email address.
-
getBaseDN
Returns the starting DN that searches for users will performed with. Searches will performed on the entire sub-tree under the base DN.- Returns:
- the starting DN used for performing searches.
-
setBaseDN
Sets the starting DN that searches for users will performed with. Searches will performed on the entire sub-tree under the base DN.- Parameters:
baseDN- the starting DN used for performing searches.
-
getAlternateBaseDN
Returns the alternate starting DN that searches for users will performed with. Searches will performed on the entire sub-tree under the alternate base DN after they are performed on the main base DN.- Returns:
- the alternate starting DN used for performing searches. If no alternate
DN is set, this method will return
null.
-
setAlternateBaseDN
Sets the alternate starting DN that searches for users will performed with. Searches will performed on the entire sub-tree under the alternate base DN after they are performed on the main base dn.- Parameters:
alternateBaseDN- the alternate starting DN used for performing searches.
-
getUsersBaseDN
Returns the BaseDN for the given username.- Parameters:
username- username to return its base DN.- Returns:
- the BaseDN for the given username. If no baseDN is found,
this method will return
null.
-
getGroupsBaseDN
Returns the BaseDN for the given groupname.- Parameters:
groupname- groupname to return its base DN.- Returns:
- the BaseDN for the given groupname. If no baseDN is found,
this method will return
null.
-
getAdminDN
Returns the starting admin DN that searches for admins will performed with. Searches will performed on the entire sub-tree under the admin DN.- Returns:
- the starting DN used for performing searches.
-
setAdminDN
Sets the starting admin DN that searches for admins will performed with. Searches will performed on the entire sub-tree under the admins DN.- Parameters:
adminDN- the starting DN used for performing admin searches.
-
getAdminPassword
Returns the starting admin DN that searches for admins will performed with. Searches will performed on the entire sub-tree under the admin DN.- Returns:
- the starting DN used for performing searches.
-
setAdminPassword
Sets the admin password for the LDAP server we're connecting to.- Parameters:
adminPassword- the admin password for the LDAP server we're connecting to.
-
setConnectionPoolEnabled
public void setConnectionPoolEnabled(boolean connectionPoolEnabled) Sets whether an LDAP connection pool should be used or not.- Parameters:
connectionPoolEnabled- true if an LDAP connection pool should be used.
-
isConnectionPoolEnabled
public boolean isConnectionPoolEnabled()Returns whether an LDAP connection pool should be used or not.- Returns:
- true if an LDAP connection pool should be used.
-
getSearchFilter
Returns the filter used for searching the directory for users, which includes the default filter (username field search) plus any custom-defined search filter.- Returns:
- the search filter.
-
setSearchFilter
Sets the search filter appended to the default filter when searching for users.- Parameters:
searchFilter- the search filter appended to the default filter when searching for users.
-
isSubTreeSearch
public boolean isSubTreeSearch()Returns true if the entire tree under the base DN will be searched (recursive search) when doing LDAP queries (finding users, groups, etc). When false, only a single level under the base DN will be searched. The default istruewhich is the best option for most LDAP setups. In only a few cases will the directory be setup in such a way that it's better to do single level searching.- Returns:
- true if the entire tree under the base DN will be searched.
-
setSubTreeSearch
public void setSubTreeSearch(boolean subTreeSearch) Sets whether the entire tree under the base DN will be searched (recursive search) when doing LDAP queries (finding users, groups, etc). When false, only a single level under the base DN will be searched. The default istruewhich is the best option for most LDAP setups. In only a few cases will the directory be setup in such a way that it's better to do single level searching.- Parameters:
subTreeSearch- true if the entire tree under the base DN will be searched.
-
isFollowReferralsEnabled
public boolean isFollowReferralsEnabled()Returns true if LDAP referrals will automatically be followed when found.- Returns:
- true if LDAP referrals are automatically followed.
-
setFollowReferralsEnabled
public void setFollowReferralsEnabled(boolean followReferrals) Sets whether LDAP referrals should be automatically followed.- Parameters:
followReferrals- true if LDAP referrals should be automatically followed.
-
isFollowAliasReferralsEnabled
public boolean isFollowAliasReferralsEnabled()Returns true if LDAP alias referrals will automatically be followed when found.- Returns:
- true if LDAP alias referrals are automatically followed.
-
setFollowAliasReferralsEnabled
public void setFollowAliasReferralsEnabled(boolean followAliasReferrals) Sets whether LDAP alias referrals should be automatically followed.- Parameters:
followAliasReferrals- true if LDAP alias referrals should be automatically followed.
-
getGroupNameField
Returns the field name used for groups. Value of groupNameField defaults to "cn".- Returns:
- the field used for groups.
-
setGroupNameField
Sets the field name used for groups.- Parameters:
groupNameField- the field used for groups.
-
getGroupMemberField
Return the field used to list members within a group. Value of groupMemberField defaults to "member".- Returns:
- the field used to list members within a group.
-
setGroupMemberField
Sets the field used to list members within a group. Value of groupMemberField defaults to "member".- Parameters:
groupMemberField- the field used to list members within a group.
-
getGroupDescriptionField
Return the field used to describe a group. Value of groupDescriptionField defaults to "description".- Returns:
- the field used to describe a group.
-
setGroupDescriptionField
Sets the field used to describe a group. Value of groupDescriptionField defaults to "description".- Parameters:
groupDescriptionField- the field used to describe a group.
-
isPosixMode
public boolean isPosixMode()Return true if the LDAP server is operating in Posix mode. By default false is returned. When in Posix mode, users are stored within a group by their username alone. When not enabled, users are stored in a group using their entire DN.- Returns:
- true if posix mode is being used by the LDAP server.
-
setPosixMode
public void setPosixMode(boolean posixMode) Sets whether the LDAP server is operating in Posix mode. When in Posix mode, users are stored within a group by their username alone. When not enabled, users are stored in a group using their entire DN.- Parameters:
posixMode- true if posix mode is being used by the LDAP server.
-
getGroupSearchFilter
Returns the filter used for searching the directory for groups, which includes the default filter plus any custom-defined search filter.- Returns:
- the search filter when searching for groups.
-
isFlattenNestedGroups
public boolean isFlattenNestedGroups()Returns true if nested / complex / hierarchic groups should be should be flattened.This means: if group A is member of group B, the members of group A will also be members of group B
-
setFlattenNestedGroups
public void setFlattenNestedGroups(boolean flattenNestedGroups) Set whether nested / complex / hierarchic groups should be should be flattened.- See Also:
-
setGroupSearchFilter
Sets the search filter appended to the default filter when searching for groups.- Parameters:
groupSearchFilter- the search filter appended to the default filter when searching for groups.
-
retrieveList
public List<String> retrieveList(String attribute, String searchFilter, int startIndex, int numResults, String suffixToTrim) Generic routine for retrieving a list of results from the LDAP server. It's meant to be very flexible so that just about any query for a list of results can make use of it without having to reimplement their own calls to LDAP. This routine also accounts for sorting settings, paging settings, any other global settings, and alternate DNs. The passed in filter string needs to be pre-prepared! In other words, nothing will be changed in the string before it is used as a string.- Parameters:
attribute- LDAP attribute to be pulled from each result and placed in the return results. Typically pulled from this manager.searchFilter- Filter to use to perform the search. Typically pulled from this manager.startIndex- Number/index of first result to include in results. (-1 for no limit)numResults- Number of results to include. (-1 for no limit)suffixToTrim- An arbitrary string to trim from the end of every attribute returned. null to disable.- Returns:
- A simple list of strings (that should be sorted) of the results.
-
retrieveList
public List<String> retrieveList(String attribute, String searchFilter, int startIndex, int numResults, String suffixToTrim, boolean escapeJIDs) Generic routine for retrieving a list of results from the LDAP server. It's meant to be very flexible so that just about any query for a list of results can make use of it without having to reimplement their own calls to LDAP. This routine also accounts for sorting settings, paging settings, any other global settings, and alternate DNs. The passed in filter string needs to be pre-prepared! In other words, nothing will be changed in the string before it is used as a string.- Parameters:
attribute- LDAP attribute to be pulled from each result and placed in the return results. Typically pulled from this manager.searchFilter- Filter to use to perform the search. Typically pulled from this manager.startIndex- Number/index of first result to include in results. (-1 for no limit)numResults- Number of results to include. (-1 for no limit)suffixToTrim- An arbitrary string to trim from the end of every attribute returned. null to disable.escapeJIDs- Use JID-escaping for returned results (e.g. usernames)- Returns:
- A simple list of strings (that should be sorted) of the results.
-
retrieveSingle
Generic routine for retrieving a single element from the LDAP server. It's meant to be very flexible so that just about any query for a single results can make use of it without having to reimplement their own calls to LDAP.The passed in filter string needs to be pre-prepared! In other words, nothing will be changed in the string before it is used as a string.
- Parameters:
attribute- LDAP attribute to be pulled from each result and placed in the return results. Typically pulled from this manager. Null means the absolute DN is returned.searchFilter- Filter to use to perform the search. Typically pulled from this manager.failOnMultipleResults- It true, anIllegalStateExceptionwill be thrown, if the search result is not unique. If false, just the first result will be returned.- Returns:
- A single string.
-
retrieveSingle
public String retrieveSingle(String attribute, String searchFilter, boolean failOnMultipleResults, LdapName baseDN) Generic routine for retrieving a single element from the LDAP server. It's meant to be very flexible so that just about any query for a single results can make use of it without having to reimplement their own calls to LDAP.The passed in filter string needs to be pre-prepared! In other words, nothing will be changed in the string before it is used as a string.
- Parameters:
attribute- LDAP attribute to be pulled from each result and placed in the return results. Typically pulled from this manager. Null means the absolute DN is returned.searchFilter- Filter to use to perform the search. Typically pulled from this manager.failOnMultipleResults- It true, anIllegalStateExceptionwill be thrown, if the search result is not unique. If false, just the first result will be returned.baseDN- DN where to start the search. TypicallygetBaseDN()orgetAlternateBaseDN().- Returns:
- A single string.
-
retrieveAttributeOf
Reads the attribute values of an entry with the given DN.- Parameters:
attributeName- LDAP attribute to be read.dn- DN of the entry.- Returns:
- A list with the values of the attribute.
- Throws:
NamingException
-
retrieveListCount
Generic routine for retrieving the number of available results from the LDAP server that match the passed search filter. This routine also accounts for paging settings and alternate DNs. The passed in filter string needs to be pre-prepared! In other words, nothing will be changed in the string before it is used as a string.- Parameters:
attribute- LDAP attribute to be pulled from each result and used in the query. Typically pulled from this manager.searchFilter- Filter to use to perform the search. Typically pulled from this manager.- Returns:
- The number of entries that match the filter.
-
sanitizeSearchFilter
Escapes any special chars (RFC 4515) from a string representing a search filter assertion value.- Parameters:
value- The input string.- Returns:
- A assertion value string ready for insertion into a search filter string.
-
escapeForJNDI
Returns a JNDI Name for an array of RDNs that is suitable to use to access LDAP through JNDI. This method applies JDNI-suitable escaping to each RDNWhen using the JNDI to access an LDAP service, you should be aware that the forward slash character ("/") in a string name has special meaning to the JNDI. If the LDAP entry's name contains this character, then you need to escape it (using the backslash character ("\")). For example, an LDAP entry with the name "cn=O/R" must be presented as the string "cn=O\\/R" to the JNDI context methods.
- Parameters:
rdn- The names to escape (cannot be null).- Returns:
- A JNDI name representation of the values (never null).
- See Also:
-
sanitizeSearchFilter
Escapes any special chars (RFC 4514/4515) from a string representing a search filter assertion value, with the exception of the '*' wildcard sign- Parameters:
value- The input string.acceptWildcard-trueto accept wildcards, otherwisefalse- Returns:
- A assertion value string ready for insertion into a search filter string.
-