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


Java ContextMapper类代码示例

本文整理汇总了Java中org.springframework.ldap.core.ContextMapper的典型用法代码示例。如果您正苦于以下问题:Java ContextMapper类的具体用法?Java ContextMapper怎么用?Java ContextMapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ContextMapper类属于org.springframework.ldap.core包,在下文中一共展示了ContextMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMembers

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
@Override
public List<String> getMembers(String groupName) {

	Set<String> eppns = new HashSet<String>();

	for(String ldapFilter: ldapFiltersGroups.keySet()) {

		if(ldapFiltersGroups.get(ldapFilter).equals(groupName)) {

			eppns.addAll(ldapTemplate.search(query().filter(ldapFilter) ,new ContextMapper<String>() {

				@Override
				public String mapFromContext(Object ctx) throws NamingException {
					DirContextAdapter searchResultContext = (DirContextAdapter)ctx;
					String eppn = searchResultContext.getStringAttribute("eduPersonPrincipalName");
					return eppn;
				}
			}));
		}
	}

	return new ArrayList<String>(eppns);
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:24,代码来源:LdapFilterGroupService.java

示例2: getMembers

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
@Override
public List<String> getMembers(String groupName) {

	String formattedFilter = MessageFormat.format(memberSearchFilter, new String[] {groupName});
		
	List<String> eppns = ldapTemplate.search(
			memberSearchBase, formattedFilter,new ContextMapper<String>() {

					@Override
					public String mapFromContext(Object ctx) throws NamingException {
						DirContextAdapter searchResultContext = (DirContextAdapter)ctx;
				        String eppn = searchResultContext.getStringAttribute("eduPersonPrincipalName");
						return eppn;
					}
				});
	
	return eppns;
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:19,代码来源:LdapGroupService.java

示例3: getMembers

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
public List<String> getMembers(String groupName) {

		String formattedFilter = MessageFormat.format(memberSearchFilter, new String[] {groupName});
			
		List<String> eppns = ldapTemplate.search(
				memberSearchBase, formattedFilter,new ContextMapper<String>() {
	
						@Override
						public String mapFromContext(Object ctx) throws NamingException {
							DirContextAdapter searchResultContext = (DirContextAdapter)ctx;
					        String eppn = searchResultContext.getStringAttribute("eduPersonPrincipalName");
							return eppn;
						}
					});
		
		return eppns;
	}
 
开发者ID:EsupPortail,项目名称:esup-nfc-tag-server,代码行数:18,代码来源:GroupService.java

示例4: getContextMapper

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected ContextMapper getContextMapper() {
    return new ContextMapper() {
        @Override
        public Object mapFromContext(Object ctx) {
            DirContextAdapter context = (DirContextAdapter) ctx;
            try {
                return ldapGroupAttributesMapper.mapAttributes(context.getNameInNamespace(),
                        context.getAttributes());
            } catch (LdapAttributeMappingException e) {
                LOGGER.warn("Error mapping a user from LDAP/AD: {} for {}", e.getMessage(),
                        context.getDn());
            }
            return null;
        }
    };
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:21,代码来源:MemberAndNonMemberModeVisitingRetriever.java

示例5: testLoadUserByUsernameNoGroups

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
/**
 * Test the main Spring Security method.  This tests edge case of no groups.
 * @throws Exception
 */
@Test
public void testLoadUserByUsernameNoGroups() throws Exception {
	Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
	authorities.add(new GrantedAuthorityImpl("ROLE_USER"));
	
	Collection<OwfGroup> groups = new ArrayList<OwfGroup>();
	
	OWFUserDetailsImpl owfUserDetails = new OWFUserDetailsImpl("jsmith", "password", authorities, groups);

	LdapOperations ldapOperations = mock(LdapOperations.class);
	when(ldapOperations.search(anyString(), anyString(), (ContextMapper)anyObject())).thenReturn(ldapAuthorityGroups);
	when(ldapOperations.lookup(anyString(), (ContextMapper)anyObject())).thenReturn(owfUserDetails);
	
	ldapUserDetailsService.setGroupSearchBase("ou=groups");
	ldapUserDetailsService.setLdapOperations(ldapOperations);
	ldapUserDetailsService.setGroupSearchQuery("(&(objectClass=groupOfNames)(member=?))");
	ldapUserDetailsService.setRoleSearchBase("ou=Ozone,o=Ozone,l=Columbia,st=Maryland,c=US");		
	ldapUserDetailsService.setRoleSearchQuery("(&(objectclass=groupOfNames)(member=?))");
	
	UserDetails userDetails = ldapUserDetailsService.loadUserByUsername("jsmith");
	
	// Since the building of the user details object is tested elsewhere 
	// and we've mocked up the lookup() method, just check for null.
	assertNotNull(userDetails);
}
 
开发者ID:ozoneplatform,项目名称:owf-security,代码行数:30,代码来源:LdapUserDetailsServiceTest.java

示例6: testLoadUserByUsernameWithNullLookup

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
/**
 * Test the main Spring Security method with a null lookup.
 */
@Test(expected=UsernameNotFoundException.class)
public void testLoadUserByUsernameWithNullLookup() {
	LdapOperations ldapOperations = mock(LdapOperations.class);
	when(ldapOperations.search(anyString(), anyString(), (ContextMapper)anyObject())).thenReturn(ldapAuthorityGroups);
	when(ldapOperations.lookup(anyString(), (ContextMapper)anyObject())).thenReturn(null);
	
	ldapUserDetailsService.setGroupSearchBase("ou=groups");
	ldapUserDetailsService.setLdapOperations(ldapOperations);
	ldapUserDetailsService.setGroupSearchQuery("(&(objectClass=groupOfNames)(member=?))");
	ldapUserDetailsService.setRoleSearchBase("ou=Ozone,o=Ozone,l=Columbia,st=Maryland,c=US");
	ldapUserDetailsService.setRoleSearchQuery("(&(objectclass=groupOfNames)(member=?))");
	
	
	ldapUserDetailsService.loadUserByUsername("jsmith");
}
 
开发者ID:ozoneplatform,项目名称:owf-security,代码行数:19,代码来源:LdapUserDetailsServiceTest.java

示例7: testLoadUserByUsernameWithNoAuthorities

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
/**
 * Test the main Spring Security method with no authorities (should
 * throw an exception).
 */
@Test(expected=UsernameNotFoundException.class)
public void testLoadUserByUsernameWithNoAuthorities() {
	Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
	OWFUserDetailsImpl owfUserDetails = new OWFUserDetailsImpl("jsmith", "password", authorities, new ArrayList<OwfGroup>());

	LdapOperations ldapOperations = mock(LdapOperations.class);
	when(ldapOperations.search(anyString(), anyString(), (ContextMapper)anyObject())).thenReturn(ldapAuthorityGroups);
	when(ldapOperations.lookup(anyString(), (ContextMapper)anyObject())).thenReturn(owfUserDetails);
	
	ldapUserDetailsService.setGroupSearchBase("ou=groups");
	ldapUserDetailsService.setLdapOperations(ldapOperations);
	ldapUserDetailsService.setGroupSearchQuery("(&(objectClass=groupOfNames)(member=?))");
	ldapUserDetailsService.setRoleSearchBase("ou=Ozone,o=Ozone,l=Columbia,st=Maryland,c=US");
	ldapUserDetailsService.setRoleSearchQuery("(&(objectclass=groupOfNames)(member=?))");
			
	ldapUserDetailsService.loadUserByUsername("jsmith");
}
 
开发者ID:ozoneplatform,项目名称:owf-security,代码行数:22,代码来源:LdapUserDetailsServiceTest.java

示例8: testExpectedControlsSupported

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
@Test
   @Category(NoAdTest.class)
public void testExpectedControlsSupported() throws Exception {
	/**
	 * Maps the 'supportedcontrol' attribute to a string array.
	 */
	ContextMapper mapper = new ContextMapper() {

		public Object mapFromContext(Object ctx) {
			DirContextAdapter adapter = (DirContextAdapter) ctx;
			return adapter.getStringAttributes(SUPPORTED_CONTROL);
		}

	};

	String[] controls = (String[]) tested.lookup("", new String[] { SUPPORTED_CONTROL }, mapper);
	System.out.println(Arrays.toString(controls));

       HashSet<String> controlsSet = new HashSet<String>(Arrays.asList(controls));

       assertThat(controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")).as("Entry Change Notification LDAPv3 control,").isTrue();
	assertThat(controlsSet.contains("1.3.6.1.4.1.4203.1.10.1")).as("Subentries Control,").isTrue();
	assertThat(controlsSet.contains("2.16.840.1.113730.3.4.2")).as("Manage DSA IT LDAPv3 control,").isTrue();
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:25,代码来源:SupportedControlsITest.java

示例9: getTokenNotExists

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void getTokenNotExists() {
	final LdapTemplate mock = Mockito.mock(LdapTemplate.class);
	Mockito.when(mock.search((String) ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(ContextMapper.class)))
			.thenReturn(Collections.emptyList());
	repository.setTemplate(mock);
	Assert.assertNull(repository.getToken("any"));
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:10,代码来源:UserLdapRepositoryTest.java

示例10: retrieve

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
@Override
public User retrieve(String id) {
    AndFilter filter = new AndFilter();
    filter.and(new EqualsFilter("objectclass", "person"));
    filter.and(new EqualsFilter(identifierAttribute, id));

    LdapQuery ldapQuery = LdapQueryBuilder
            .query()
            .base(baseDn)
            .countLimit(1)
            .timeLimit(5000)
            .searchScope(SearchScope.SUBTREE)
            .attributes(identifierAttribute, "givenname", "sn", "mail")
            .filter(filter);

    List<User> users = ldapTemplate.search(ldapQuery, new UserAttributesMapper());
    if (users != null && ! users.isEmpty()) {
        LdapUser user = (LdapUser) users.iterator().next();
        List<String> result = ldapTemplate.search(
                baseDn, filter.encode(),
                (ContextMapper<String>) o -> ((LdapCtx) o).getNameInNamespace());
        user.setDn(result.iterator().next());

        return user;
    } else {
        return null;
    }
}
 
开发者ID:gravitee-io,项目名称:gravitee-management-rest-api,代码行数:29,代码来源:LdapIdentityLookup.java

示例11: testLoadUserByUsername

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
/**
 * Test the main Spring Security method.
 * @throws Exception
 */
@Test
public void testLoadUserByUsername() throws Exception {
	Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
	authorities.add(new GrantedAuthorityImpl("ROLE_USER"));
	
	Collection<OwfGroup> groups = new ArrayList<OwfGroup>();
	groups.add(new OwfGroupImpl("My Special Group!", "Description 1", "[email protected]", true)); 
	groups.add(new OwfGroupImpl("My Boring Group!", "Description 2", "[email protected]", true));
	
	OWFUserDetailsImpl owfUserDetails = new OWFUserDetailsImpl("jsmith", "password", authorities, groups);

	LdapOperations ldapOperations = mock(LdapOperations.class);
	when(ldapOperations.search(anyString(), anyString(), (ContextMapper)anyObject())).thenReturn(ldapAuthorityGroups);
	when(ldapOperations.lookup(anyString(), (ContextMapper)anyObject())).thenReturn(owfUserDetails);
	
	ldapUserDetailsService.setGroupSearchBase("ou=groups");
	ldapUserDetailsService.setRoleSearchBase("ou=groups");
	ldapUserDetailsService.setGroupSearchQuery("ou=groups");
	ldapUserDetailsService.setRoleSearchQuery("ou=groups");
	ldapUserDetailsService.setLdapOperations(ldapOperations);
	
	UserDetails userDetails = ldapUserDetailsService.loadUserByUsername("jsmith");
	
	// Since the building of the user details object is tested elsewhere 
	// and we've mocked up the lookup() method, just check for null.
	assertNotNull(userDetails);
	assertEquals("jsmith", userDetails.getUsername() );
	OWFUserDetails owfUserDetailsResult = (OWFUserDetails)userDetails;
	
	assertEquals(2,owfUserDetailsResult.getOwfGroups().size());
	
}
 
开发者ID:ozoneplatform,项目名称:owf-security,代码行数:37,代码来源:LdapUserDetailsServiceTest.java

示例12: testAuthenticate

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
@Test
public void testAuthenticate() throws AuthenticationException {
    DistinguishedName dn = new DistinguishedName("ou=SLIAdmin");
    Mockito.when(
            ldapTemplate.authenticate(Mockito.eq(dn), Mockito.eq("(&(objectclass=person)(uid=testuser))"),
                    Mockito.eq("testuser1234"), Mockito.any(AuthenticationErrorCallback.class))).thenReturn(true);
    User mockUser = new User();
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("userName", "Test User");
    mockUser.attributes = attributes;
    mockUser.userId = "testuser";
    Mockito.when(
            ldapTemplate.searchForObject(Mockito.eq(dn), Mockito.eq("(&(objectclass=person)(uid=testuser))"),
                    Mockito.any(ContextMapper.class))).thenReturn(mockUser);
    List<String> mockGroups = new ArrayList<String>();
    mockGroups.add("TestGroup1");
    mockGroups.add("TestGroup2");
    Mockito.when(
            ldapTemplate.search(Mockito.eq(dn), Mockito.eq("(&(objectclass=posixGroup)(memberuid=testuser))"),
                    Mockito.any(GroupContextMapper.class))).thenReturn(mockGroups);

    UserService.User user = userService.authenticate("SLIAdmin", "testuser", "testuser1234");
    assertEquals("testuser", user.getUserId());
    assertEquals("Test User", user.getAttributes().get("userName"));
    assertEquals("staff", user.getAttributes().get("userType"));
    assertEquals(2, user.getRoles().size());
    assertEquals("TestGroup1", user.getRoles().get(0));
    assertEquals("TestGroup2", user.getRoles().get(1));
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:30,代码来源:UsersTest.java

示例13: testStaffAuthenticate

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
@Test
public void testStaffAuthenticate() throws AuthenticationException {
    DistinguishedName dn = new DistinguishedName("ou=StaffMember");
    List<String> mockGroups = new ArrayList<String>();
    mockGroups.add("Educator");
    Mockito.when(
            ldapTemplate.search(Mockito.eq(dn), Mockito.eq("(&(objectclass=posixGroup)(memberuid=staffuser))"),
                    Mockito.any(GroupContextMapper.class))).thenReturn(mockGroups);

    Mockito.when(
            ldapTemplate.authenticate(Mockito.eq(dn), Mockito.eq("(&(objectclass=person)(uid=staffuser))"),
                    Mockito.eq("staffuser1234"), Mockito.any(AuthenticationErrorCallback.class))).thenReturn(true);

    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("userName", "Staff User");
    attributes.put("userType", "staff");
    User mockUser = new User("staffuser", mockGroups, attributes);

    Mockito.when(
            ldapTemplate.searchForObject(Mockito.eq(dn), Mockito.eq("(&(objectclass=person)(uid=staffuser))"),
                    Mockito.any(ContextMapper.class))).thenReturn(mockUser);

    UserService.User user = userService.authenticate("StaffMember", "staffuser", "staffuser1234");
    assertEquals("staffuser", user.getUserId());
    assertEquals("Staff User", user.getAttributes().get("userName"));
    assertEquals("staff", user.getAttributes().get("userType"));
    assertEquals(1, user.getRoles().size());
    assertEquals("Educator", user.getRoles().get(0));
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:30,代码来源:UsersTest.java

示例14: testStudentAuthenticate

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
@Test
public void testStudentAuthenticate() throws AuthenticationException {
    DistinguishedName dn = new DistinguishedName("ou=Students");
    List<String> mockGroups = new ArrayList<String>();
    mockGroups.add("Student");
    Mockito.when(
            ldapTemplate.search(Mockito.eq(dn), Mockito.eq("(&(objectclass=posixGroup)(memberuid=studentuser))"),
                    Mockito.any(GroupContextMapper.class))).thenReturn(mockGroups);

    Mockito.when(
            ldapTemplate.authenticate(Mockito.eq(dn), Mockito.eq("(&(objectclass=person)(uid=studentuser))"),
                    Mockito.eq("studentuser1234"), Mockito.any(AuthenticationErrorCallback.class))).thenReturn(true);

    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("userName", "Student User");
    attributes.put("userType", "student");
    attributes.put("employeeNumber", "1234567890");
    User mockUser = new User("studentuser", mockGroups, attributes);

    Mockito.when(
            ldapTemplate.searchForObject(Mockito.eq(dn), Mockito.eq("(&(objectclass=person)(uid=studentuser))"),
                    Mockito.any(ContextMapper.class))).thenReturn(mockUser);

    UserService.User user = userService.authenticate("Students", "studentuser", "studentuser1234");
    assertEquals("1234567890", user.getUserId());
    assertEquals("Student User", user.getAttributes().get("userName"));
    assertEquals("student", user.getAttributes().get("userType"));
    assertEquals(1, user.getRoles().size());
    assertEquals("Student", user.getRoles().get(0));
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:31,代码来源:UsersTest.java

示例15: testSandboxAuthenticate

import org.springframework.ldap.core.ContextMapper; //导入依赖的package包/类
@Test
public void testSandboxAuthenticate() throws AuthenticationException {
    DistinguishedName dn = new DistinguishedName("ou=SLIAdmin");
    Mockito.when(
            ldapTemplate.authenticate(Mockito.eq(dn), Mockito.eq("(&(objectclass=person)(uid=testuser))"),
                    Mockito.eq("testuser1234"), Mockito.any(AuthenticationErrorCallback.class))).thenReturn(true);
    User mockUser = new User();
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("userName", "Test User");
    attributes.put("Tenant", "mytenant");
    attributes.put("isAdmin", "true");
    mockUser.attributes = attributes;
    mockUser.userId = "testuser";
    Mockito.when(
            ldapTemplate.searchForObject(Mockito.eq(dn), Mockito.eq("(&(objectclass=person)(uid=testuser))"),
                    Mockito.any(ContextMapper.class))).thenReturn(mockUser);
    List<String> mockGroups = new ArrayList<String>();
    mockGroups.add("TestGroup1");
    mockGroups.add("TestGroup2");
    Mockito.when(
            ldapTemplate.search(Mockito.eq(dn), Mockito.eq("(&(objectclass=posixGroup)(memberuid=testuser))"),
                    Mockito.any(GroupContextMapper.class))).thenReturn(mockGroups);

    UserService.User user = userService.authenticate("SLIAdmin", "testuser", "testuser1234");
    assertEquals("testuser", user.getUserId());
    assertEquals("Test User", user.getAttributes().get("userName"));
    assertEquals("mytenant", user.getAttributes().get("Tenant"));
    assertEquals("admin", user.getAttributes().get("userType"));
    assertEquals(2, user.getRoles().size());
    assertEquals("TestGroup1", user.getRoles().get(0));
    assertEquals("TestGroup2", user.getRoles().get(1));
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:33,代码来源:UsersTest.java


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