當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。