static List<List<String>> getPersonGroupsByAccountName(String accountName){ EqualsFilter filter = new EqualsFilter("sAMAccountName", accountName); return ldap.search(DistinguishedName.EMPTY_PATH,filter.encode(),new AttributesMapper(){ public Object mapFromAttributes( javax.naming.directory.Attributes attrs) throws javax.naming.NamingException { List<String> memberof = new ArrayList(); for (Enumeration vals = attrs.get("memberOf").getAll(); vals.hasMoreElements();) { memberof.add((String)vals.nextElement()); } return memberof; } });
@Test public void testEncode() { EqualsFilter eqq = new EqualsFilter("foo", "*bar(fie)"); StringBuffer buff = new StringBuffer(); eqq.encode(buff); assertThat(buff.toString()).isEqualTo("(foo=\\2abar\\28fie\\29)"); }
/** * Return all user entries. * * @param groups * The existing groups. They will be be used to complete the membership of each returned user. * @return all user entries. Key is the user login. */ @Override public Map<String, UserOrg> findAllNoCache(final Map<String, GroupOrg> groups) { // List of attributes to retrieve from LDAP. final String[] returnAttrs = new String[] { SN_ATTRIBUTE, GIVEN_NAME_ATTRIBUTE, PASSWORD_ATTRIBUTE, MAIL_ATTRIBUTE, uidAttribute, departmentAttribute, localIdAttribute, lockedAttribute, PWD_ACCOUNT_LOCKED_ATTRIBUTE }; // Fetch users and their direct attributes final List<UserOrg> users = template.search(peopleBaseDn, new EqualsFilter(OBJECT_CLASS, peopleClass).encode(), SearchControls.SUBTREE_SCOPE, returnAttrs, mapper); // INdex the users by the identifier final Map<String, UserOrg> result = new HashMap<>(); for (final UserOrg user : users) { user.setGroups(new ArrayList<>()); result.put(user.getId(), user); } // Update the memberships of this user for (final Entry<String, GroupOrg> groupEntry : groups.entrySet()) { updateMembership(result, groupEntry); } return result; }
/** * Fetch and return all normalized customers for projects. Note the result use cache, so does not reflect the LDAP. * current state of LDAP. * * @param baseDn * Base DN. * @return all normalized customers for projects. Note the result use cache, so does not reflect the LDAP. current * state of LDAP. Key is the normalized name, Value is the DN. */ @CacheResult(cacheName = "customers") public Set<String> findAll(@CacheKey final String baseDn) { return getUser().getTemplate() .search(baseDn, new EqualsFilter(UserLdapRepository.OBJECT_CLASS, CUSTOMER_OF_PROJECT).encode(), (Object ctx) -> (DirContextAdapter) ctx) .stream().map(g -> DnUtils.toRdn(g.getDn().toString())).collect(Collectors.toSet()); }
@Test public void testEncodeInt() { EqualsFilter eqq = new EqualsFilter("foo", 456); StringBuffer buff = new StringBuffer(); eqq.encode(buff); assertThat(buff.toString()).isEqualTo("(foo=456)"); }
new EqualsFilter("objectClass", GROUP_OF_UNIQUE_NAMES).encode(), (Object ctx) -> (DirContextAdapter) ctx)) { final Set<String> members = new HashSet<>();
@SuppressWarnings("unchecked") @Override public PaginationResult<UserData> fetchGroupUsers(GroupName groupName, int firstResult, int maxResults, UserDataParts... fetchParameters) throws GroupNotFoundException { if (groupName==null) { throw new GroupNotFoundException(groupName, "unable to find null group!"); } EqualsFilter filter = new EqualsFilter( JoomlaLDAPConstants.GROUP_ATTR_NAME, groupName.getName()); // FIXME currently no pagination is being performed, it seems LDAP does not provide this functionality List<UserData> results = ldapTemplate.search(DistinguishedName.EMPTY_PATH, filter.encode(), new UserDataAttributesMapper(passwordEncoding, fetchEffectiveGroupsSpecified(fetchParameters))); return new PaginationResult<UserData>(results!=null?results.size():0, results); }
for(String rne : user.getListeRnes()){ String filtre1 = filtre.replace("#{organisation}", rne); String filtreGlobal = "(&" + filtre1.concat(new EqualsFilter(id, user.getUid()).encode()) + ")"; PersonAttributMapper personAttributMapper = new PersonAttributMapper(); List<Person> liste = ldapTemplateLecture.search("", filtreGlobal, personAttributMapper);