Search in sources :

Example 76 with Name

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

the class ContextManagedReferenceFactory method getReference.

@Override
public ManagedReference getReference() {
    final NamingStore namingStore = namingStoreInjectedValue.getValue();
    try {
        final Name name = NameParser.INSTANCE.parse(this.name);
        final NamingContext context = new NamingContext(name, namingStore, null);
        return new ManagedReference() {

            @Override
            public void release() {
            }

            @Override
            public Object getInstance() {
                return context;
            }
        };
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }
}
Also used : NamingException(javax.naming.NamingException) Name(javax.naming.Name)

Example 77 with Name

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

the class NamingContext method lookup.

public Object lookup(final Name name, boolean dereference) throws NamingException {
    check(name, JndiPermission.ACTION_LOOKUP);
    if (isEmpty(name)) {
        return new NamingContext(prefix, namingStore, environment);
    }
    final Name absoluteName = getAbsoluteName(name);
    Object result;
    try {
        result = namingStore.lookup(absoluteName, dereference);
    } catch (CannotProceedException cpe) {
        final Context continuationContext = NamingManager.getContinuationContext(cpe);
        if (continuationContext instanceof NamingContext) {
            result = ((NamingContext) continuationContext).lookup(cpe.getRemainingName(), dereference);
        } else {
            result = continuationContext.lookup(cpe.getRemainingName());
        }
    }
    if (result instanceof ResolveResult) {
        final ResolveResult resolveResult = (ResolveResult) result;
        final Object resolvedObject = resolveResult.getResolvedObj();
        Object context;
        if (resolvedObject instanceof Context) {
            context = resolvedObject;
        } else if (resolvedObject instanceof LinkRef) {
            context = resolveLink(resolvedObject, dereference);
        } else {
            context = getObjectInstance(resolvedObject, absoluteName, environment);
        }
        if (!(context instanceof Context)) {
            throw notAContextException(absoluteName.getPrefix(absoluteName.size() - resolveResult.getRemainingName().size()));
        }
        final Context namingContext = (Context) context;
        if (namingContext instanceof NamingContext) {
            return ((NamingContext) namingContext).lookup(resolveResult.getRemainingName(), dereference);
        } else {
            return namingContext.lookup(resolveResult.getRemainingName());
        }
    } else if (result instanceof LinkRef) {
        result = resolveLink(result, dereference);
    } else if (result instanceof Reference) {
        result = getObjectInstance(result, absoluteName, environment);
        if (result instanceof LinkRef) {
            result = resolveLink(result, dereference);
        }
    }
    return result;
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) EventContext(javax.naming.event.EventContext) CannotProceedException(javax.naming.CannotProceedException) Reference(javax.naming.Reference) ResolveResult(javax.naming.spi.ResolveResult) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) LinkRef(javax.naming.LinkRef)

Example 78 with Name

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

the class NamingContext method getAbsoluteName.

private Name getAbsoluteName(final Name name) throws NamingException {
    if (name.isEmpty()) {
        return composeName(name, prefix);
    }
    final String firstComponent = name.get(0);
    if (firstComponent.startsWith("java:")) {
        final String cleaned = firstComponent.substring(5);
        final Name suffix = name.getSuffix(1);
        if (cleaned.isEmpty()) {
            return suffix;
        }
        return suffix.add(0, cleaned);
    } else if (firstComponent.isEmpty()) {
        return name.getSuffix(1);
    } else {
        return composeName(name, prefix);
    }
}
Also used : CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 79 with Name

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

the class NamingContext method composeName.

/** {@inheritDoc} */
public Name composeName(Name name, Name prefix) throws NamingException {
    final Name result = (Name) prefix.clone();
    if (name instanceof CompositeName) {
        if (name.size() == 1) {
            // name could be a nested name
            final String firstComponent = name.get(0);
            result.addAll(parseName(firstComponent));
        } else {
            result.addAll(name);
        }
    } else {
        result.addAll(new CompositeName(name.toString()));
    }
    return result;
}
Also used : CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 80 with Name

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

the class NamingContext method check.

private void check(Name name, int actions) throws NamingException {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null && WildFlySecurityManager.isChecking()) {
        // build absolute name (including store's base name)
        Name absoluteName = (Name) namingStore.getBaseName().clone();
        if (name.isEmpty()) {
            absoluteName.addAll(prefix);
        } else {
            final String firstComponent = name.get(0);
            if (firstComponent.startsWith("java:")) {
                absoluteName = name;
            } else if (firstComponent.isEmpty()) {
                absoluteName.addAll(name.getSuffix(1));
            } else {
                absoluteName.addAll(prefix);
                if (name instanceof CompositeName) {
                    if (name.size() == 1) {
                        // name could be a nested name
                        absoluteName.addAll(parseName(firstComponent));
                    } else {
                        absoluteName.addAll(name);
                    }
                } else {
                    absoluteName.addAll(new CompositeName(name.toString()));
                }
            }
        }
        sm.checkPermission(new JndiPermission(absoluteName.toString(), actions));
    }
}
Also used : WildFlySecurityManager(org.wildfly.security.manager.WildFlySecurityManager) CompositeName(javax.naming.CompositeName) JndiPermission(org.wildfly.naming.java.permission.JndiPermission) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Aggregations

Name (javax.naming.Name)107 CompositeName (javax.naming.CompositeName)48 NamingException (javax.naming.NamingException)38 Context (javax.naming.Context)37 InitialContext (javax.naming.InitialContext)36 NameNotFoundException (javax.naming.NameNotFoundException)34 Test (org.junit.Test)32 Reference (javax.naming.Reference)24 NotContextException (javax.naming.NotContextException)22 Binding (javax.naming.Binding)19 CompoundName (javax.naming.CompoundName)19 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)19 NameParser (javax.naming.NameParser)17 OperationNotSupportedException (javax.naming.OperationNotSupportedException)16 InvalidNameException (javax.naming.InvalidNameException)10 NamingContext (org.eclipse.jetty.jndi.NamingContext)10 IOException (java.io.IOException)8 LinkRef (javax.naming.LinkRef)7 ServiceName (org.jboss.msc.service.ServiceName)7 Referenceable (javax.naming.Referenceable)6