Search in sources :

Example 61 with CompositeName

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

the class ReadOnlyContext method lookup.

@Override
public Object lookup(String name) throws NamingException {
    if (name.length() == 0) {
        return this;
    }
    Object result = treeBindings.get(name);
    if (result == null) {
        result = bindings.get(name);
    }
    if (result == null) {
        int pos = name.indexOf(':');
        if (pos > 0) {
            String scheme = name.substring(0, pos);
            Context ctx = NamingManager.getURLContext(scheme, environment);
            if (ctx == null) {
                throw new NamingException("scheme " + scheme + " not recognized");
            }
            return ctx.lookup(name);
        } else {
            // Split out the first name of the path
            // and look for it in the bindings map.
            CompositeName path = new CompositeName(name);
            if (path.size() == 0) {
                return this;
            } else {
                String first = path.get(0);
                Object obj = bindings.get(first);
                if (obj == null) {
                    throw new NameNotFoundException(name);
                } else if (obj instanceof Context && path.size() > 1) {
                    Context subContext = (Context) obj;
                    obj = subContext.lookup(path.getSuffix(1));
                }
                return obj;
            }
        }
    }
    if (result instanceof LinkRef) {
        LinkRef ref = (LinkRef) result;
        result = lookup(ref.getLinkName());
    }
    if (result instanceof Reference) {
        try {
            result = NamingManager.getObjectInstance(result, null, null, this.environment);
        } catch (NamingException e) {
            throw e;
        } catch (Exception e) {
            throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
        }
    }
    if (result instanceof ReadOnlyContext) {
        String prefix = getNameInNamespace();
        if (prefix.length() > 0) {
            prefix = prefix + SEPARATOR;
        }
        result = new ReadOnlyContext((ReadOnlyContext) result, environment, prefix + name);
    }
    return result;
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NotContextException(javax.naming.NotContextException) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) NameNotFoundException(javax.naming.NameNotFoundException) LinkRef(javax.naming.LinkRef)

Example 62 with CompositeName

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

the class TestContext method lookup.

@Override
public Object lookup(String name) throws NamingException {
    if (name.length() == 0) {
        return this;
    }
    Object result = treeBindings.get(name);
    if (result == null) {
        result = bindings.get(name);
    }
    if (result == null) {
        int pos = name.indexOf(':');
        if (pos > 0) {
            String scheme = name.substring(0, pos);
            Context ctx = NamingManager.getURLContext(scheme, environment);
            if (ctx == null) {
                throw new NamingException("scheme " + scheme + " not recognized");
            }
            return ctx.lookup(name);
        } else {
            // Split out the first name of the path
            // and look for it in the bindings map.
            CompositeName path = new CompositeName(name);
            if (path.size() == 0) {
                return this;
            } else {
                String first = path.get(0);
                Object obj = bindings.get(first);
                if (obj == null) {
                    throw new NameNotFoundException(name);
                } else if (obj instanceof Context && path.size() > 1) {
                    Context subContext = (Context) obj;
                    obj = subContext.lookup(path.getSuffix(1));
                }
                return obj;
            }
        }
    }
    if (result instanceof LinkRef) {
        LinkRef ref = (LinkRef) result;
        result = lookup(ref.getLinkName());
    }
    if (result instanceof Reference) {
        try {
            result = NamingManager.getObjectInstance(result, null, null, this.environment);
        } catch (NamingException e) {
            throw e;
        } catch (Exception e) {
            throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
        }
    }
    if (result instanceof TestContext) {
        String prefix = getNameInNamespace();
        if (prefix.length() > 0) {
            prefix = prefix + SEPARATOR;
        }
        result = new TestContext((TestContext) result, environment, prefix + name);
    }
    return result;
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NotContextException(javax.naming.NotContextException) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) NameNotFoundException(javax.naming.NameNotFoundException) LinkRef(javax.naming.LinkRef)

Example 63 with CompositeName

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

the class NamingContextBindingsEnumeration method nextElementInternal.

private Binding nextElementInternal() throws NamingException {
    NamingEntry entry = iterator.next();
    Object value;
    // If the entry is a reference, resolve it
    if (entry.type == NamingEntry.REFERENCE || entry.type == NamingEntry.LINK_REF) {
        try {
            value = ctx.lookup(new CompositeName(entry.name));
        } catch (NamingException e) {
            throw e;
        } catch (Exception e) {
            NamingException ne = new NamingException(e.getMessage());
            ne.initCause(e);
            throw ne;
        }
    } else {
        value = entry.value;
    }
    return new Binding(entry.name, value.getClass().getName(), value, true);
}
Also used : Binding(javax.naming.Binding) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException)

Example 64 with CompositeName

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

the class WARDirContext method loadEntries.

/**
 * Constructs a tree of the entries contained in a WAR file.
 */
protected void loadEntries() {
    try {
        Enumeration<? extends ZipEntry> entryList = base.entries();
        entries = new Entry("/", new ZipEntry("/"));
        while (entryList.hasMoreElements()) {
            ZipEntry entry = entryList.nextElement();
            String name = normalize(entry);
            int pos = name.lastIndexOf('/');
            // Check that parent entries exist and, if not, create them.
            // This fixes a bug for war files that don't record separate
            // zip entries for the directories.
            int currentPos = -1;
            int lastPos = 0;
            while ((currentPos = name.indexOf('/', lastPos)) != -1) {
                Name parentName = getEscapedJndiName(name.substring(0, lastPos));
                Name childName = getEscapedJndiName(name.substring(0, currentPos));
                String entryName = name.substring(lastPos, currentPos);
                // Parent should have been created in last cycle through
                // this loop
                Entry parent = treeLookup(parentName);
                Entry child = treeLookup(childName);
                if (child == null) {
                    // Create a new entry for missing entry and strip off
                    // the leading '/' character and appended on by the
                    // normalize method and add '/' character to end to
                    // signify that it is a directory entry
                    String zipName = name.substring(1, currentPos) + "/";
                    child = new Entry(entryName, new ZipEntry(zipName));
                    if (parent != null)
                        parent.addChild(child);
                }
                // Increment lastPos
                lastPos = currentPos + 1;
            }
            String entryName = name.substring(pos + 1, name.length());
            Name compositeName = getEscapedJndiName(name.substring(0, pos));
            Entry parent = treeLookup(compositeName);
            Entry child = new Entry(entryName, entry);
            if (parent != null)
                parent.addChild(child);
        }
    } catch (Exception e) {
    // Ignore
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) NamingEntry(org.apache.naming.NamingEntry) ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 65 with CompositeName

use of javax.naming.CompositeName in project tomcat 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
 * @exception NamingException if a directory server error occurs
 */
protected String getDistinguishedName(DirContext context, String base, SearchResult result) throws NamingException {
    // Get the entry's distinguished name.  For relative results, this means
    // we need to composite a name with the base name, the context name, and
    // the result name.  For non-relative names, use the returned name.
    String resultName = result.getName();
    Name name;
    if (result.isRelative()) {
        if (containerLog.isTraceEnabled()) {
            containerLog.trace("  search returned relative name: " + resultName);
        }
        NameParser parser = context.getNameParser("");
        Name contextName = parser.parse(context.getNameInNamespace());
        Name baseName = parser.parse(base);
        // Bugzilla 32269
        Name entryName = parser.parse(new CompositeName(resultName).get(0));
        name = contextName.addAll(baseName);
        name = name.addAll(entryName);
    } else {
        if (containerLog.isTraceEnabled()) {
            containerLog.trace("  search returned absolute name: " + resultName);
        }
        try {
            // Normalize the name by running it through the name parser.
            NameParser parser = context.getNameParser("");
            URI userNameUri = new URI(resultName);
            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: " + resultName);
            }
            name = parser.parse(pathComponent.substring(1));
        } catch (URISyntaxException e) {
            throw new InvalidNameException("Search returned unparseable absolute name: " + resultName);
        }
    }
    if (getForceDnHexEscape()) {
        // Bug 63026
        return convertToHexEscape(name.toString());
    } else {
        return name.toString();
    }
}
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) GSSName(org.ietf.jgss.GSSName)

Aggregations

CompositeName (javax.naming.CompositeName)124 Test (org.junit.Test)69 Name (javax.naming.Name)43 NameNotFoundException (javax.naming.NameNotFoundException)27 NamingException (javax.naming.NamingException)25 Reference (javax.naming.Reference)19 Context (javax.naming.Context)18 InvalidNameException (javax.naming.InvalidNameException)13 NotContextException (javax.naming.NotContextException)12 ServiceName (org.jboss.msc.service.ServiceName)11 Test (org.junit.jupiter.api.Test)10 JndiPermission (org.wildfly.naming.java.permission.JndiPermission)10 Hashtable (java.util.Hashtable)9 Binding (javax.naming.Binding)8 LinkRef (javax.naming.LinkRef)8 OperationNotSupportedException (javax.naming.OperationNotSupportedException)8 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)7 IEntityGroup (org.apereo.portal.groups.IEntityGroup)7 BaseAggrEventsJpaDaoTest (org.apereo.portal.test.BaseAggrEventsJpaDaoTest)7 StringRefAddr (javax.naming.StringRefAddr)5