本文整理汇总了Java中org.springframework.ldap.filter.EqualsFilter类的典型用法代码示例。如果您正苦于以下问题:Java EqualsFilter类的具体用法?Java EqualsFilter怎么用?Java EqualsFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EqualsFilter类属于org.springframework.ldap.filter包,在下文中一共展示了EqualsFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findAllNoCache
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
/**
* 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.
*/
public Map<String, UserOrg> findAllNoCache(final Map<String, GroupOrg> groups) {
// Fetch users and their direct attributes
final List<UserOrg> users = template.search(peopleBaseDn, new EqualsFilter(OBJECT_CLASS, peopleClass).encode(), 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;
}
示例2: zzdeleteUser
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
@Test
public void zzdeleteUser() {
initSpringSecurityContext("assist");
Assert.assertEquals(1, resource.findAll("ing", null, "jdoe5", newUriInfo()).getData().size());
Assert.assertNotNull(getUser().findByIdNoCache("jdoE5"));
Assert.assertTrue(getGroup().findAll().get("dig rha").getMembers().contains("jdoe5"));
resource.delete("jDOE5");
Assert.assertEquals(0, resource.findAll("ing", null, "jdoe5", newUriInfo()).getData().size());
Assert.assertNull(getUser().findByIdNoCache("jdoe5"));
Assert.assertFalse(getGroup().findAll().get("dig rha").getMembers().contains("jdoe5"));
final AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "groupOfUniqueNames"));
filter.and(new EqualsFilter("cn", "dig rha"));
final List<DirContextAdapter> groups = getTemplate().search("ou=groups,dc=sample,dc=com", filter.encode(),
(Object ctx) -> (DirContextAdapter) ctx);
Assert.assertEquals(1, groups.size());
final DirContextAdapter group = groups.get(0);
final String[] stringAttributes = group.getStringAttributes("uniqueMember");
Assert.assertFalse(stringAttributes.length == 0);
for (final String memberDN : stringAttributes) {
Assert.assertFalse(memberDN.startsWith("uid=jdoe5"));
}
// Restore the state, create back the user
initSpringSecurityContext(DEFAULT_USER);
final UserOrgEditionVo user = new UserOrgEditionVo();
user.setId("jdoe5");
user.setFirstName("First5");
user.setLastName("Last5");
user.setCompany("ing-internal");
final List<String> groups2 = new ArrayList<>();
groups2.add("DIG RHA");
user.setGroups(groups2);
resource.create(user);
}
示例3: search
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
@Override
public Collection<User> search(String query) {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "person"));
filter.and(new WhitespaceWildcardsFilter("cn", query));
LdapQuery ldapQuery = LdapQueryBuilder
.query()
.base(baseDn)
.countLimit(20)
.timeLimit(5000)
.searchScope(SearchScope.SUBTREE)
.attributes(identifierAttribute, "givenname", "sn", "mail")
.filter(filter);
return ldapTemplate.search(ldapQuery, new UserAttributesMapper());
}
示例4: authenticate
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
@Override
public ComposableFuture<Boolean> authenticate(final Credentials<UserPasswordToken> credentials) {
final String username = credentials.get().getUsername();
final LdapQuery query = LdapQueryBuilder.query().filter(new EqualsFilter(UID_ATTRIBUTE, username));
return ComposableFutures.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
try {
ldapTemplate.authenticate(query, new String(credentials.get().getPassword()));
return true;
} catch (final Exception e) {
return false;
}
}
});
}
示例5: getUserGroups
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
/**
*
* @param realm
* The realm under which the user exists
* @param userId
* The id of the user
* @return List of roles assigned to this user
*/
public List<String> getUserGroups(String realm, String userId) {
DistinguishedName dn = new DistinguishedName("ou=" + realm);
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", groupObjectClass)).and(
new EqualsFilter(groupSearchAttribute, userId));
@SuppressWarnings("unchecked")
List<String> groups = ldapTemplate.search(dn, filter.toString(), new GroupContextMapper());
// map the roles in LDAP which are better suited for Posix systems to
// the roles used by the API
List<String> result = new LinkedList<String>();
for (String group : groups) {
result.add(LDAP_ROLE_MAPPING.containsKey(group) ? LDAP_ROLE_MAPPING.get(group) : group);
}
return result;
}
示例6: getUser
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public User getUser(String realm, String uid) {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter(OBJECTCLASS, userObjectClass)).and(new EqualsFilter(userSearchAttribute, uid));
DistinguishedName dn = new DistinguishedName("ou=" + realm);
User user;
try {
List userList = ldapTemplate.search(dn, filter.toString(), SearchControls.SUBTREE_SCOPE, new String[] {
"*", CREATE_TIMESTAMP, MODIFY_TIMESTAMP }, new UserContextMapper());
if (userList == null || userList.size() == 0) {
throw new EmptyResultDataAccessException(1);
} else if (userList.size() > 1) {
throw new IncorrectResultSizeDataAccessException("User must be unique", 1);
}
user = (User) userList.get(0);
user.setUid(uid);
user.setGroups(getGroupNames(getUserGroups(realm, uid)));
} catch (EmptyResultDataAccessException e) {
return null;
}
return user;
}
示例7: testAuthenticateWithLookupOperationPerformedOnAuthenticatedContext
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
@Test
@Category(NoAdTest.class)
public void testAuthenticateWithLookupOperationPerformedOnAuthenticatedContext() {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3"));
AuthenticatedLdapEntryContextCallback contextCallback = new AuthenticatedLdapEntryContextCallback() {
public void executeWithContext(DirContext ctx, LdapEntryIdentification ldapEntryIdentification) {
try {
DirContextAdapter adapter = (DirContextAdapter) ctx.lookup(ldapEntryIdentification.getRelativeDn());
assertThat(adapter.getStringAttribute("cn")).isEqualTo("Some Person3");
}
catch (NamingException e) {
throw new RuntimeException("Failed to lookup " + ldapEntryIdentification.getRelativeDn(), e);
}
}
};
assertThat(tested.authenticate("", filter.toString(), "password", contextCallback)).isTrue();
}
示例8: verifyAuthenticate
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
@Category(NoAdTest.class)
public void verifyAuthenticate() {
EqualsFilter filter = new EqualsFilter("cn", "Some Person2");
List<String> results = ldapTemplate.search("", filter.toString(), new DnContextMapper());
if (results.size() != 1) {
throw new IncorrectResultSizeDataAccessException(1, results.size());
}
DirContext ctx = null;
try {
ctx = tested.getContext(results.get(0), "password");
assertThat(true).isTrue();
}
catch (Exception e) {
fail("Authentication failed");
}
finally {
LdapUtils.closeContext(ctx);
}
}
示例9: testFindOne
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
@Test
public void testFindOne() throws Exception {
Class<Object> expectedClass = Object.class;
when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock);
when(odmMock.filterFor(expectedClass,
new EqualsFilter("ou", "somevalue"))).thenReturn(new EqualsFilter("ou", "somevalue"));
DirContextAdapter expectedObject = new DirContextAdapter();
SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes());
singleSearchResult(searchControlsRecursive(), searchResult);
Object expectedResult = expectedObject;
when(odmMock.mapFromLdapDataEntry(expectedObject, expectedClass)).thenReturn(expectedResult);
Object result = tested.findOne(query()
.where("ou").is("somevalue"), expectedClass);
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
assertThat(result).isSameAs(expectedResult);
}
示例10: verifyThatFindOneThrowsEmptyResultIfNoResult
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
@Test
public void verifyThatFindOneThrowsEmptyResultIfNoResult() throws Exception {
Class<Object> expectedClass = Object.class;
when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock);
when(odmMock.filterFor(expectedClass,
new EqualsFilter("ou", "somevalue"))).thenReturn(new EqualsFilter("ou", "somevalue"));
noSearchResults(searchControlsRecursive());
try {
tested.findOne(query().where("ou").is("somevalue"), expectedClass);
fail("EmptyResultDataAccessException expected");
} catch (EmptyResultDataAccessException expected) {
assertThat(true).isTrue();
}
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
verify(odmMock, never()).mapFromLdapDataEntry(any(LdapDataEntry.class), any(Class.class));
}
示例11: verifyThatFindOneThrowsIncorrectResultSizeDataAccessExceptionWhenMoreResults
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
@Test
public void verifyThatFindOneThrowsIncorrectResultSizeDataAccessExceptionWhenMoreResults() throws Exception {
Class<Object> expectedClass = Object.class;
when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock);
when(odmMock.filterFor(expectedClass,
new EqualsFilter("ou", "somevalue"))).thenReturn(new EqualsFilter("ou", "somevalue"));
DirContextAdapter expectedObject = new DirContextAdapter();
SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes());
setupSearchResults(searchControlsRecursive(), new SearchResult[]{searchResult, searchResult});
Object expectedResult = expectedObject;
when(odmMock.mapFromLdapDataEntry(expectedObject, expectedClass)).thenReturn(expectedResult, expectedResult);
try {
tested.findOne(query().where("ou").is("somevalue"), expectedClass);
fail("EmptyResultDataAccessException expected");
} catch (IncorrectResultSizeDataAccessException expected) {
assertThat(true).isTrue();
}
verify(namingEnumerationMock).close();
verify(dirContextMock).close();
}
示例12: findAllNoCache
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
/**
* Fetch and return all normalized customers for projects.
*
* @param baseDn
* Base DN.
* @return all normalized customers for projects. Key is the DN, Value is the normalized name.
*/
public Map<String, String> findAllNoCache(final String baseDn) {
final Map<String, String> result = new HashMap<>();
for (final DirContextAdapter groupRaw : getUser().getTemplate().search(baseDn, new EqualsFilter("objectClass", CUSTOMER_OF_PROJECT).encode(),
(Object ctx) -> (DirContextAdapter) ctx)) {
final String dn = groupRaw.getDn().toString();
result.put(DnUtils.toRdn(dn), dn);
}
return result;
}
示例13: findAllBy
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
@Override
public List<UserOrg> findAllBy(final String attribute, final String value) {
final AndFilter filter = new AndFilter();
filter.and(new EqualsFilter(OBJECT_CLASS, peopleClass));
filter.and(new EqualsFilter(attribute, value));
return template.search(peopleBaseDn, filter.encode(), mapper).stream().map(u -> Optional.ofNullable(findById(u.getId())).orElse(u))
.collect(Collectors.toList());
}
示例14: authenticate
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
@Override
public boolean authenticate(final String name, final String password) {
log.info("Authenticating {} ...", name);
final String property = getAuthenticateProperty(name);
final AndFilter filter = new AndFilter().and(new EqualsFilter("objectclass", peopleClass)).and(new EqualsFilter(property, name));
final boolean result = template.authenticate(peopleBaseDn, filter.encode(), password);
log.info("Authenticate {} : {}", name, result);
return result;
}
示例15: getToken
import org.springframework.ldap.filter.EqualsFilter; //导入依赖的package包/类
@Override
public String getToken(final String login) {
final AndFilter filter = new AndFilter();
filter.and(new EqualsFilter(OBJECT_CLASS, peopleClass));
filter.and(new EqualsFilter(uidAttribute, login));
return template.search(peopleBaseDn, filter.encode(), new AbstractContextMapper<String>() {
@Override
public String doMapFromContext(final DirContextOperations context) {
// Get the password
return new String(ObjectUtils.defaultIfNull((byte[]) context.getObjectAttribute(PASSWORD_ATTRIBUTE), new byte[0]),
StandardCharsets.UTF_8);
}
}).stream().findFirst().orElse(null);
}