Code example for SearchControls

0
 
    /** 
     * Controls used to determine whether group searches should be performed over the full sub-tree from the 
     * base DN. Modified by searchSubTree property 
     */ 
    private final SearchControls searchControls = new SearchControls();
 
    /** 
     * The ID of the attribute which contains the role name for a group 
     */ 
    private String groupRoleAttribute = "cn";
 
    /** 
     * The base DN from which the search for group membership should be performed 
     */ 
    private String groupSearchBase;
 
    /** 
     * The pattern to be used for the user search. {0} is the user's DN 
     */ 
    private String groupSearchFilter = "(member={0})";
    /** 
     * The role prefix that will be prepended to each role name 
     */ 
    private String rolePrefix = "ROLE_";
    /** 
     * Should we convert the role name to uppercase 
     */ 
    private boolean convertToUpperCase = true;
 
    //~ Constructors =================================================================================================== 
 
    /** 
     * Constructor for group search scenarios. <tt>userRoleAttributes</tt> may still be 
     * set as a property. 
     * 
     * @param contextSource supplies the contexts used to search for user roles. 
     * @param groupSearchBase          if this is an empty string the search will be performed from the root DN of the 
     *                                 context factory. If null, no search will be performed. 
     */ 
    public DefaultLdapAuthoritiesPopulator(ContextSource contextSource, String groupSearchBase) {
        Assert.notNull(contextSource, "contextSource must not be null");
        ldapTemplate = new SpringSecurityLdapTemplate(contextSource);
        getLdapTemplate().setSearchControls(getSearchControls()); 
        this.groupSearchBase = groupSearchBase;
 
        if (groupSearchBase == null) {
            logger.info("groupSearchBase is null. No group search will be performed.");
        } else if (groupSearchBase.length() == 0) {