Search in sources :

Example 61 with InvalidNameException

use of javax.naming.InvalidNameException in project wildfly by wildfly.

the class InMemoryNamingStoreTestCase method testBindEmptyName.

@Test
public void testBindEmptyName() throws Exception {
    try {
        nameStore.bind(new CompositeName(), new Object(), Object.class);
        fail("Should have thrown and InvalidNameException");
    } catch (InvalidNameException expected) {
    }
    try {
        nameStore.bind(new CompositeName(""), new Object(), Object.class);
        fail("Should have thrown and InvalidNameException");
    } catch (InvalidNameException expected) {
    }
}
Also used : InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName) Test(org.junit.Test)

Example 62 with InvalidNameException

use of javax.naming.InvalidNameException in project uPortal by Jasig.

the class ReferenceCompositeGroupService method getEntity.

/**
 * Returns an <code>IEntity</code> representing a portal entity. This does not guarantee that
 * the entity actually exists.
 */
@Override
public IEntity getEntity(String key, Class type, String svcName) throws GroupsException {
    IIndividualGroupService svc = null;
    if (svcName == null) {
        svc = getDefaultService();
    } else {
        try {
            Name n = GroupService.parseServiceName(svcName);
            svc = getComponentService(n);
        } catch (InvalidNameException ine) {
            throw new GroupsException("Invalid service name.");
        }
    }
    return (svc == null) ? null : svc.getEntity(key, type);
}
Also used : InvalidNameException(javax.naming.InvalidNameException) Name(javax.naming.Name)

Example 63 with InvalidNameException

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

the class JNDIContext method lookup.

@Override
public Object lookup(String name) throws NamingException {
    if (name == null) {
        throw new InvalidNameException("The name cannot be null");
    } else if (name.equals("")) {
        return new JNDIContext(this);
    } else if (name.startsWith("java:")) {
        name = name.replaceFirst("^java:", "");
    } else if (!name.startsWith("/")) {
        name = tail + name;
    }
    final String prop = name.replaceFirst("comp/env/", "");
    String value = System.getProperty(prop);
    if (value != null) {
        return parseEntry(prop, value);
    }
    if (name.equals("comp/ORB")) {
        return getDefaultOrb();
    }
    final JNDIRequest req = new JNDIRequest();
    req.setRequestMethod(RequestMethodCode.JNDI_LOOKUP);
    req.setRequestString(name);
    req.setModuleId(moduleId);
    final JNDIResponse res;
    try {
        res = request(req);
    } catch (Exception e) {
        if (e instanceof RemoteException) {
            if (e.getCause() instanceof ConnectException) {
                e = (Exception) e.getCause();
                throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot lookup '" + name + "'.").initCause(e);
            } else if (AuthenticationException.class.isInstance(e.getCause())) {
                throw AuthenticationException.class.cast(e.getCause());
            }
        }
        throw (NamingException) new NamingException("Cannot lookup '" + name + "'.").initCause(e);
    }
    switch(res.getResponseCode()) {
        case ResponseCodes.JNDI_EJBHOME:
            return createEJBHomeProxy((EJBMetaDataImpl) res.getResult());
        case ResponseCodes.JNDI_BUSINESS_OBJECT:
            return createBusinessObject(res.getResult());
        case ResponseCodes.JNDI_OK:
            return res.getResult();
        case ResponseCodes.JNDI_INJECTIONS:
            return res.getResult();
        case ResponseCodes.JNDI_CONTEXT:
            final JNDIContext subCtx = new JNDIContext(this);
            if (!name.endsWith("/")) {
                name += '/';
            }
            subCtx.tail = name;
            return subCtx;
        case ResponseCodes.JNDI_DATA_SOURCE:
            return createDataSource((DataSourceMetaData) res.getResult());
        case ResponseCodes.JNDI_WEBSERVICE:
            return createWebservice((WsMetaData) res.getResult());
        case ResponseCodes.JNDI_RESOURCE:
            final String type = (String) res.getResult();
            value = System.getProperty("Resource/" + type);
            if (value == null) {
                return null;
            }
            return parseEntry(prop, value);
        case ResponseCodes.JNDI_REFERENCE:
            final Reference ref = (Reference) res.getResult();
            try {
                return NamingManager.getObjectInstance(ref, getNameParser(name).parse(name), this, env);
            } catch (Exception e) {
                throw (NamingException) new NamingException("Could not dereference " + ref).initCause(e);
            }
        case ResponseCodes.JNDI_NOT_FOUND:
            throw new NameNotFoundException(name + " does not exist in the system.  Check that the app was successfully deployed.");
        case ResponseCodes.JNDI_NAMING_EXCEPTION:
            final Throwable throwable = ((ThrowableArtifact) res.getResult()).getThrowable();
            if (throwable instanceof NamingException) {
                throw (NamingException) throwable;
            }
            throw (NamingException) new NamingException().initCause(throwable);
        case ResponseCodes.JNDI_RUNTIME_EXCEPTION:
            throw (RuntimeException) res.getResult();
        case ResponseCodes.JNDI_ERROR:
            {
                Object result = res.getResult();
                if (Error.class.isInstance(result)) {
                    throw Error.class.cast(result);
                }
                if (RuntimeException.class.isInstance(result)) {
                    throw RuntimeException.class.cast(result);
                }
                final Throwable th = Throwable.class.cast(result);
                throw new ClientRuntimeException(th.getMessage(), th);
            }
        default:
            throw new ClientRuntimeException("Invalid response from server: " + res.getResponseCode());
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) ServiceUnavailableException(javax.naming.ServiceUnavailableException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) ConnectException(java.net.ConnectException) NameNotFoundException(javax.naming.NameNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) InvalidNameException(javax.naming.InvalidNameException) InvalidNameException(javax.naming.InvalidNameException) NamingException(javax.naming.NamingException) RemoteException(java.rmi.RemoteException) ConnectException(java.net.ConnectException)

Example 64 with InvalidNameException

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

the class JNDIContext method list.

@SuppressWarnings("unchecked")
@Override
public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
    if (name == null) {
        throw new InvalidNameException("The name cannot be null");
    } else if (name.startsWith("java:")) {
        name = name.replaceFirst("^java:", "");
    } else if (!name.startsWith("/")) {
        name = tail + name;
    }
    final JNDIRequest req = new JNDIRequest(RequestMethodCode.JNDI_LIST, name);
    req.setModuleId(moduleId);
    final JNDIResponse res;
    try {
        res = request(req);
    } catch (Exception e) {
        if (e instanceof RemoteException && e.getCause() instanceof ConnectException) {
            e = (Exception) e.getCause();
            throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot list '" + name + "'.").initCause(e);
        }
        throw (NamingException) new NamingException("Cannot list '" + name + "'.").initCause(e);
    }
    switch(res.getResponseCode()) {
        case ResponseCodes.JNDI_OK:
            return null;
        case ResponseCodes.JNDI_ENUMERATION:
            return (NamingEnumeration) res.getResult();
        case ResponseCodes.JNDI_NOT_FOUND:
            throw new NameNotFoundException(name);
        case ResponseCodes.JNDI_NAMING_EXCEPTION:
            final Throwable throwable = ((ThrowableArtifact) res.getResult()).getThrowable();
            if (throwable instanceof NamingException) {
                throw (NamingException) throwable;
            }
            throw (NamingException) new NamingException().initCause(throwable);
        case ResponseCodes.JNDI_ERROR:
            throw (Error) res.getResult();
        default:
            throw new ClientRuntimeException("Invalid response from server :" + res.getResponseCode());
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) NamingEnumeration(javax.naming.NamingEnumeration) ServiceUnavailableException(javax.naming.ServiceUnavailableException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException) NamingException(javax.naming.NamingException) AuthenticationException(javax.naming.AuthenticationException) ConnectException(java.net.ConnectException) NameNotFoundException(javax.naming.NameNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) InvalidNameException(javax.naming.InvalidNameException) InvalidNameException(javax.naming.InvalidNameException) NamingException(javax.naming.NamingException) RemoteException(java.rmi.RemoteException) ConnectException(java.net.ConnectException)

Example 65 with InvalidNameException

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

the class ZKHostnameVerifier method extractCN.

private static String extractCN(final String subjectPrincipal) throws SSLException {
    if (subjectPrincipal == null) {
        return null;
    }
    try {
        final LdapName subjectDN = new LdapName(subjectPrincipal);
        final List<Rdn> rdns = subjectDN.getRdns();
        for (int i = rdns.size() - 1; i >= 0; i--) {
            final Rdn rds = rdns.get(i);
            final Attributes attributes = rds.toAttributes();
            final Attribute cn = attributes.get("cn");
            if (cn != null) {
                try {
                    final Object value = cn.get();
                    if (value != null) {
                        return value.toString();
                    }
                } catch (final NoSuchElementException ignore) {
                // ignore exception
                } catch (final NamingException ignore) {
                // ignore exception
                }
            }
        }
        return null;
    } catch (final InvalidNameException e) {
        throw new SSLException(subjectPrincipal + " is not a valid X500 distinguished name");
    }
}
Also used : InvalidNameException(javax.naming.InvalidNameException) Attribute(javax.naming.directory.Attribute) Attributes(javax.naming.directory.Attributes) NamingException(javax.naming.NamingException) Rdn(javax.naming.ldap.Rdn) SSLException(javax.net.ssl.SSLException) NoSuchElementException(java.util.NoSuchElementException) LdapName(javax.naming.ldap.LdapName)

Aggregations

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