Search in sources :

Example 21 with LdapName

use of javax.naming.ldap.LdapName in project portfolio by buchen.

the class AboutDialog method addSignerInfo.

@SuppressWarnings("nls")
private void addSignerInfo(StringBuilder builder, Bundle b) {
    Map<X509Certificate, List<X509Certificate>> certificates = b.getSignerCertificates(Bundle.SIGNERS_ALL);
    if (certificates.isEmpty())
        return;
    builder.append(" [signed by ");
    boolean isFirstCertificate = true;
    for (X509Certificate cert : certificates.keySet()) {
        try {
            LdapName ldapDN = new LdapName(cert.getSubjectDN().getName());
            for (Rdn rdn : ldapDN.getRdns()) {
                if ("CN".equals(rdn.getType())) {
                    if (!isFirstCertificate)
                        builder.append(", ");
                    builder.append(rdn.getValue());
                    isFirstCertificate = false;
                }
            }
        } catch (InvalidNameException ignore) {
        // ignore
        }
    }
    builder.append("]");
}
Also used : InvalidNameException(javax.naming.InvalidNameException) ArrayList(java.util.ArrayList) List(java.util.List) Rdn(javax.naming.ldap.Rdn) X509Certificate(java.security.cert.X509Certificate) LdapName(javax.naming.ldap.LdapName)

Example 22 with LdapName

use of javax.naming.ldap.LdapName in project certmgr by hdecarne.

the class DNEditorController method validateAndGetDN.

private X500Principal validateAndGetDN() throws ValidationException {
    LdapName ldapDN = new LdapName(this.ctlRdnEntries.getItems());
    X500Principal x500DN;
    try {
        x500DN = X500Names.fromString(ldapDN.toString());
    } catch (IllegalArgumentException e) {
        throw new ValidationException(DNEditorI18N.formatSTR_MESSAGE_INVALID_DN(e.getLocalizedMessage()), e);
    }
    return x500DN;
}
Also used : ValidationException(de.carne.jfx.util.validation.ValidationException) X500Principal(javax.security.auth.x500.X500Principal) LdapName(javax.naming.ldap.LdapName)

Example 23 with LdapName

use of javax.naming.ldap.LdapName in project jbosstools-openshift by jbosstools.

the class HumanReadableX509Certificate method getAllRDN.

private String getAllRDN(X500Principal principal) {
    StringBuilder builder = new StringBuilder();
    try {
        LdapName ldapDN = new LdapName(principal.getName());
        int i = 0;
        for (Rdn rdn : ldapDN.getRdns()) {
            String type = getTypeFullName(rdn.getType());
            if (!StringUtils.isEmpty(type)) {
                if (i++ > 0) {
                    builder.append(StringUtils.getLineSeparator());
                }
                builder.append(type).append(SEPARATOR_LABEL_VALUE).append(StringUtils.toStringOrNull(rdn.getValue()));
            }
        }
        return builder.toString();
    } catch (InvalidNameException e) {
        return builder.toString();
    }
}
Also used : InvalidNameException(javax.naming.InvalidNameException) Rdn(javax.naming.ldap.Rdn) LdapName(javax.naming.ldap.LdapName)

Example 24 with LdapName

use of javax.naming.ldap.LdapName in project activemq-artemis by apache.

the class LegacyLDAPSecuritySettingPlugin method processSearchResult.

private void processSearchResult(Map<String, Set<Role>> securityRoles, SearchResult searchResult) throws NamingException {
    Attributes attrs = searchResult.getAttributes();
    if (attrs == null || attrs.size() == 0) {
        return;
    }
    LdapName searchResultLdapName = new LdapName(searchResult.getName());
    logger.debug("LDAP search result : " + searchResultLdapName);
    String permissionType = null;
    String destination = null;
    String destinationType = "unknown";
    for (Rdn rdn : searchResultLdapName.getRdns()) {
        if (rdn.getType().equals("cn")) {
            logger.debug("\tPermission type: " + rdn.getValue());
            permissionType = rdn.getValue().toString();
        }
        if (rdn.getType().equals("uid")) {
            logger.debug("\tDestination name: " + rdn.getValue());
            destination = rdn.getValue().toString();
        }
        if (rdn.getType().equals("ou")) {
            String rawDestinationType = rdn.getValue().toString();
            if (rawDestinationType.toLowerCase().contains("queue")) {
                destinationType = "queue";
            } else if (rawDestinationType.toLowerCase().contains("topic")) {
                destinationType = "topic";
            }
            logger.debug("\tDestination type: " + destinationType);
        }
    }
    logger.debug("\tAttributes: " + attrs);
    Attribute attr = attrs.get(roleAttribute);
    NamingEnumeration<?> e = attr.getAll();
    Set<Role> roles = securityRoles.get(destination);
    boolean exists = false;
    if (roles == null) {
        roles = new HashSet<>();
    } else {
        exists = true;
    }
    while (e.hasMore()) {
        String value = (String) e.next();
        LdapName ldapname = new LdapName(value);
        Rdn rdn = ldapname.getRdn(ldapname.size() - 1);
        String roleName = rdn.getValue().toString();
        logger.debug("\tRole name: " + roleName);
        Role role = new Role(roleName, // send
        permissionType.equalsIgnoreCase(writePermissionValue), // consume
        permissionType.equalsIgnoreCase(readPermissionValue), // createDurableQueue
        permissionType.equalsIgnoreCase(adminPermissionValue), // deleteDurableQueue
        permissionType.equalsIgnoreCase(adminPermissionValue), // createNonDurableQueue
        permissionType.equalsIgnoreCase(adminPermissionValue), // deleteNonDurableQueue
        permissionType.equalsIgnoreCase(adminPermissionValue), // manage - there is no permission from ActiveMQ 5.x that corresponds to this
        false, // browse
        permissionType.equalsIgnoreCase(readPermissionValue), // createAddress
        permissionType.equalsIgnoreCase(adminPermissionValue), // deleteAddress
        permissionType.equalsIgnoreCase(adminPermissionValue));
        roles.add(role);
    }
    if (!exists) {
        securityRoles.put(destination, roles);
    }
}
Also used : Role(org.apache.activemq.artemis.core.security.Role) Attribute(javax.naming.directory.Attribute) Attributes(javax.naming.directory.Attributes) Rdn(javax.naming.ldap.Rdn) LdapName(javax.naming.ldap.LdapName)

Example 25 with LdapName

use of javax.naming.ldap.LdapName in project spring-security by spring-projects.

the class FilterBasedLdapUserSearchWithSpacesTests method searchForUserWhenSpacesInBaseDnThenSuccess.

// gh-9742
@Test
public void searchForUserWhenSpacesInBaseDnThenSuccess() throws Exception {
    FilterBasedLdapUserSearch locator = new FilterBasedLdapUserSearch("ou=space cadets", "(uid={0})", this.contextSource);
    locator.setSearchSubtree(false);
    locator.setSearchTimeLimit(0);
    locator.setDerefLinkFlag(false);
    DirContextOperations bob = locator.searchForUser("space cadet");
    assertThat(bob.getStringAttribute("uid")).isEqualTo("space cadet");
    assertThat(bob.getDn()).isEqualTo(new LdapName("uid=space cadet,ou=space cadets"));
}
Also used : DirContextOperations(org.springframework.ldap.core.DirContextOperations) LdapName(javax.naming.ldap.LdapName) Test(org.junit.jupiter.api.Test)

Aggregations

LdapName (javax.naming.ldap.LdapName)86 Rdn (javax.naming.ldap.Rdn)43 InvalidNameException (javax.naming.InvalidNameException)27 Attribute (javax.naming.directory.Attribute)18 NamingException (javax.naming.NamingException)16 Attributes (javax.naming.directory.Attributes)12 SearchResult (javax.naming.directory.SearchResult)10 Test (org.junit.Test)10 IOException (java.io.IOException)6 X509Certificate (java.security.cert.X509Certificate)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 Test (org.junit.jupiter.api.Test)5 HashSet (java.util.HashSet)4 List (java.util.List)4 NoSuchElementException (java.util.NoSuchElementException)4 TreeSet (java.util.TreeSet)4 SearchControls (javax.naming.directory.SearchControls)4 SSLException (javax.net.ssl.SSLException)4