Search in sources :

Example 51 with CompositeName

use of javax.naming.CompositeName in project Payara by payara.

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 = new CompositeName(name.substring(0, lastPos));
                Name childName = new CompositeName(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 = new CompositeName(name.substring(0, pos));
            Entry parent = treeLookup(compositeName);
            Entry child = new Entry(entryName, entry);
            if (parent != null)
                parent.addChild(child);
        }
    } catch (Exception e) {
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) NamingEntry(org.apache.naming.NamingEntry) ZipEntry(java.util.zip.ZipEntry) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) ZipException(java.util.zip.ZipException) NameAlreadyBoundException(javax.naming.NameAlreadyBoundException) IOException(java.io.IOException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 52 with CompositeName

use of javax.naming.CompositeName in project Payara by payara.

the class GlassfishNamingManagerImpl method publishCosNamingObject.

@Override
public void publishCosNamingObject(String name, Object obj, boolean rebind) throws NamingException {
    Name nameObj = new CompositeName(name);
    // Create any COS naming sub-contexts in name
    // that don't already exist.
    createSubContexts(nameObj, getCosContext());
    if (rebind) {
        getCosContext().rebind(name, obj);
    } else {
        getCosContext().bind(name, obj);
    }
    // Bind a reference to it in the SerialContext using
    // the same name. This is needed to allow standalone clients
    // to lookup the object using the same JNDI name.
    // It is also used from bindObjects while populating ejb-refs in
    // the java:comp namespace.
    Object serialObj = new Reference("reference", new StringRefAddr("url", name), IIOPOBJECT_FACTORY, null);
    publishObject(name, serialObj, rebind);
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 53 with CompositeName

use of javax.naming.CompositeName in project geronimo-xbean by apache.

the class AbstractContext method composeName.

public String composeName(String name, String prefix) throws NamingException {
    if (name == null)
        throw new NullPointerException("name is null");
    if (prefix == null)
        throw new NullPointerException("prefix is null");
    CompositeName result = new CompositeName(prefix);
    result.addAll(new CompositeName(name));
    return result.toString();
}
Also used : CompositeName(javax.naming.CompositeName)

Example 54 with CompositeName

use of javax.naming.CompositeName in project Payara by payara.

the class LDAPRealm method userSearch.

/**
 * Do anonymous search for the user. Should be unique if exists.
 */
private String userSearch(DirContext ctx, String baseDN, String filter) {
    if (_logger.isLoggable(Level.FINEST)) {
        _logger.log(Level.FINE, "search: baseDN: " + baseDN + "  filter: " + filter);
    }
    String foundDN = null;
    NamingEnumeration namingEnum = null;
    SearchControls ctls = new SearchControls();
    ctls.setReturningAttributes(_dnOnly);
    ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
    ctls.setCountLimit(1);
    try {
        namingEnum = ctx.search(baseDN, filter, ctls);
        if (namingEnum.hasMore()) {
            SearchResult res = (SearchResult) namingEnum.next();
            StringBuffer sb = new StringBuffer();
            // for dn name with '/'
            CompositeName compDN = new CompositeName(res.getName());
            String ldapDN = compDN.get(0);
            sb.append(ldapDN);
            if (res.isRelative()) {
                sb.append(",");
                sb.append(baseDN);
            }
            foundDN = sb.toString();
            if (_logger.isLoggable(Level.FINEST)) {
                _logger.log(Level.FINE, "Found user DN: " + foundDN);
            }
        }
    } catch (Exception e) {
        _logger.log(Level.WARNING, "ldaprealm.searcherror", filter);
        _logger.log(Level.WARNING, "security.exception", e);
    } finally {
        if (namingEnum != null) {
            try {
                namingEnum.close();
            } catch (Exception ex) {
            }
        }
    }
    return foundDN;
}
Also used : StringBuffer(java.lang.StringBuffer) CompositeName(javax.naming.CompositeName) NamingEnumeration(javax.naming.NamingEnumeration) SearchControls(javax.naming.directory.SearchControls) SearchResult(javax.naming.directory.SearchResult) LoginException(javax.security.auth.login.LoginException) BadRealmException(com.sun.enterprise.security.auth.realm.BadRealmException) NamingException(javax.naming.NamingException) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) InvalidOperationException(com.sun.enterprise.security.auth.realm.InvalidOperationException) IOException(java.io.IOException) NoSuchUserException(com.sun.enterprise.security.auth.realm.NoSuchUserException)

Example 55 with CompositeName

use of javax.naming.CompositeName in project rabbitmq-jms-client by rabbitmq.

the class RMQConnectionFactoryTest method testConnectionFactoryRegeneration.

@Test
public void testConnectionFactoryRegeneration() throws Exception {
    RMQConnectionFactory connFactory = new RMQConnectionFactory();
    connFactory.setHost("sillyHost");
    connFactory.setPassword("my-password");
    connFactory.setPort(42);
    connFactory.setQueueBrowserReadMax(52);
    connFactory.setSsl(true);
    connFactory.setTerminationTimeout(1234567890123456789L);
    connFactory.setUsername("fred");
    connFactory.setVirtualHost("bill");
    Reference ref = connFactory.getReference();
    RMQConnectionFactory newFactory = (RMQConnectionFactory) new RMQObjectFactory().createConnectionFactory(ref, new Hashtable<Object, Object>(), new CompositeName("newOne"));
    assertEquals("amqps://fred:my-password@sillyHost:42/bill", newFactory.getUri(), "Not the correct uri");
    assertEquals("sillyHost", newFactory.getHost(), "Not the correct host");
    assertEquals("my-password", newFactory.getPassword(), "Not the correct password");
    assertEquals(42, newFactory.getPort(), "Not the correct port");
    assertEquals(52, newFactory.getQueueBrowserReadMax(), "Not the correct queueBrowserReadMax");
    assertEquals(true, newFactory.isSsl(), "Not the correct ssl");
    assertEquals(15000L, newFactory.getTerminationTimeout(), "Not the correct terminationTimeout");
    assertEquals("fred", newFactory.getUsername(), "Not the correct username");
    assertEquals("bill", newFactory.getVirtualHost(), "Not the correct virtualHost");
}
Also used : Reference(javax.naming.Reference) Hashtable(java.util.Hashtable) CompositeName(javax.naming.CompositeName) Test(org.junit.jupiter.api.Test)

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