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


Java AbstractContextMapper类代码示例

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


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

示例1: validateDnExist

import org.springframework.ldap.core.support.AbstractContextMapper; //导入依赖的package包/类
private boolean validateDnExist(LdapTemplateContextSource ldapTemplateContextSource, String fullDn){
    try {
        String dn = fullDn.replace("," + ldapTemplateContextSource.getLdapContextSource().getBaseLdapPathAsString(), "");
        Object result = ldapTemplateContextSource.getLdapTemplate().lookup(dn, new AbstractContextMapper<Object>() {
            @Override
            protected Object doMapFromContext(DirContextOperations ctx) {
                Attributes group = ctx.getAttributes();
                return group;
            }
        });
        return result != null;
    }catch (Exception e){
        logger.warn(String.format("validateDnExist[%s] fail", fullDn), e);
        return false;
    }
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:17,代码来源:LdapManagerImpl.java

示例2: getLdapTree

import org.springframework.ldap.core.support.AbstractContextMapper; //导入依赖的package包/类
private LdapTree getLdapTree(final DirContextOperations rootContext) {
	final LdapTree ldapTree = new LdapTree(rootContext);
	ldapTemplate.listBindings(rootContext.getDn(),
			new AbstractContextMapper<Object>() {
				@Override
				protected Object doMapFromContext(DirContextOperations ctx) {
					Name dn = ctx.getDn();
					dn = LdapUtils.prepend(dn, rootContext.getDn());
					ldapTree.addSubTree(getLdapTree(ldapTemplate
							.lookupContext(dn)));
					return null;
				}
			});

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

示例3: getToken

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

示例4: getToken

import org.springframework.ldap.core.support.AbstractContextMapper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void getToken() {
	final LdapTemplate mock = Mockito.mock(LdapTemplate.class);
	final DirContextOperations dirCtx = Mockito.mock(DirContextOperations.class);
	Mockito.when(mock.search((String) ArgumentMatchers.any(), ArgumentMatchers.any(), (AbstractContextMapper<String>) ArgumentMatchers.any()))
			.thenAnswer(i -> {
				((AbstractContextMapper<DirContextOperations>) i.getArgument(2)).mapFromContext(dirCtx);
				return Collections.singletonList("token");
			});
	repository.setTemplate(mock);
	Assert.assertEquals("token", repository.getToken("user1"));
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:14,代码来源:UserLdapRepositoryTest.java

示例5: update

import org.springframework.ldap.core.support.AbstractContextMapper; //导入依赖的package包/类
private void update(LdapTemplate ldapTemplate, LdapAccountRefVO ref){
    String uid = ref.getLdapUid();

    AndFilter filter = new AndFilter();
    filter.and(new EqualsFilter("uid", ref.getLdapUid()));

    List<Object> result = ldapTemplate.search("", filter.toString(), new AbstractContextMapper<Object>() {
        @Override
        protected Object doMapFromContext(DirContextOperations ctx) {
            return ctx.getNameInNamespace();
        }
    });

    if(result.size() == 0){
        logger.error(String.format("Can not find ldapUid[%s] dn", uid));
        return;
    }

    if(result.size() > 1){
        logger.error(String.format("ldapUid[%s] More than one dn result", uid));
        return;
    }

    String dn = result.get(0).toString();
    ref.setLdapUid(dn);
    dbf.update(ref);
    logger.info(String.format("update ldapUid[%s] to ldapDn[%s] success", uid, dn));
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:29,代码来源:LdapUpgradeExtension.java

示例6: getFullUserDn

import org.springframework.ldap.core.support.AbstractContextMapper; //导入依赖的package包/类
private String getFullUserDn(LdapTemplate ldapTemplate, String filter) {
    String dn;
    try {
        List<Object> result = ldapTemplate.search("", filter, new AbstractContextMapper<Object>() {
            @Override
            protected Object doMapFromContext(DirContextOperations ctx) {
                return ctx.getNameInNamespace();
            }
        });
        if (result.size() == 1) {
            dn = result.get(0).toString();
        } else if (result.size() > 1) {
            throw new OperationFailureException(errf.instantiateErrorCode(
                    LdapErrors.UNABLE_TO_GET_SPECIFIED_LDAP_UID, "More than one ldap search result"));
        } else {
            return "";
        }
        logger.info(String.format("getDn success filter:%s, dn:%s", filter, dn));
    } catch (NamingException e) {
        LdapServerVO ldapServerVO = getLdapServer();
        String errString = String.format(
                "You'd better check the ldap server[url:%s, baseDN:%s, encryption:%s, username:%s, password:******]" +
                        " configuration and test connection first.getDn error filter:%s",
                ldapServerVO.getUrl(), ldapServerVO.getBase(),
                ldapServerVO.getEncryption(), ldapServerVO.getUsername(), filter);
        throw new OperationFailureException(errf.instantiateErrorCode(
                LdapErrors.UNABLE_TO_GET_SPECIFIED_LDAP_UID, errString));
    }
    return dn;
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:31,代码来源:LdapManagerImpl.java

示例7: findLdapDnMemberOfList

import org.springframework.ldap.core.support.AbstractContextMapper; //导入依赖的package包/类
public void findLdapDnMemberOfList(LdapTemplate ldapTemplate, String ldapDn, List<String> resultDnList, List<String> dnIgnoreList){
    if(dnIgnoreList.contains(ldapDn)){
        return;
    }

    AndFilter filter = new AndFilter();
    filter.and(new EqualsFilter(LdapUtil.getMemberKey(), ldapDn));

    List<Object> groupList = ldapTemplate.search("", filter.toString(), new AbstractContextMapper<Object>() {
        @Override
        protected Object doMapFromContext(DirContextOperations ctx) {
            return ctx.getNameInNamespace();
        }
    });

    if(groupList.isEmpty()){
        dnIgnoreList.add(ldapDn);
        return;
    }

    for(Object groupObj : groupList){
        if(groupObj == null || !(groupObj instanceof String)){
            continue;
        }

        String groupDn = (String)groupObj;

        if(resultDnList.contains(groupDn)){
            continue;
        }

        resultDnList.add(groupDn);
        findLdapDnMemberOfList(ldapTemplate, groupDn, resultDnList, dnIgnoreList);
    }
}
 
开发者ID:zstackio,项目名称:zstack,代码行数:36,代码来源:LdapManagerImpl.java

示例8: testSearchForObjectWithMultipleHits

import org.springframework.ldap.core.support.AbstractContextMapper; //导入依赖的package包/类
@Test(expected = IncorrectResultSizeDataAccessException.class)
public void testSearchForObjectWithMultipleHits() {
	tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=*))", new AbstractContextMapper() {
		@Override
		protected Object doMapFromContext(DirContextOperations ctx) {
			return ctx;
		}
	});
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:10,代码来源:LdapTemplateSearchResultITest.java

示例9: testSearchForObjectNoHits

import org.springframework.ldap.core.support.AbstractContextMapper; //导入依赖的package包/类
@Test(expected = EmptyResultDataAccessException.class)
public void testSearchForObjectNoHits() {
	tested.searchForObject(BASE_STRING, "(&(objectclass=person)(sn=Person does not exist))", new AbstractContextMapper() {
		@Override
		protected Object doMapFromContext(DirContextOperations ctx) {
			return ctx;
		}
	});
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:10,代码来源:LdapTemplateSearchResultITest.java

示例10: testSearchForDnSpoiledByCompositeName

import org.springframework.ldap.core.support.AbstractContextMapper; //导入依赖的package包/类
/**
 * Test for LDAP-109, LDAP-50. When an entry has a distinguished name
 * including a backslach ('\') the Name supplied to DefaultDirObjectFactory
 * will be invalid.
 * <p>
 * E.g. the distinguished name "cn=Some\\Person6,ou=company1,ou=Sweden"
 * (indicating that the cn value is 'Some\Person'), will be represented by a
 * <code>CompositeName</code> with the string representation
 * "cn=Some\\\Person6,ou=company1,ou=Sweden", which is in fact an invalid DN.
 * This will be supplied to <code>DistinguishedName</code> for parsing,
 * causing it to fail. This test makes sure that Spring LDAP properly works
 * around this bug.
 * </p>
 * <p>
 * What happens under the covers is (in the Java LDAP Provider code):
 * 
 * <pre>
 * LdapName ldapname = new LdapName(&quot;cn=Some\\\\Person6,ou=company1,ou=Sweden&quot;);
 * CompositeName compositeName = new CompositeName();
 * compositeName.add(ldapname.get(ldapname.size() - 1)); // for some odd reason
 * </pre>
 * <code>CompositeName#add()</code> cannot handle this and the result is
 * the spoiled DN.
 * </p>
 * @throws InvalidNameException
 */
@Test
   @Category(NoAdTest.class)
public void testSearchForDnSpoiledByCompositeName() throws InvalidNameException {
	List result = tested.search("", "(sn=Person6)", new AbstractContextMapper() {
		@Override
		protected Object doMapFromContext(DirContextOperations ctx) {
			LdapName dn = (LdapName) ctx.getDn();
               Rdn rdn = LdapUtils.getRdn(dn, "cn");
               assertThat(dn.toString()).isEqualTo("cn=Some\\\\Person6,ou=company1,ou=Sweden");
			assertThat(rdn.getValue()).isEqualTo("Some\\Person6");
			return new Object();
		}
	});

	assertThat(result).hasSize(1);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:43,代码来源:InvalidBackslashITest.java


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