Search in sources :

Example 91 with CompositeName

use of javax.naming.CompositeName 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)

Example 92 with CompositeName

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

the class ServiceBasedNamingStore method suffix.

private Name suffix(ServiceName parent, ServiceName child) {
    String[] p = parent.toArray();
    String[] c = child.toArray();
    CompositeName name = new CompositeName();
    for (int i = p.length; i < c.length; i++) {
        try {
            name.add(c[i]);
        } catch (InvalidNameException e) {
            throw new IllegalStateException(e);
        }
    }
    return name;
}
Also used : InvalidNameException(javax.naming.InvalidNameException) CompositeName(javax.naming.CompositeName)

Example 93 with CompositeName

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

the class InMemoryNamingStoreTestCase method testList.

@Test
public void testList() throws Exception {
    final Name name = new CompositeName("test");
    final Object object = new Object();
    nameStore.bind(name, object, Object.class);
    final Name nameTwo = new CompositeName("testTwo");
    final Object objectTwo = new Object();
    nameStore.bind(nameTwo, objectTwo, Object.class);
    final Name nameThree = new CompositeName("testThree");
    final Object objectThree = new Object();
    nameStore.bind(nameThree, objectThree, Object.class);
    nameStore.bind(new CompositeName("testContext/test"), "test");
    final List<NameClassPair> results = nameStore.list(new CompositeName());
    assertEquals(4, results.size());
    final Set<String> expected = new HashSet<String>(Arrays.asList("test", "testTwo", "testThree", "testContext"));
    for (NameClassPair result : results) {
        final String resultName = result.getName();
        if ("test".equals(resultName) || "testTwo".equals(resultName) || "testThree".equals(resultName)) {
            assertEquals(Object.class.getName(), result.getClassName());
        } else if ("testContext".equals(resultName)) {
            assertEquals(Context.class.getName(), result.getClassName());
        } else {
            fail("Unknown result name: " + resultName);
        }
        expected.remove(resultName);
    }
    assertTrue("Not all expected results were returned", expected.isEmpty());
}
Also used : NameClassPair(javax.naming.NameClassPair) CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 94 with CompositeName

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

the class InMemoryNamingStoreTestCase method testBindAndRebind.

@Test
public void testBindAndRebind() throws Exception {
    final Name name = new CompositeName("test");
    final Object object = new Object();
    nameStore.bind(name, object, Object.class);
    assertEquals(object, nameStore.lookup(name));
    final Object objectTwo = new Object();
    nameStore.rebind(name, objectTwo, Object.class);
    assertEquals(objectTwo, nameStore.lookup(name));
}
Also used : CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) Test(org.junit.Test)

Example 95 with CompositeName

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

the class InMemoryNamingStoreTestCase method testBindAndLookup.

@Test
public void testBindAndLookup() throws Exception {
    final Name name = new CompositeName("test");
    final Object object = new Object();
    nameStore.bind(name, object, Object.class);
    final Object result = nameStore.lookup(name);
    assertEquals(object, result);
}
Also used : CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) Test(org.junit.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