当前位置: 首页>>代码示例>>Java>>正文


Java EqualsFilter类代码示例

本文整理汇总了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;
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:26,代码来源:UserLdapRepository.java

示例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);
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:37,代码来源:UserLdapResourceTest.java

示例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());
}
 
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:19,代码来源:LdapIdentityLookup.java

示例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;
      }
    }
  });
}
 
开发者ID:outbrain,项目名称:ob1k,代码行数:17,代码来源:LdapCredentialsAuthenticator.java

示例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;
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:25,代码来源:UserService.java

示例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;
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:24,代码来源:LdapServiceImpl.java

示例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();
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:19,代码来源:LdapTemplateAuthenticationITest.java

示例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);
	}
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:23,代码来源:LdapContextSourceIntegrationTest.java

示例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);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:24,代码来源:LdapTemplateTest.java

示例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));
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:22,代码来源:LdapTemplateTest.java

示例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();
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:27,代码来源:LdapTemplateTest.java

示例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;
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:17,代码来源:ProjectCustomerLdapRepository.java

示例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());
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:9,代码来源:UserLdapRepository.java

示例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;
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:10,代码来源:UserLdapRepository.java

示例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);
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:15,代码来源:UserLdapRepository.java


注:本文中的org.springframework.ldap.filter.EqualsFilter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。