@SuppressWarnings("unchecked") public List<Long> groups( String username, LdapConfig config, LdapOperations ldap, RoleProvider provider, AttributeSet attrSet) { Set<String> groupNames = attrSet.getAll(grpAttribute); if (groupNames == null) { throw new ValidationException(username + " has no attributes " + grpAttribute); } final GroupAttributeMapper mapper = new GroupAttributeMapper(config); // If filtered is activated, then load all group names as mapped // via the name field. // // TODO: this should likely be done via either paged queries // or once for each target. List<String> filteredNames = null; if (filtered) { String filter = config.getGroupFilter().encode(); filteredNames = (List<String>) ldap.search("", filter, mapper); } List<Long> groups = new ArrayList<Long>(); for (String grpName : groupNames) { // If DN is true, then we need to map from the attribute value // to the actual group name before comparing. if (dn) { DistinguishedName relative = config.relativeDN(grpName); String nameAttr = config.getGroupAttribute("name"); grpName = relative.getValue(nameAttr); } // Apply filter if necessary. if (filtered && !filteredNames.contains(grpName)) { log.debug("Group not found by filter: " + grpName); continue; } // Finally, add the grou groups.add(provider.createGroup(grpName, null, false, true)); } return groups; }
/** * Initialize an LdapConfig with command line options. * * @param line Parsed command line arguments container. * @return <code>LdapConfig</code> that has been initialized * @throws Exception On errors thrown by handler. */ protected LdapConfig initLdapConfig(final CommandLine line) throws Exception { final LdapConfig config = new LdapConfig(); this.initLdapProperties(config, line); if (line.hasOption(OPT_TRACE)) { config.setTracePackets(System.out); } if (config.getBindDn() != null && config.getBindCredential() == null) { // prompt the user to enter a password System.out.print("Enter password for service user " + config.getBindDn() + ": "); final String pass = (new BufferedReader(new InputStreamReader(System.in))).readLine(); config.setBindCredential(pass); } return config; }