Search in sources :

Example 36 with InvalidNameException

use of javax.naming.InvalidNameException in project qpid-broker-j by apache.

the class NonJavaKeyStoreImpl method getSubjectName.

@Override
public String getSubjectName() {
    if (_certificate != null) {
        try {
            String dn = _certificate.getSubjectX500Principal().getName();
            LdapName ldapDN = new LdapName(dn);
            String name = dn;
            for (Rdn rdn : ldapDN.getRdns()) {
                if (rdn.getType().equalsIgnoreCase("CN")) {
                    name = String.valueOf(rdn.getValue());
                    break;
                }
            }
            return name;
        } catch (InvalidNameException e) {
            LOGGER.error("Error getting subject name from certificate");
            return null;
        }
    } else {
        return null;
    }
}
Also used : InvalidNameException(javax.naming.InvalidNameException) Rdn(javax.naming.ldap.Rdn) LdapName(javax.naming.ldap.LdapName)

Example 37 with InvalidNameException

use of javax.naming.InvalidNameException 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 38 with InvalidNameException

use of javax.naming.InvalidNameException in project gerrit by GerritCodeReview.

the class LdapGroupBackend method cnFor.

private static String cnFor(String dn) {
    try {
        LdapName name = new LdapName(dn);
        if (!name.isEmpty()) {
            String cn = name.get(name.size() - 1);
            int index = cn.indexOf('=');
            if (index >= 0) {
                cn = cn.substring(index + 1);
            }
            return cn;
        }
    } catch (InvalidNameException e) {
        log.warn("Cannot parse LDAP dn for cn", e);
    }
    return dn;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) ParameterizedString(com.google.gerrit.common.data.ParameterizedString) LdapName(javax.naming.ldap.LdapName)

Example 39 with InvalidNameException

use of javax.naming.InvalidNameException in project jdk8u_jdk by JetBrains.

the class ResolveResult method appendRemainingComponent.

/**
      * Adds a single component to the end of remaining name.
      *
      * @param name The component to add. Can be null.
      * @see #getRemainingName
      * @see #appendRemainingName
      */
public void appendRemainingComponent(String name) {
    if (name != null) {
        CompositeName rname = new CompositeName();
        try {
            rname.add(name);
        } catch (InvalidNameException e) {
        // ignore; shouldn't happen for empty composite name
        }
        appendRemainingName(rname);
    }
}
Also used : InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName)

Example 40 with InvalidNameException

use of javax.naming.InvalidNameException in project Spark by igniterealtime.

the class MutualAuthenticationSettingsPanel method addCertificate.

private void addCertificate() {
    fileChooser.setAcceptAllFileFilterUsed(false);
    fileChooser.addChoosableFileFilter(certFilter);
    fileChooser.setFileFilter(certFilter);
    int retVal = fileChooser.showOpenDialog(this);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        try {
            idControll.addEntryToKeyStore(file);
        } catch (CertificateException e) {
            JOptionPane.showMessageDialog(null, Res.getString("dialog.cannot.upload.certificate.might.be.ill.formated"));
            Log.error("Cannot upload certificate file", e);
        } catch (InvalidKeySpecException | NoSuchAlgorithmException | KeyStoreException | InvalidNameException | IOException e) {
            JOptionPane.showMessageDialog(null, Res.getString("dialog.cannot.upload.certificate"));
            Log.error("Cannot upload certificate file", e);
        }
    }
}
Also used : InvalidNameException(javax.naming.InvalidNameException) CertificateException(java.security.cert.CertificateException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) File(java.io.File)

Aggregations

InvalidNameException (javax.naming.InvalidNameException)70 LdapName (javax.naming.ldap.LdapName)32 Rdn (javax.naming.ldap.Rdn)25 CompositeName (javax.naming.CompositeName)12 NamingException (javax.naming.NamingException)12 ArrayList (java.util.ArrayList)9 Name (javax.naming.Name)8 NameNotFoundException (javax.naming.NameNotFoundException)8 Context (javax.naming.Context)7 Attribute (javax.naming.directory.Attribute)7 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)6 NotContextException (javax.naming.NotContextException)6 Attributes (javax.naming.directory.Attributes)6 X509Certificate (java.security.cert.X509Certificate)5 NoSuchElementException (java.util.NoSuchElementException)5 OperationNotSupportedException (javax.naming.OperationNotSupportedException)5 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 SSLException (javax.net.ssl.SSLException)4 HashMap (java.util.HashMap)3