List of usage examples for javax.naming.directory SearchControls SUBTREE_SCOPE
int SUBTREE_SCOPE
To view the source code for javax.naming.directory SearchControls SUBTREE_SCOPE.
Click Source Link
From source file:alpine.auth.LdapConnectionWrapper.java
/** * Retrieves a list of all the groups in the directory. * @param dirContext a DirContext//from w w w .j a v a 2 s . com * @return A list of Strings representing the fully qualified DN of each group * @throws NamingException if an exception if thrown * @since 1.4.0 */ public List<String> getGroups(DirContext dirContext) throws NamingException { final List<String> groupDns = new ArrayList<>(); final SearchControls sc = new SearchControls(); sc.setSearchScope(SearchControls.SUBTREE_SCOPE); final NamingEnumeration<SearchResult> ne = dirContext.search(BASE_DN, GROUPS_FILTER, sc); while (hasMoreEnum(ne)) { final SearchResult result = ne.next(); groupDns.add(result.getNameInNamespace()); } closeQuietly(ne); return groupDns; }
From source file:org.apache.archiva.redback.common.ldap.role.DefaultLdapRoleMapper.java
public boolean hasRole(DirContext context, String roleName) throws MappingException { String groupName = findGroupName(roleName); if (groupName == null) { if (this.useDefaultRoleName) { groupName = roleName;/*from w w w. j ava 2 s. c o m*/ } else { log.warn("skip group creation as no mapping for roleName:'{}'", roleName); return false; } } NamingEnumeration<SearchResult> namingEnumeration = null; try { SearchControls searchControls = new SearchControls(); searchControls.setDerefLinkFlag(true); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); String filter = "objectClass=" + getLdapGroupClass(); namingEnumeration = context.search("cn=" + groupName + "," + getGroupsDn(), filter, searchControls); return namingEnumeration.hasMore(); } catch (NameNotFoundException e) { log.debug("group {} for role {} not found", groupName, roleName); return false; } catch (LdapException e) { throw new MappingException(e.getMessage(), e); } catch (NamingException e) { throw new MappingException(e.getMessage(), e); } finally { close(namingEnumeration); } }
From source file:org.archone.ad.domain.LdapActions.java
@RPCAction(name = "group.list", required = { "domain" }) @SecuredMethod(constraints = "administrator.by_domain") public HashMap<String, Object> listGroups(OperationContext opContext) throws NamingException { String domain = (String) opContext.getParams().get("domain"); DirContextAdapter userDirContext = (DirContextAdapter) SecurityUtils.getSubject().getPrincipal(); DomainDn domainDn = nameHelper.newDomainDnFromDomain(domain); SearchControls controls = new SearchControls(); controls.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration<SearchResult> searchResults = userDirContext.search(nameHelper.getGroupsBaseDn(domainDn), "(cn=*)", controls); List<HashMap<String, Object>> groups = new LinkedList<HashMap<String, Object>>(); while (searchResults.hasMore()) { SearchResult sr = searchResults.next(); if (nameHelper.isGroupDn(sr.getNameInNamespace().toLowerCase())) { HashMap<String, Object> group = new HashMap<String, Object>(); group.put("groupId", nameHelper.newGroupDn(sr.getNameInNamespace().toLowerCase()).getAsGroupId()); groups.add(group);//w ww .j a v a 2 s .c o m } } HashMap<String, Object> response = new HashMap<String, Object>(); response.put("groups", groups); return response; }
From source file:org.jasig.schedassist.impl.oraclecalendar.OracleLdapCalendarAccountDaoImpl.java
/** * /* w w w .jav a2 s. c om*/ * @param searchFilter * @return */ @SuppressWarnings("unchecked") protected List<ICalendarAccount> executeSearchReturnList(final Filter searchFilter) { LOG.debug("searchFilter: " + searchFilter); SearchControls searchControls = new SearchControls(); searchControls.setCountLimit(searchResultsLimit); searchControls.setTimeLimit(searchTimeLimit); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); List<ICalendarAccount> results = Collections.emptyList(); try { results = ldapTemplate.search(baseDn, searchFilter.toString(), searchControls, new OracleCalendarUserAccountAttributesMapper(this.oracleGUIDSource)); if (LOG.isDebugEnabled()) { LOG.debug("search " + searchFilter + " returned " + results.size() + " results"); } Collections.sort(results, new AccountComparator()); } catch (SizeLimitExceededException e) { LOG.debug("search filter exceeded size limit (" + searchResultsLimit + "): " + searchFilter); } catch (TimeLimitExceededException e) { LOG.debug("search filter exceeded time limit(" + searchTimeLimit + " milliseconds): " + searchFilter); } return results; }
From source file:com.orangeleap.common.security.OrangeLeapLdapUserSearch.java
@Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("[ searchFilter: '").append(searchFilter).append("', "); sb.append("searchBase: '").append(searchBase).append("'"); sb.append(", scope: ").append( searchControls.getSearchScope() == SearchControls.SUBTREE_SCOPE ? "subtree" : "single-level, "); sb.append(", searchTimeLimit: ").append(searchControls.getTimeLimit()); sb.append(", derefLinkFlag: ").append(searchControls.getDerefLinkFlag()).append(" ]"); return sb.toString(); }
From source file:com.aurel.track.util.LdapUtil.java
/** * Returns the CN (common name) for a given login name * // w w w . j a v a 2s .c om * @param loginName * the loginName of the user * @return CN as a String(if found), or null (else) */ private static String getCn(TSiteBean siteBean, String loginName) throws NamingException { String keyDn = null; DirContext ctx = getInitialContext(siteBean.getLdapServerURL(), siteBean.getLdapBindDN(), siteBean.getLdapBindPassword()); if (ctx != null) { SearchControls ctls = new SearchControls(); ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); // Search for the user-id String searchStr = "(" + siteBean.getLdapAttributeLoginName() + "=" + loginName + ")"; NamingEnumeration<SearchResult> answer = ctx.search("", searchStr, ctls); if (answer.hasMore()) { // retrieve the CN SearchResult sr = answer.next(); keyDn = sr.getName();// + "," + ctx.getNameInNamespace(); LOGGER.debug("Name = " + keyDn); String nameInNamespace = ctx.getNameInNamespace(); LOGGER.debug("Name in namespace " + nameInNamespace); if (nameInNamespace != null && nameInNamespace.trim().length() > 0) { keyDn += "," + ctx.getNameInNamespace(); } LOGGER.debug("entry found for LDAP-search >" + searchStr + "<: dn= >" + keyDn + "<!"); answer.close(); // wo don't need more answers } else { LOGGER.debug("no entry found for LDAP-search >" + searchStr + "<!"); } ctx.close(); } return keyDn; }
From source file:org.jasig.schedassist.impl.ldap.LDAPCalendarAccountDaoImpl.java
/** * /*from w w w . j a v a2s .co m*/ * @param searchFilter * @return */ @SuppressWarnings("unchecked") protected List<ICalendarAccount> executeSearchReturnList(final Filter searchFilter) { log.debug("executing search filter: " + searchFilter); SearchControls sc = new SearchControls(); sc.setCountLimit(searchResultsLimit); sc.setTimeLimit(searchTimeLimit); sc.setSearchScope(SearchControls.SUBTREE_SCOPE); List<ICalendarAccount> results = Collections.emptyList(); try { results = ldapTemplate.search(baseDn, searchFilter.toString(), sc, new DefaultContextMapperImpl(ldapAttributesKey)); } catch (SizeLimitExceededException e) { log.debug("search filter exceeded results size limit(" + searchResultsLimit + "): " + searchFilter); } catch (TimeLimitExceededException e) { log.warn("search filter exceeded time limit (" + searchTimeLimit + " milliseconds): " + searchFilter); } return results; }
From source file:com.wfp.utils.LDAPUtils.java
/** * Search the LDAP based on default inputs. This method searches for <b>memberOf </b> * @return/*from w w w .j a v a 2 s. com*/ * @throws NamingException */ @SuppressWarnings("unchecked") public static NamingEnumeration getSearchResults() { // Specify the attributes to return String returnedAtts[] = { PROPERTY_MEMBER_OF }; // Specify the search scope SearchControls searchCtls = new SearchControls(); searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); searchCtls.setReturningAttributes(returnedAtts); // Search for objects using the filter try { return getSearchResults(getLDAPContext(), searchCtls, SEARCH_FILTER, LDAP_BASE); } catch (NamingException e) { Logger.error("Error occured while searching results : 181: getSearchResults():[" + e.getLocalizedMessage() + "]", LDAPUtils.class); } return null; }
From source file:com.healthcit.cacure.businessdelegates.LdapUserManager.java
public List<UserCredentials> getAllUsers() { List<UserCredentials> userCredentials = new ArrayList<UserCredentials>(); try {//w ww . j a va 2 s. co m SearchControls searchCtls = new SearchControls(); String returnedAtts[] = { "uid" }; searchCtls.setReturningAttributes(returnedAtts); searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); String searchFilter = "(&(objectClass=person))"; NamingEnumeration<SearchResult> elements = contextSource.getReadOnlyContext().search("", searchFilter, searchCtls); while (elements.hasMoreElements()) { DistinguishedName dn = new DistinguishedName(elements.nextElement().getName()); String userName = dn.getValue("uid"); userCredentials.add(getUserFromDatabase(userName)); } } catch (org.springframework.ldap.NamingException e) { e.printStackTrace(); return null; } catch (NamingException e) { e.printStackTrace(); return null; } return userCredentials; }