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


Java LdapName类代码示例

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


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

示例1: removeUserSchema

import javax.naming.ldap.LdapName; //导入依赖的package包/类
/**
 * Mock a managed LDAP schema violation
 */
@Test
public void removeUserSchema() {
	thrown.expect(ValidationJsonException.class);
	thrown.expect(MatcherUtil.validationMatcher("groups", "last-member-of-group"));
	final GroupLdapRepository groupRepository = new GroupLdapRepository() {
		@Override
		public GroupOrg findById(final String name) {
			// The group has only the user user we want to remove
			return new GroupOrg("dc=" + name, name, Collections.singleton("flast1"));
		}

	};
	groupRepository.setLdapCacheRepository(Mockito.mock(LdapCacheRepository.class));

	final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
	groupRepository.setTemplate(ldapTemplate);
	Mockito.doThrow(new org.springframework.ldap.SchemaViolationException(new SchemaViolationException("any"))).when(ldapTemplate)
			.modifyAttributes(ArgumentMatchers.any(LdapName.class), ArgumentMatchers.any());
	removeUser(groupRepository);
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:24,代码来源:GroupLdapRepositoryTest.java

示例2: getCommonName

import javax.naming.ldap.LdapName; //导入依赖的package包/类
public static String getCommonName(X509Certificate cert)
        throws InvalidNameException {
    // use LDAP API to parse the certifiate Subject :)
    // see http://stackoverflow.com/a/7634755/972463
    LdapName ldapDN
            = new LdapName(cert.getSubjectX500Principal().getName());
    String cn = "";
    for (Rdn rdn : ldapDN.getRdns()) {
        if (rdn.getType().equals("CN")) {
            cn = rdn.getValue().toString();
        }
    }
    return cn;
}
 
开发者ID:spyhunter99,项目名称:installcert,代码行数:15,代码来源:InstallCert.java

示例3: removeUserSync

import javax.naming.ldap.LdapName; //导入依赖的package包/类
/**
 * Mock a managed LDAP desynchronization
 */
@Test
public void removeUserSync() {
	final GroupLdapRepository groupRepository = new GroupLdapRepository() {
		@Override
		public GroupOrg findById(final String name) {
			// The group has only the user user we want to remove
			return new GroupOrg("dc=" + name, name, Collections.singleton("flast1"));
		}

	};
	groupRepository.setLdapCacheRepository(Mockito.mock(LdapCacheRepository.class));
	final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
	groupRepository.setTemplate(ldapTemplate);
	Mockito.doThrow(new org.springframework.ldap.AttributeInUseException(new AttributeInUseException("any"))).when(ldapTemplate)
			.modifyAttributes(ArgumentMatchers.any(LdapName.class), ArgumentMatchers.any());
	removeUser(groupRepository);
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:21,代码来源:GroupLdapRepositoryTest.java

示例4: testAddAllIntName

import javax.naming.ldap.LdapName; //导入依赖的package包/类
/**
 * Test for DIRSERVER-191
 */
@Test
public void testAddAllIntName() throws LdapException, InvalidNameException
{
    LdapName jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
    Dn aName = new Dn( "cn=four,cn=three,cn=two,cn=one" );

    assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
    assertNotSame( aName, aName.add( new Dn( "cn=zero,cn=zero.5" ) ) );
    assertNotSame( jName.toString(), aName.toString() );

    assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
    assertNotSame( aName, aName.add( new Dn( "cn=zero,cn=zero.5" ) ) );
    assertNotSame( jName.toString(), aName.toString() );

    assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
    assertNotSame( aName, aName.add( new Dn( "cn=zero,cn=zero.5" ) ) );
    assertNotSame( jName.toString(), aName.toString() );
}
 
开发者ID:apache,项目名称:directory-ldap-api,代码行数:22,代码来源:DnTest.java

示例5: ldapInjectionSunApi

import javax.naming.ldap.LdapName; //导入依赖的package包/类
public void ldapInjectionSunApi(String input) throws NamingException {
    //Stub instances
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    props.put(Context.PROVIDER_URL, "ldap://ldap.example.com");
    props.put(Context.REFERRAL, "ignore");

    SearchControls ctrls = new SearchControls();
    ctrls.setReturningAttributes(new String[]{"givenName", "sn"});
    ctrls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    //Two context instances mostly usable with sun specific API
    LdapCtx            context5 = null;
    EventDirContext    context6 = null; //LdapCtx is the only known class to implements to this interface

    NamingEnumeration<SearchResult> answers;
    answers = context5.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", ctrls);
    answers = context5.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", new Object[0], ctrls);
    answers = context5.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", ctrls);
    answers = context5.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", new Object[0], ctrls);

    answers = context6.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", ctrls);
    answers = context6.search(new LdapName("dc=People,dc=example,dc=com"), "(uid=" + input + ")", new Object[0], ctrls);
    answers = context6.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", ctrls);
    answers = context6.search("dc=People,dc=example,dc=com", "(uid=" + input + ")", new Object[0], ctrls);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:27,代码来源:JndiLdapAdditionalSignature.java

示例6: constructAuthenticationIdentity

import javax.naming.ldap.LdapName; //导入依赖的package包/类
private AuthenticationIdentity constructAuthenticationIdentity(X509Certificate certificate) {
  AuthenticationIdentity identity = new AuthenticationIdentity();
  try {
    LdapName ln = new LdapName(certificate.getSubjectDN().getName());
    for(Rdn rdn : ln.getRdns()) {
      if(rdn.getType().equalsIgnoreCase("GIVENNAME")) {
        identity.setGivenName(rdn.getValue().toString());
      } else if(rdn.getType().equalsIgnoreCase("SURNAME")) {
        identity.setSurName(rdn.getValue().toString());
      } else if(rdn.getType().equalsIgnoreCase("SERIALNUMBER")) {
        identity.setIdentityCode(rdn.getValue().toString().split("-")[1]);
      } else if(rdn.getType().equalsIgnoreCase("C")) {
        identity.setCountry(rdn.getValue().toString());
      }

    }
    return identity;
  } catch (InvalidNameException e) {
    logger.error("Error getting authentication identity from the certificate", e);
    throw new TechnicalErrorException("Error getting authentication identity from the certificate", e);
  }
}
 
开发者ID:SK-EID,项目名称:smart-id-java-client,代码行数:23,代码来源:AuthenticationResponseValidator.java

示例7: compareDNs

import javax.naming.ldap.LdapName; //导入依赖的package包/类
/**
 * Returns true if the two provided DNs are equivalent, regardless of the order of the elements. Returns false if one or both are invalid DNs.
 *
 * Example:
 *
 * CN=test1, O=testOrg, C=US compared to CN=test1, O=testOrg, C=US -> true
 * CN=test1, O=testOrg, C=US compared to O=testOrg, CN=test1, C=US -> true
 * CN=test1, O=testOrg, C=US compared to CN=test2, O=testOrg, C=US -> false
 * CN=test1, O=testOrg, C=US compared to O=testOrg, CN=test2, C=US -> false
 * CN=test1, O=testOrg, C=US compared to                           -> false
 *                           compared to                           -> true
 *
 * @param dn1 the first DN to compare
 * @param dn2 the second DN to compare
 * @return true if the DNs are equivalent, false otherwise
 */
public static boolean compareDNs(String dn1, String dn2) {
    if (dn1 == null) {
        dn1 = "";
    }

    if (dn2 == null) {
        dn2 = "";
    }

    if (StringUtils.isEmpty(dn1) || StringUtils.isEmpty(dn2)) {
        return dn1.equals(dn2);
    }
    try {
        List<Rdn> rdn1 = new LdapName(dn1).getRdns();
        List<Rdn> rdn2 = new LdapName(dn2).getRdns();

        return rdn1.size() == rdn2.size() && rdn1.containsAll(rdn2);
    } catch (InvalidNameException e) {
        logger.warn("Cannot compare DNs: {} and {} because one or both is not a valid DN", dn1, dn2);
        return false;
    }
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:39,代码来源:CertificateUtils.java

示例8: getAttributeFromDN

import javax.naming.ldap.LdapName; //导入依赖的package包/类
/**
 * Extracts from DN a given attribute.
 * @param dn
 *         The entire DN
 * @param attribute
 *         The attribute to extract
 * @return the attribute value or null if not found an attribute with the given dn.
 */
public static String getAttributeFromDN(String dn, String attribute) {
    try {
        LdapName subjectDn = new LdapName(dn);

        for (Rdn rdn : subjectDn.getRdns()) {
            if (rdn.getType().equals(attribute)) {
                return rdn.getValue().toString();
            }
        }
    } catch (InvalidNameException e) {
        throw new IllegalArgumentException(e);
    }

    return null;
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:24,代码来源:CertificateUtil.java

示例9: buildGroupMapper

import javax.naming.ldap.LdapName; //导入依赖的package包/类
protected NodeMapper buildGroupMapper(final boolean disjoint, final LdapName groupDistinguishedNamePrefix,
        final LdapName userDistinguishedNamePrefix)
{
    return (searchResult) -> {
        final UidNodeDescription nodeDescription = this.mapToNode(searchResult, this.groupIdAttributeName, this.groupAttributeMapping,
                this.groupAttributeDefaults);

        final String groupName = AuthorityType.GROUP.getPrefixString() + nodeDescription.getId();
        nodeDescription.getProperties().put(ContentModel.PROP_AUTHORITY_NAME, groupName);

        final Collection<String> groupChildren = this.lookupGroupChildren(searchResult, groupName, disjoint,
                groupDistinguishedNamePrefix, userDistinguishedNamePrefix);
        nodeDescription.getChildAssociations().addAll(groupChildren);

        return nodeDescription;
    };
}
 
开发者ID:Acosix,项目名称:alfresco-mt-support,代码行数:18,代码来源:EnhancedLDAPUserRegistry.java

示例10: testComposeDn

import javax.naming.ldap.LdapName; //导入依赖的package包/类
@Test
public void testComposeDn() throws Exception {
	final String TEST_NAME = "testComposeDn";
	TestUtil.displayTestTile(TEST_NAME);
	BasicExpressionFunctions basic = createBasicFunctions();
	
	assertEquals("cn=foo,o=bar", basic.composeDn("cn","foo","o","bar"));
	assertEquals("cn=foo,o=bar", basic.composeDn("cn",PrismTestUtil.createPolyString("foo"),"o","bar"));
	assertEquals("cn=foo,o=bar", basic.composeDn("cn",PrismTestUtil.createPolyStringType("foo"),"o","bar"));
	assertEquals("cn=foo,o=bar", basic.composeDn("cn","foo",new Rdn("o","bar")));
	assertEquals("cn=foo,ou=baz,o=bar", basic.composeDn(new Rdn("cn","foo"),"ou","baz",new Rdn("o","bar")));
	assertEquals("cn=foo,ou=baz,o=bar", basic.composeDn(new Rdn("cn","foo"),"ou","baz","o","bar"));
	assertEquals("cn=foo,ou=baz,o=bar", basic.composeDn(new Rdn("cn","foo"),new LdapName("ou=baz,o=bar")));
	assertEquals("cn=foo,ou=baz,o=bar", basic.composeDn("cn","foo",new LdapName("ou=baz,o=bar")));
	assertEquals("cn=foo\\,foo,ou=baz,o=bar", basic.composeDn("cn","foo,foo",new LdapName("ou=baz,o=bar")));
	assertEquals("cn=foo\\=foo,ou=baz,o=bar", basic.composeDn("cn","foo=foo",new LdapName("ou=baz,o=bar")));
	assertEquals(null, basic.composeDn(null));
	assertEquals(null, basic.composeDn());
	assertEquals(null, basic.composeDn(""));
	assertEquals(null, basic.composeDn("   "));
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:22,代码来源:TestExpressionFunctions.java

示例11: distributionGroupOU

import javax.naming.ldap.LdapName; //导入依赖的package包/类
private String distributionGroupOU() throws InvalidNameException {
    LdapName container = new LdapName(getContainer());
    List<String> ous = new ArrayList<>();
    List<String> dcs = new ArrayList<>();
    String retval = "";
    for (Rdn rdn : container.getRdns()) {
        if (rdn.getType().equalsIgnoreCase("OU")) {
            ous.add(rdn.getValue().toString());
        } else if (rdn.getType().equalsIgnoreCase("DC")) {
            dcs.add(rdn.getValue().toString());
        }
    }
    for (int i = dcs.size()-1; i >= 0; i--) {
        if (!retval.isEmpty()) {
            retval += ".";
        }
        retval += dcs.get(i);
    }
    for (int i = 0; i < ous.size(); i++) {
        retval += "/" + ous.get(i);
    }
    return retval;
}
 
开发者ID:Pardus-Engerek,项目名称:engerek,代码行数:24,代码来源:TestExchangeConnectorLow.java

示例12: invokeRemoteEJBHandlerName

import javax.naming.ldap.LdapName; //导入依赖的package包/类
@Test
public void invokeRemoteEJBHandlerName() throws Throwable {
   log.debug("start invokeRemoteEJBHandlerName()");
   TEntity entity = new TEntity("ja", 88, "mys");
   Object[] params = new Object[] { "kll", 15, 34, "wossel".getBytes(), entity, new Long(900L) };

   URL url = Thread.currentThread().getContextClassLoader().getResource("jndi_.properties");
   log.debug("url=" + url);
   Properties properties = new Properties();
   properties.load(url.openStream());

   Method m = RemoteEJBImpl.class.getMethod("testInvoke", String.class, int.class, int.class, byte[].class,
         TEntity.class, Long.class);
   Name name = new LdapName("CN=Steve Kille,O=Isode Limited,C=GB");

   Constructor<RemoteEjbInvocationHandler> constr = RemoteEjbInvocationHandler.class
         .getDeclaredConstructor(Object.class, Hashtable.class, Name.class);
   constr.setAccessible(true);
   RemoteEjbInvocationHandler handler = constr.newInstance(new RemoteEJBImpl(), properties, name);

   List<Object> result = (List<Object>) handler.invoke(new Object(), m, params);
   assertNotNull(result);
   assertEquals(6, result.size());
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:25,代码来源:RemoteEjbIT.java

示例13: populateUserAndRolesFromCert

import javax.naming.ldap.LdapName; //导入依赖的package包/类
private boolean populateUserAndRolesFromCert(X509Certificate certificate) throws InvalidNameException {
    LdapName ldapName = new LdapName(certificate.getSubjectDN().getName());

    // Find the first CN that maps to a valid user as supplied in the config
    Optional<String> validCN = ldapName.getRdns().stream()
        .filter(rdn -> rdn.getType().equalsIgnoreCase("CN"))
        .map(rdn -> String.valueOf(rdn.getValue()))
        .filter(n -> validCertUsers.containsKey(n)).findFirst();

    if(validCN.isPresent()) {
        String name = validCN.get();
        user = name; roles.addAll(validCertUsers.get(name));
        return true;
    } else {
        return false;
    }
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:18,代码来源:SaslDelegatingLogin.java

示例14: getSignerCn

import javax.naming.ldap.LdapName; //导入依赖的package包/类
/**
 * Convenience method. Equivalent to calling getSignerCert and
 * then parsing out the CN from the certificate's Subject field.
 * @return Signer CN or null if there's a problem.
 */
@Override
public String getSignerCn() {
    try {
        X509Certificate signerCert = this.getSignerCert();
        String dn = signerCert.getSubjectX500Principal().getName();

        String cn = null;
        try {
            LdapName ldapDn = new LdapName(dn);
            List<Rdn> rdns = ldapDn.getRdns();
            for(Rdn r : rdns) {
                if("CN".equals(r.getType())) {
                    cn = r.getValue().toString();
                }
            }
        } catch(InvalidNameException e) {
            log.warn("Invalid name", e);
        }

        return cn;
    } catch(Throwable t) {
        log.error("Failed to get signer CN: " + t.getMessage());
        return null;
    }
}
 
开发者ID:laverca,项目名称:laverca,代码行数:31,代码来源:CmsSignature.java

示例15: parseSubjectName

import javax.naming.ldap.LdapName; //导入依赖的package包/类
/**
 * Parse the given RND type from the given certificate's subject
 * @param cert Certificate
 * @param rdnType RND type
 * @return parsed value as String
 */
public static String parseSubjectName(final X509Certificate cert, final String rdnType) {
    String dn = cert.getSubjectX500Principal().getName();

    String name = null;
    try {
        LdapName ldapDn = new LdapName(dn);
        List<Rdn> rdns = ldapDn.getRdns();
        for(Rdn r : rdns) {
            if(rdnType.equals(r.getType())) {
                name = r.getValue().toString();
            }
        }
    } catch(InvalidNameException e) {
        log.error(e);
    }
    
    return name;
}
 
开发者ID:laverca,项目名称:laverca,代码行数:25,代码来源:X509Util.java


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