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


Java DirContextAdapter类代码示例

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


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

示例1: create

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的package包/类
@Override
public UserOrg create(final UserOrg entry) {
	// Build the DN
	final Name dn = buildDn(entry);

	// Create the LDAP entry
	entry.setDn(dn.toString());
	final DirContextAdapter context = new DirContextAdapter(dn);
	context.setAttributeValues(OBJECT_CLASS, new String[] { peopleClass });
	mapToContext(entry, context);
	template.bind(context);

	// Also, update the cache
	ldapCacheRepository.create(entry);

	// Return the original entry with updated DN
	return entry;
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:19,代码来源:UserLdapRepository.java

示例2: findAllNoCache

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的package包/类
/**
 * Fetch and return all normalized companies. Note the result use cache, so does not reflect the current state of
 * LDAP.
 * 
 * @return the companies. Key is the normalized name.
 */
public Map<String, CompanyOrg> findAllNoCache() {
	final Map<String, CompanyOrg> companiesNameToDn = new HashMap<>();
	for (final DirContextAdapter company : template.search(companyBaseDn, "objectClass=" + ORGANIZATIONAL_UNIT,
			(Object ctx) -> (DirContextAdapter) ctx)) {
		final CompanyOrg companyLdap = new CompanyOrg(company.getDn().toString(), company.getStringAttributes("ou")[0]);
		companiesNameToDn.put(companyLdap.getId(), companyLdap);
	}

	// Also add/replace the quarantine zone
	final CompanyOrg quarantine = new CompanyOrg(quarantineBaseDn, getQuarantineCompany());
	quarantine.setLocked(true);
	companiesNameToDn.put(quarantine.getId(), quarantine);

	// The complete the hierarchy of companies
	companiesNameToDn.values().forEach(this::buildLdapName);
	companiesNameToDn.values().forEach(c -> this.buildHierarchy(companiesNameToDn, c));
	return companiesNameToDn;
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:25,代码来源:CompanyLdapRepository.java

示例3: getMembers

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的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

示例4: getMembers

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的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

示例5: getMembers

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的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

示例6: mapFromContext

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public ExternalUserGroup mapFromContext(Object contex) {
    DirContextAdapter context = (DirContextAdapter) contex;
    ExternalUserGroup result = ExternalUserGroup.Factory.newInstance();
    try {
        ExternalGroupVO externalGroup = new LdapGroupAttributesMapper(groupSyncConfig
                .getGroupSearch()
                .getPropertyMapping(),
                groupSyncConfig.getLdapConfiguration().getSystemId(),
                groupSyncConfig.isGroupIdentifierIsBinary()).mapAttributes(context.getDn()
                .toString(), context.getAttributes());
        if (externalGroup != null && userGroupManagement != null) {
            // TODO is this a good idea to create any group?
            Long groupId = userGroupManagement.createOrUpdateExternalGroup(externalGroup);
            result = externalUserGroupDao.load(groupId);
        }
    } catch (Exception e) {
        LOGGER.error("Error during context mapping: {} ", e.getMessage());
    }
    return result;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:25,代码来源:ExternalGroupVOContextMapper.java

示例7: getContextMapper

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的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

示例8: testContextMapper

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的package包/类
/**
 * Test mapping functionality, ensure the proper fields get mapped.
 * @throws Exception
 */
@Test
public void testContextMapper() throws Exception {

	DirContextAdapter contextAdapter = mock(DirContextAdapter.class);
	when(contextAdapter.getDn()).thenReturn(new LdapName("cn=user,ou=groups,o=OWF,st=Maryland,c=us"));
	when(contextAdapter.getStringAttribute("cn")).thenReturn("user");
	when(contextAdapter.getStringAttributes("member")).thenReturn(new String[]{ "cn=jsmith,ou=OWF,o=OWFDevelopment,l=Columbia,st=Maryland,c=US",
			                                                                    "cn=jdoe,ou=OWF,o=OWFDevelopment,l=Columbia,st=Maryland,c=US"
			                                                                  });
	
	Object oLdapAuthorityGroup = ldapAuthorityGroupContextMapper.mapFromContext(contextAdapter);
	
	assertTrue(new IsInstanceOf(LdapAuthorityGroup.class).matches(oLdapAuthorityGroup));
	LdapAuthorityGroup ldapAuthorityGroup = (LdapAuthorityGroup)oLdapAuthorityGroup;
	
	assertEquals("cn=user,ou=groups,o=OWF,st=Maryland,c=us",ldapAuthorityGroup.getDn());
	assertEquals("user",ldapAuthorityGroup.getCn());
	assertEquals(2,ldapAuthorityGroup.getMembers().length);
}
 
开发者ID:ozoneplatform,项目名称:owf-security,代码行数:24,代码来源:LdapAuthorityGroupContextMapperTest.java

示例9: testGetObjectInstance_BaseSet

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的package包/类
/**
 * Make sure that the base suffix is stripped off from the DN.
 * 
 * @throws Exception
 */
   @Test
public void testGetObjectInstance_BaseSet() throws Exception {
	Attributes expectedAttributes = new NameAwareAttributes();
	expectedAttributes.put("someAttribute", "someValue");

	when(contextMock2.getNameInNamespace()).thenReturn("dc=jayway, dc=se");

	DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(contextMock, LdapUtils.newLdapName(
			"ou=some unit"), contextMock2, new Hashtable(), expectedAttributes);

       verify(contextMock).close();

	assertThat(adapter.getDn().toString()).isEqualTo("ou=some unit");
	assertThat(adapter.getNameInNamespace()).isEqualTo("ou=some unit,dc=jayway,dc=se");
	assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:22,代码来源:DefaultDirObjectFactoryTest.java

示例10: testAttributeExtractionCommas

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的package包/类
@Test
public void testAttributeExtractionCommas() {
    String desc = "tenant=myTenantId,edOrg=myEdorgId";
    PersonContextMapper mapper = new PersonContextMapper();
    DirContextAdapter context = Mockito.mock(DirContextAdapter.class);
    Mockito.when(context.getStringAttribute("cn")).thenReturn("Full Name");
    Mockito.when(context.getStringAttribute("description")).thenReturn(desc);
    User user = (User) mapper.mapFromContext(context);

    assertEquals("Full Name", user.getAttributes().get("userName"));
    assertEquals("myTenantId", user.getAttributes().get("tenant"));
    assertEquals("myEdorgId", user.getAttributes().get("edOrg"));
    assertEquals(null, user.getAttributes().get("vendor"));
    assertEquals(null, user.getAttributes().get("givenName"));
    assertEquals(null, user.getAttributes().get("sn"));
    assertEquals(6, user.getAttributes().size());
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:18,代码来源:UsersTest.java

示例11: create

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的package包/类
public void create(OrgPerson person) {
	DistinguishedName dn = new DistinguishedName();
       dn.add("ou", person.getCountry());
       dn.add("ou", person.getCompany());
       dn.add("cn", person.getFullname());

       DirContextAdapter ctx = new DirContextAdapter();
       ctx.setAttributeValues("objectclass", new String[] { "top", "person" });
       ctx.setAttributeValue("cn", person.getFullname());
       ctx.setAttributeValue("sn", person.getLastname());
       ctx.setAttributeValue("description", person.getDescription());
       ldapTemplate.bind(dn, ctx, null);
	this.getHibernateTemplate().saveOrUpdate(person);


}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:17,代码来源:DummyDaoLdapAndHibernateImpl.java

示例12: testExpectedControlsSupported

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的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

示例13: testAuthenticateWithLookupOperationPerformedOnAuthenticatedContext

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的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

示例14: testBindAndUnbind_Plain

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的package包/类
@Test
public void testBindAndUnbind_Plain() {
	DirContextAdapter adapter = new DirContextAdapter();
	adapter.setAttributeValues("objectclass", new String[] { "top", "person" });
	adapter.setAttributeValue("cn", "Some Person4");
	adapter.setAttributeValue("sn", "Person4");
	tested.bind("cn=Some Person4, ou=company1, ou=Sweden," + base, adapter, null);

	DirContextAdapter result = (DirContextAdapter) tested
			.lookup("cn=Some Person4, ou=company1, ou=Sweden," + base);

	assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4");
	assertThat(result.getStringAttribute("sn")).isEqualTo("Person4");
	assertThat(result.getDn()).isEqualTo(LdapUtils.newLdapName("cn=Some Person4,ou=company1,ou=Sweden," + base));

	tested.unbind("cn=Some Person4,ou=company1,ou=Sweden," + base);
	try {
		tested.lookup("cn=Some Person4, ou=company1, ou=Sweden," + base);
		fail("NameNotFoundException expected");
	}
	catch (NameNotFoundException expected) {
		assertThat(true).isTrue();
	}
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:25,代码来源:LdapTemplateNoBaseSuffixITest.java

示例15: testBindAndRebindWithDirContextAdapterOnly

import org.springframework.ldap.core.DirContextAdapter; //导入依赖的package包/类
@Test
public void testBindAndRebindWithDirContextAdapterOnly() {
	DirContextAdapter adapter = new DirContextAdapter(LdapUtils.newLdapName(DN));
	adapter.setAttributeValues("objectclass", new String[] { "top",
			"person" });
	adapter.setAttributeValue("cn", "Some Person4");
	adapter.setAttributeValue("sn", "Person4");

	tested.bind(adapter);
	verifyBoundCorrectData();
	adapter.setAttributeValue("sn", "Person4.Changed");
	tested.rebind(adapter);
	verifyReboundCorrectData();
	tested.unbind(DN);
	verifyCleanup();
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:17,代码来源:LdapTemplateBindUnbindITest.java


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