Search in sources :

Example 1 with GroupRepository

use of org.simbasecurity.core.domain.repository.GroupRepository in project simba-os by cegeka.

the class ActiveDirectoryLoginModule method addADGroupsToUser.

protected void addADGroupsToUser(LdapContext ldapContext, User user, String userCN) throws NamingException {
    SearchControls searchControls = new SearchControls();
    searchControls.setReturningAttributes(new String[] { "dn" });
    searchControls.setSearchScope(searchScope);
    GroupRepository groupRepository = GlobalContext.locate(GroupRepository.class);
    String filterGroups = "(&(member=" + userCN + "," + searchBase + ")(objectcategory=group))";
    NamingEnumeration results = ldapContext.search(searchBase, filterGroups, searchControls);
    while (hasMoreResults(results)) {
        String groupCN = ((SearchResult) results.next()).getName();
        Group group = groupRepository.findByCN(groupCN);
        if (group != null) {
            user.addGroup(group);
        }
    }
}
Also used : Group(org.simbasecurity.core.domain.Group) SearchControls(javax.naming.directory.SearchControls) NamingEnumeration(javax.naming.NamingEnumeration) SearchResult(javax.naming.directory.SearchResult) GroupRepository(org.simbasecurity.core.domain.repository.GroupRepository)

Aggregations

NamingEnumeration (javax.naming.NamingEnumeration)1 SearchControls (javax.naming.directory.SearchControls)1 SearchResult (javax.naming.directory.SearchResult)1 Group (org.simbasecurity.core.domain.Group)1 GroupRepository (org.simbasecurity.core.domain.repository.GroupRepository)1