Search in sources :

Example 41 with InvalidNameException

use of javax.naming.InvalidNameException in project tomcat70 by apache.

the class JNDIRealm method getDistinguishedName.

/**
 * Returns the distinguished name of a search result.
 *
 * @param context Our DirContext
 * @param base The base DN
 * @param result The search result
 * @return String containing the distinguished name
 */
protected String getDistinguishedName(DirContext context, String base, SearchResult result) throws NamingException {
    // the result name.  For non-relative names, use the returned name.
    if (result.isRelative()) {
        if (containerLog.isTraceEnabled()) {
            containerLog.trace("  search returned relative name: " + result.getName());
        }
        NameParser parser = context.getNameParser("");
        Name contextName = parser.parse(context.getNameInNamespace());
        Name baseName = parser.parse(base);
        // Bugzilla 32269
        Name entryName = parser.parse(new CompositeName(result.getName()).get(0));
        Name name = contextName.addAll(baseName);
        name = name.addAll(entryName);
        return name.toString();
    } else {
        String absoluteName = result.getName();
        if (containerLog.isTraceEnabled())
            containerLog.trace("  search returned absolute name: " + result.getName());
        try {
            // Normalize the name by running it through the name parser.
            NameParser parser = context.getNameParser("");
            URI userNameUri = new URI(absoluteName);
            String pathComponent = userNameUri.getPath();
            // Should not ever have an empty path component, since that is /{DN}
            if (pathComponent.length() < 1) {
                throw new InvalidNameException("Search returned unparseable absolute name: " + absoluteName);
            }
            Name name = parser.parse(pathComponent.substring(1));
            return name.toString();
        } catch (URISyntaxException e) {
            throw new InvalidNameException("Search returned unparseable absolute name: " + absoluteName);
        }
    }
}
Also used : InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) NameParser(javax.naming.NameParser) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 42 with InvalidNameException

use of javax.naming.InvalidNameException in project certmgr by hdecarne.

the class CertOptionsTemplates method wrap.

public static Template wrap(UserCertStoreEntry storeEntry) {
    String dnInput = X500Names.toString(storeEntry.dn());
    String aliasInput = dnInput;
    try {
        LdapName dn = new LdapName(aliasInput);
        for (Rdn rdn : dn.getRdns()) {
            if (DN_ALIAS_KEY.equals(rdn.getType())) {
                aliasInput = String.valueOf(rdn.getValue());
                break;
            }
        }
    } catch (InvalidNameException e) {
        Exceptions.ignore(e);
    }
    CertOptionsPreset preset = new CertOptionsPreset(aliasInput, dnInput);
    try {
        if (storeEntry.hasCRT()) {
            X509Certificate crt = storeEntry.getCRT();
            PublicKey publicKey = crt.getPublicKey();
            preset.setKeyAlg(KeyHelper.getKeyAlg(publicKey));
            preset.setKeySize(KeyHelper.getKeySize(publicKey));
            Set<String> criticalExtensionOIDs = crt.getCriticalExtensionOIDs();
            if (criticalExtensionOIDs != null) {
                for (String criticalExtensionOID : criticalExtensionOIDs) {
                    if (!INVALID_PRESET_EXTENSIONS.contains(criticalExtensionOID)) {
                        X509ExtensionData criticalExtension = X509ExtensionData.decode(criticalExtensionOID, true, crt.getExtensionValue(criticalExtensionOID));
                        preset.addExtension(criticalExtension);
                    }
                }
            }
            Set<String> nonCriticalExtensionOIDs = crt.getNonCriticalExtensionOIDs();
            if (nonCriticalExtensionOIDs != null) {
                for (String nonCriticalExtensionOID : nonCriticalExtensionOIDs) {
                    if (!INVALID_PRESET_EXTENSIONS.contains(nonCriticalExtensionOID)) {
                        X509ExtensionData nonCriticalExtension = X509ExtensionData.decode(nonCriticalExtensionOID, false, crt.getExtensionValue(nonCriticalExtensionOID));
                        preset.addExtension(nonCriticalExtension);
                    }
                }
            }
        }
    } catch (IOException e) {
        Exceptions.warn(e);
    }
    return new Template(preset.aliasInput(), preset);
}
Also used : X509ExtensionData(de.carne.certmgr.certs.x509.X509ExtensionData) InvalidNameException(javax.naming.InvalidNameException) PublicKey(java.security.PublicKey) IOException(java.io.IOException) Rdn(javax.naming.ldap.Rdn) X509Certificate(java.security.cert.X509Certificate) LdapName(javax.naming.ldap.LdapName)

Example 43 with InvalidNameException

use of javax.naming.InvalidNameException in project certmgr by hdecarne.

the class DNEditorController method init.

/**
 * Initialize the DN editor's content.
 *
 * @param dnInput The current DN input.
 * @return This controller.
 */
public DNEditorController init(String dnInput) {
    try {
        LdapName dn = new LdapName(dnInput);
        this.ctlRdnEntries.getItems().addAll(dn.getRdns());
    } catch (InvalidNameException e) {
        Exceptions.ignore(e);
    }
    return this;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) LdapName(javax.naming.ldap.LdapName)

Example 44 with InvalidNameException

use of javax.naming.InvalidNameException in project archiva by apache.

the class ArchivaLdapConnectionFactory method initialize.

@PostConstruct
@Override
public void initialize() {
    try {
        LdapConfiguration ldapConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getLdapConfiguration();
        ldapConnectionConfiguration = new LdapConnectionConfiguration();
        ldapConnectionConfiguration.setHostname(ldapConfiguration.getHostName());
        ldapConnectionConfiguration.setPort(ldapConfiguration.getPort());
        ldapConnectionConfiguration.setSsl(ldapConfiguration.isSsl());
        ldapConnectionConfiguration.setBaseDn(ldapConfiguration.getBaseDn());
        ldapConnectionConfiguration.setContextFactory(ldapConfiguration.getContextFactory());
        ldapConnectionConfiguration.setBindDn(ldapConfiguration.getBindDn());
        ldapConnectionConfiguration.setPassword(ldapConfiguration.getPassword());
        ldapConnectionConfiguration.setAuthenticationMethod(ldapConfiguration.getAuthenticationMethod());
        ldapConnectionConfiguration.setExtraProperties(toProperties(ldapConfiguration.getExtraProperties()));
        valid = true;
    } catch (InvalidNameException e) {
        log.error("Error during initialization of LdapConnectionFactory {}", e.getMessage(), e);
    // throw new RuntimeException( "Error while initializing connection factory.", e );
    } catch (RepositoryAdminException e) {
        throw new RuntimeException("Error while initializing ldapConnectionConfiguration: " + e.getMessage(), e);
    }
}
Also used : InvalidNameException(javax.naming.InvalidNameException) LdapConfiguration(org.apache.archiva.admin.model.beans.LdapConfiguration) LdapConnectionConfiguration(org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) PostConstruct(javax.annotation.PostConstruct)

Example 45 with InvalidNameException

use of javax.naming.InvalidNameException in project archiva by apache.

the class DefaultRedbackRuntimeConfigurationService method checkLdapConnection.

@Override
public Boolean checkLdapConnection(LdapConfiguration ldapConfiguration) throws ArchivaRestServiceException {
    LdapConnection ldapConnection = null;
    try {
        LdapConnectionConfiguration ldapConnectionConfiguration = new LdapConnectionConfiguration(ldapConfiguration.getHostName(), ldapConfiguration.getPort(), ldapConfiguration.getBaseDn(), ldapConfiguration.getContextFactory(), ldapConfiguration.getBindDn(), ldapConfiguration.getPassword(), ldapConfiguration.getAuthenticationMethod(), toProperties(ldapConfiguration.getExtraProperties()));
        ldapConnectionConfiguration.setSsl(ldapConfiguration.isSsl());
        ldapConnection = ldapConnectionFactory.getConnection(ldapConnectionConfiguration);
        ldapConnection.close();
        // verify groups dn value too
        ldapConnectionConfiguration = new LdapConnectionConfiguration(ldapConfiguration.getHostName(), ldapConfiguration.getPort(), ldapConfiguration.getBaseGroupsDn(), ldapConfiguration.getContextFactory(), ldapConfiguration.getBindDn(), ldapConfiguration.getPassword(), ldapConfiguration.getAuthenticationMethod(), toProperties(ldapConfiguration.getExtraProperties()));
        ldapConnectionConfiguration.setSsl(ldapConfiguration.isSsl());
        ldapConnection = ldapConnectionFactory.getConnection(ldapConnectionConfiguration);
    } catch (InvalidNameException e) {
        log.warn("fail to get ldapConnection: {}", e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } catch (LdapException e) {
        log.warn("fail to get ldapConnection: {}", e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } finally {
        if (ldapConnection != null) {
            ldapConnection.close();
        }
    }
    return Boolean.TRUE;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) LdapConnectionConfiguration(org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration) LdapException(org.apache.archiva.redback.common.ldap.connection.LdapException) LdapConnection(org.apache.archiva.redback.common.ldap.connection.LdapConnection)

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