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


Java LdapUtils类代码示例

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


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

示例1: loadData

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
protected static void loadData() throws Exception
{
    // Bind to the directory
    LdapContextSource contextSource = new LdapContextSource();
    contextSource.setUrl("ldap://127.0.0.1:10389");
    contextSource.setUserDn("uid=admin,ou=system");
    contextSource.setPassword("secret");
    contextSource.setPooled(false);
    //contextSource.setDirObjectFactory(null);
    contextSource.afterPropertiesSet();

    // Create the Sprint LDAP template
    LdapTemplate template = new LdapTemplate(contextSource);

    // Clear out any old data - and load the test data
    LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName("dc=example,dc=com"));
    LdapTestUtils.loadLdif(contextSource, new ClassPathResource("data.ldif"));
}
 
开发者ID:geoserver,项目名称:geofence,代码行数:19,代码来源:BaseDAOTest.java

示例2: doAuthentication

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
@Override
protected DirContextOperations doAuthentication(
		UsernamePasswordAuthenticationToken auth) {
	String username = auth.getName();
	String password = (String) auth.getCredentials();

	DirContext ctx = bindAsUser(username, password);

	try {
		return searchForUser(ctx, username);
	}
	catch (NamingException e) {
		logger.error("Failed to locate directory entry for authenticated user: "
				+ username, e);
		throw badCredentials(e);
	}
	finally {
		LdapUtils.closeContext(ctx);
	}
}
 
开发者ID:gustajz,项目名称:parking-api,代码行数:21,代码来源:ActiveDirectoryAliasLdapAuthenticationProvider.java

示例3: testAddDnAttributeNewValue

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
@Test
public void testAddDnAttributeNewValue() throws NamingException {
    BasicAttributes attributes = new BasicAttributes();
    attributes.put("uniqueMember", "cn=john doe, ou=company");

    DirContextAdapter tested = new DirContextAdapter(attributes, LdapUtils.newLdapName("cn=administrators, ou=groups"));
    tested.setUpdateMode(true);

    tested.addAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=jane doe, ou=company"));
    ModificationItem[] modificationItems = tested.getModificationItems();
    assertThat(modificationItems.length).isEqualTo(1);

    ModificationItem modificationItem = modificationItems[0];
    assertThat(modificationItem.getModificationOp()).isEqualTo(DirContext.ADD_ATTRIBUTE);
    assertThat(modificationItem.getAttribute().getID()).isEqualTo("uniqueMember");
    assertThat(modificationItem.getAttribute().get()).isEqualTo("cn=jane doe, ou=company");
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:18,代码来源:DirContextAdapterTest.java

示例4: testUpdateWithIdSpecified

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
@Test
public void testUpdateWithIdSpecified() throws NamingException {
    when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock);
    when(contextSourceMock.getReadWriteContext()).thenReturn(dirContextMock);
    LdapName expectedName = LdapUtils.newLdapName("ou=someOu");

    ModificationItem[] expectedModificationItems = new ModificationItem[0];
    DirContextOperations ctxMock = mock(DirContextOperations.class);
    when(ctxMock.getDn()).thenReturn(expectedName);
    when(ctxMock.isUpdateMode()).thenReturn(true);
    when(ctxMock.getModificationItems()).thenReturn(expectedModificationItems);

    Object expectedObject = new Object();
    when(odmMock.getId(expectedObject)).thenReturn(expectedName);
    when(odmMock.getCalculatedId(expectedObject)).thenReturn(null);

    when(dirContextMock.lookup(expectedName)).thenReturn(ctxMock);

    tested.update(expectedObject);

    verify(odmMock, never()).setId(expectedObject, expectedName);
    verify(odmMock).mapToLdapDataEntry(expectedObject, ctxMock);
    verify(dirContextMock).modifyAttributes(expectedName, expectedModificationItems);

    verify(dirContextMock, times(2)).close();
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:27,代码来源:LdapTemplateTest.java

示例5: loadLdif

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private static void loadLdif(DirContext context, Name rootNode, Resource ldifFile) {
       try {
           LdapName baseDn = (LdapName)
                   context.getEnvironment().get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY);

           LdifParser parser = new LdifParser(ldifFile);
           parser.open();
           while (parser.hasMoreRecords()) {
               LdapAttributes record = parser.getRecord();

               LdapName dn = record.getName();

               if(baseDn != null) {
                   dn = LdapUtils.removeFirst(dn, baseDn);
               }

               if(!rootNode.isEmpty()) {
                   dn = LdapUtils.prepend(dn, rootNode);
               }
               context.bind(dn, null, record);
           }
       } catch (Exception e) {
           throw new UncategorizedLdapException("Failed to populate LDIF", e);
       }
   }
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:27,代码来源:LdapTestUtils.java

示例6: testUnbindRecursive

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
@Test
public void testUnbindRecursive() throws Exception {
	expectGetReadWriteContext();

	when(namingEnumerationMock.hasMore()).thenReturn(true, false, false);
	Binding binding = new Binding("cn=Some name", null);
	when(namingEnumerationMock.next()).thenReturn(binding);

	LdapName listDn = LdapUtils.newLdapName(DEFAULT_BASE_STRING);
	when(dirContextMock.listBindings(listDn)).thenReturn(namingEnumerationMock);
	LdapName subListDn = LdapUtils.newLdapName("cn=Some name, o=example.com");
	when(dirContextMock.listBindings(subListDn)).thenReturn(namingEnumerationMock);

	tested.unbind(new CompositeName(DEFAULT_BASE_STRING), true);

       verify(dirContextMock).unbind(subListDn);
       verify(dirContextMock).unbind(listDn);
       verify(namingEnumerationMock, times(2)).close();
       verify(dirContextMock).close();
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:21,代码来源:LdapTemplateTest.java

示例7: testPostProcessBeforeInitializationWithLdapNameAwareNoBasePathSet

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
@Test
public void testPostProcessBeforeInitializationWithLdapNameAwareNoBasePathSet() throws Exception {
    final LdapContextSource expectedContextSource = new LdapContextSource();
    String expectedPath = "dc=example, dc=com";
    expectedContextSource.setBase(expectedPath);

    tested = new BaseLdapPathBeanPostProcessor() {
        BaseLdapPathSource getBaseLdapPathSourceFromApplicationContext() {
            return expectedContextSource;
        }
    };

    Object result = tested.postProcessBeforeInitialization(ldapNameAwareMock, "someName");

    verify(ldapNameAwareMock).setBaseLdapPath(LdapUtils.newLdapName(expectedPath));

    assertThat(result).isSameAs(ldapNameAwareMock);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:19,代码来源:BaseLdapPathBeanPostProcessorTest.java

示例8: doGetContext

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
private DirContext doGetContext(String principal, String credentials, boolean explicitlyDisablePooling) {
    Hashtable<String, Object> env = getAuthenticatedEnv(principal, credentials);
    if(explicitlyDisablePooling) {
        env.remove(SUN_LDAP_POOLING_FLAG);
    }

    DirContext ctx = createContext(env);

    try {
        DirContext processedDirContext = authenticationStrategy.processContextAfterCreation(ctx, principal, credentials);
        return processedDirContext;
    }
    catch (NamingException e) {
        closeContext(ctx);
        throw LdapUtils.convertLdapException(e);
    }
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:18,代码来源:AbstractContextSource.java

示例9: testUpdateWithChangedDn

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
@Test
public void testUpdateWithChangedDn() {
    PersonWithDnAnnotations person = tested.findOne(query()
            .where("cn").is("Some Person3"), PersonWithDnAnnotations.class);

    // This should make the entry move
    person.setCountry("Norway");
    String entryUuid = person.getEntryUuid();
    assertThat(entryUuid).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty();
    tested.update(person);

    person = tested.findByDn(
            LdapUtils.newLdapName("cn=Some Person3, ou=company1, ou=Norway"),
            PersonWithDnAnnotations.class);

    assertThat(person.getCommonName()).isEqualTo("Some Person3");
    assertThat(person.getSurname()).isEqualTo("Person3");
    assertThat(person.getCountry()).isEqualTo("Norway");
    assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
    assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
    assertThat(person.getEntryUuid()).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty();
    assertThat(person.getEntryUuid()).isNotEqualTo(entryUuid);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:24,代码来源:LdapTemplateOdmWithDnAnnotationsITest.java

示例10: testModifyAttributesWithDirContextOperations

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
@Test
public void testModifyAttributesWithDirContextOperations() throws Exception {
	final ModificationItem[] expectedModifications = new ModificationItem[0];

       final LdapName epectedDn = LdapUtils.emptyLdapName();
       when(dirContextOperationsMock.getDn()).thenReturn(epectedDn);
	when(dirContextOperationsMock.isUpdateMode()).thenReturn(true);
	when(dirContextOperationsMock.getModificationItems()).thenReturn(expectedModifications);

	LdapTemplate tested = new LdapTemplate() {
		public void modifyAttributes(Name dn, ModificationItem[] mods) {
			assertThat(dn).isSameAs(epectedDn);
			assertThat(mods).isSameAs(expectedModifications);
		}
	};

	tested.modifyAttributes(dirContextOperationsMock);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:19,代码来源:LdapTemplateTest.java

示例11: testUpdateWithIdCalculated

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
@Test
public void testUpdateWithIdCalculated() throws NamingException {
    when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock);
    when(contextSourceMock.getReadWriteContext()).thenReturn(dirContextMock);
    LdapName expectedName = LdapUtils.newLdapName("ou=someOu");

    ModificationItem[] expectedModificationItems = new ModificationItem[0];
    DirContextOperations ctxMock = mock(DirContextOperations.class);
    when(ctxMock.getDn()).thenReturn(expectedName);
    when(ctxMock.isUpdateMode()).thenReturn(true);
    when(ctxMock.getModificationItems()).thenReturn(expectedModificationItems);

    Object expectedObject = new Object();
    when(odmMock.getId(expectedObject)).thenReturn(null);
    when(odmMock.getCalculatedId(expectedObject)).thenReturn(expectedName);

    when(dirContextMock.lookup(expectedName)).thenReturn(ctxMock);

    tested.update(expectedObject);

    verify(odmMock).setId(expectedObject, expectedName);
    verify(odmMock).mapToLdapDataEntry(expectedObject, ctxMock);
    verify(dirContextMock).modifyAttributes(expectedName, expectedModificationItems);

    verify(dirContextMock, times(2)).close();
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:27,代码来源:LdapTemplateTest.java

示例12: testRemoveOneOfSeveralDnAttributeSyntacticallyEqual

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
@Test
public void testRemoveOneOfSeveralDnAttributeSyntacticallyEqual() throws NamingException {
    BasicAttributes attributes = new BasicAttributes();
    BasicAttribute attribute = new BasicAttribute("uniqueMember", "cn=john doe,OU=company");
    attribute.add("cn=jane doe, ou=company");
    attributes.put(attribute);

    DirContextAdapter tested = new DirContextAdapter(attributes, LdapUtils.newLdapName("cn=administrators, ou=groups"));
    tested.setUpdateMode(true);

    tested.removeAttributeValue("uniqueMember", LdapUtils.newLdapName("cn=john doe, ou=company"));
    ModificationItem[] modificationItems = tested.getModificationItems();
    assertThat(modificationItems.length).isEqualTo(1);

    ModificationItem modificationItem = modificationItems[0];
    assertThat(modificationItem.getModificationOp()).isEqualTo(DirContext.REMOVE_ATTRIBUTE);
    assertThat(modificationItem.getAttribute().getID()).isEqualTo("uniqueMember");
    assertThat(modificationItem.getAttribute().get()).isEqualTo("cn=john doe,OU=company");
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:20,代码来源:DirContextAdapterTest.java

示例13: testRecordOperation_Name

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
@Test
public void testRecordOperation_Name() {
    BindOperationRecorder tested = new BindOperationRecorder(
            ldapOperationsMock);
    LdapName expectedDn = LdapUtils.newLdapName("cn=John Doe");

    Object expectedObject = new Object();
    BasicAttributes expectedAttributes = new BasicAttributes();
    // Perform test.
    CompensatingTransactionOperationExecutor operation = tested
            .recordOperation(new Object[] { expectedDn, expectedObject,
                    expectedAttributes });

    assertThat(operation instanceof BindOperationExecutor).isTrue();
    BindOperationExecutor rollbackOperation = (BindOperationExecutor) operation;
    assertThat(rollbackOperation.getDn()).isSameAs(expectedDn);
    assertThat(rollbackOperation.getLdapOperations()).isSameAs(ldapOperationsMock);
    assertThat(rollbackOperation.getOriginalObject()).isSameAs(expectedObject);
    assertSame(expectedAttributes, rollbackOperation
            .getOriginalAttributes());
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:22,代码来源:BindOperationRecorderTest.java

示例14: testEqualDistinguishedNameValue

import org.springframework.ldap.support.LdapUtils; //导入依赖的package包/类
@Test
public void testEqualDistinguishedNameValue() throws NamingException {
    // The names here are syntactically equal, but differ in exact string representation
    String expectedName1 = "cn=John Doe, OU=People";
    String expectedName2 = "cn=John Doe,ou=People";

    NameAwareAttribute attr1 = new NameAwareAttribute("someAttribute");
    attr1.add(LdapUtils.newLdapName(expectedName1));
    NameAwareAttribute attr2 = new NameAwareAttribute("someAttribute");
    attr2.add(LdapUtils.newLdapName(expectedName2));

    assertThat(attr2).isEqualTo(attr1);
    assertThat(attr2.hashCode()).isEqualTo(attr1.hashCode());
    assertThat(attr1.get()).isEqualTo(expectedName1);
    assertThat(attr2.get()).isEqualTo(expectedName2);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:17,代码来源:NameAwareAttributeTest.java

示例15: verifyAuthenticate

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


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