Make template and search controls member variables.
This commit is contained in:
parent
d3e42c6f3f
commit
ce1c59e924
|
@ -123,11 +123,11 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
|
||||||
/** The ID of the attribute which contains the role name for a group */
|
/** The ID of the attribute which contains the role name for a group */
|
||||||
private String groupRoleAttribute = "cn";
|
private String groupRoleAttribute = "cn";
|
||||||
|
|
||||||
/** Whether group searches should be performed over the full sub-tree from the base DN */
|
/** Controls used to determine whether group searches should be performed over the
|
||||||
// private boolean searchSubtree = false;
|
* full sub-tree from the base DN. Modified by searchSubTree property
|
||||||
|
*/
|
||||||
|
|
||||||
/** Internal variable, tied to searchSubTree property */
|
private SearchControls searchControls = new SearchControls();
|
||||||
private int searchScope = SearchControls.ONELEVEL_SCOPE;
|
|
||||||
|
|
||||||
private boolean convertToUpperCase = true;
|
private boolean convertToUpperCase = true;
|
||||||
|
|
||||||
|
@ -137,6 +137,9 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
|
||||||
/** An initial context factory is only required if searching for groups is required. */
|
/** An initial context factory is only required if searching for groups is required. */
|
||||||
private InitialDirContextFactory initialDirContextFactory = null;
|
private InitialDirContextFactory initialDirContextFactory = null;
|
||||||
|
|
||||||
|
private LdapTemplate ldapTemplate;
|
||||||
|
|
||||||
|
|
||||||
//~ Constructors ===========================================================
|
//~ Constructors ===========================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -157,6 +160,9 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
|
||||||
logger.info("groupSearchBase is empty. Searches will be performed from the root: " +
|
logger.info("groupSearchBase is empty. Searches will be performed from the root: " +
|
||||||
initialDirContextFactory.getRootDn());
|
initialDirContextFactory.getRootDn());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ldapTemplate = new LdapTemplate(initialDirContextFactory);
|
||||||
|
ldapTemplate.setSearchControls(searchControls);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
@ -216,11 +222,9 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
|
||||||
+ " in search base '" + groupSearchBase + "'");
|
+ " in search base '" + groupSearchBase + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
LdapTemplate template = new LdapTemplate(initialDirContextFactory);
|
|
||||||
|
|
||||||
template.setSearchScope(searchScope);
|
Set userRoles = ldapTemplate.searchForSingleAttributeValues(groupSearchBase, groupSearchFilter,
|
||||||
|
new String[]{userDn, username}, groupRoleAttribute);
|
||||||
Set userRoles = template.searchForSingleAttributeValues(groupSearchBase, groupSearchFilter, new String[]{userDn, username}, groupRoleAttribute);
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Roles from search: " + userRoles);
|
logger.debug("Roles from search: " + userRoles);
|
||||||
|
@ -281,9 +285,9 @@ public class DefaultLdapAuthoritiesPopulator implements LdapAuthoritiesPopulator
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSearchSubtree(boolean searchSubtree) {
|
public void setSearchSubtree(boolean searchSubtree) {
|
||||||
// this.searchSubtree = searchSubtree;
|
int searchScope = searchSubtree ?
|
||||||
this.searchScope = searchSubtree ?
|
|
||||||
SearchControls.SUBTREE_SCOPE : SearchControls.ONELEVEL_SCOPE;
|
SearchControls.SUBTREE_SCOPE : SearchControls.ONELEVEL_SCOPE;
|
||||||
|
searchControls.setSearchScope(searchScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConvertToUpperCase(boolean convertToUpperCase) {
|
public void setConvertToUpperCase(boolean convertToUpperCase) {
|
||||||
|
|
Loading…
Reference in New Issue