Search in sources :

Example 6 with CompositeName

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

the class ServiceBasedNamingStore method convert.

private Name convert(ServiceName serviceName) {
    String[] c = serviceName.toArray();
    CompositeName name = new CompositeName();
    int baseIndex = serviceNameBase.toArray().length;
    for (int i = baseIndex; 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 7 with CompositeName

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

the class WritableServiceBasedNamingStoreTestCase method testRebindNoOwner.

@Test
public void testRebindNoOwner() throws Exception {
    try {
        store.rebind(new CompositeName("test"), new Object());
        fail("Should have failed with a read-only context exception");
    } catch (UnsupportedOperationException expected) {
    }
}
Also used : CompositeName(javax.naming.CompositeName) Test(org.junit.Test)

Example 8 with CompositeName

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

the class WritableServiceBasedNamingStoreTestCase method testUnbind.

@Test
public void testUnbind() throws Exception {
    final Name name = new CompositeName("test");
    final Object value = new Object();
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.bind(name, value);
        store.unbind(name);
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    try {
        store.lookup(name);
        fail("Should have thrown name not found");
    } catch (NameNotFoundException expect) {
    }
}
Also used : NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) Test(org.junit.Test)

Example 9 with CompositeName

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

the class WritableServiceBasedNamingStoreTestCase method testMultipleOwnersBindingReferences.

@Test
public void testMultipleOwnersBindingReferences() throws Exception {
    final Name name = new CompositeName("test");
    final ServiceName serviceName = store.buildServiceName(name);
    final Object value = new Object();
    // ensure bind does not exists
    try {
        store.lookup(name);
        fail("Should have thrown name not found");
    } catch (NameNotFoundException expect) {
    }
    // ensure the owners RuntimeBindReleaseService have no reference to the future bind
    final RuntimeBindReleaseService.References fooDuBindingReferences = (RuntimeBindReleaseService.References) container.getService(JndiNamingDependencyProcessor.serviceName(OWNER_FOO)).getValue();
    assertFalse(fooDuBindingReferences.contains(serviceName));
    final RuntimeBindReleaseService.References barDuBindingReferences = (RuntimeBindReleaseService.References) container.getService(JndiNamingDependencyProcessor.serviceName(OWNER_BAR)).getValue();
    assertFalse(barDuBindingReferences.contains(serviceName));
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.bind(name, value);
        // Foo's RuntimeBindReleaseService should now have a reference to the new bind
        assertTrue(fooDuBindingReferences.contains(serviceName));
        // Bar's RuntimeBindReleaseService reference to the bind should not exist
        assertFalse(barDuBindingReferences.contains(serviceName));
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    WritableServiceBasedNamingStore.pushOwner(OWNER_BAR);
    try {
        store.rebind(name, value);
        // after rebind, Foo's RuntimeBindReleaseService reference to the bind should still exist
        assertTrue(fooDuBindingReferences.contains(serviceName));
        // after rebind, Bar's RuntimeBindReleaseService reference to the bind should now exist
        assertTrue(barDuBindingReferences.contains(serviceName));
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.unbind(name);
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) RuntimeBindReleaseService(org.jboss.as.naming.deployment.RuntimeBindReleaseService) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) Test(org.junit.Test)

Example 10 with CompositeName

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

the class WritableServiceBasedNamingStoreTestCase method testPermissions.

/**
     * Binds an entry and then do lookups with several permissions
     * @throws Exception
     */
@Test
public void testPermissions() throws Exception {
    final NamingContext namingContext = new NamingContext(store, null);
    final String name = "a/b";
    final Object value = new Object();
    ArrayList<JndiPermission> permissions = new ArrayList<JndiPermission>();
    // simple bind test, note that permission must have absolute path
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        permissions.add(new JndiPermission(store.getBaseName() + "/" + name, "bind,list,listBindings"));
        store.bind(new CompositeName(name), value);
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    // all of these lookup should work
    permissions.set(0, new JndiPermission(store.getBaseName() + "/" + name, JndiPermission.ACTION_LOOKUP));
    assertEquals(value, testActionWithPermission(JndiPermission.ACTION_LOOKUP, permissions, namingContext, name));
    permissions.set(0, new JndiPermission(store.getBaseName() + "/-", JndiPermission.ACTION_LOOKUP));
    assertEquals(value, testActionWithPermission(JndiPermission.ACTION_LOOKUP, permissions, namingContext, name));
    permissions.set(0, new JndiPermission(store.getBaseName() + "/a/*", JndiPermission.ACTION_LOOKUP));
    assertEquals(value, testActionWithPermission(JndiPermission.ACTION_LOOKUP, permissions, namingContext, name));
    permissions.set(0, new JndiPermission(store.getBaseName() + "/a/-", JndiPermission.ACTION_LOOKUP));
    assertEquals(value, testActionWithPermission(JndiPermission.ACTION_LOOKUP, permissions, namingContext, name));
    permissions.set(0, new JndiPermission("<<ALL BINDINGS>>", JndiPermission.ACTION_LOOKUP));
    assertEquals(value, testActionWithPermission(JndiPermission.ACTION_LOOKUP, permissions, namingContext, name));
    permissions.set(0, new JndiPermission(store.getBaseName() + "/" + name, JndiPermission.ACTION_LOOKUP));
    assertEquals(value, testActionWithPermission(JndiPermission.ACTION_LOOKUP, permissions, namingContext, store.getBaseName() + "/" + name));
    NamingContext aNamingContext = (NamingContext) namingContext.lookup("a");
    permissions.set(0, new JndiPermission(store.getBaseName() + "/" + name, JndiPermission.ACTION_LOOKUP));
    assertEquals(value, testActionWithPermission(JndiPermission.ACTION_LOOKUP, permissions, aNamingContext, "b"));
    // this lookup should not work, no permission
    try {
        testActionWithPermission(JndiPermission.ACTION_LOOKUP, Collections.<JndiPermission>emptyList(), namingContext, name);
        fail("Should have failed due to missing permission");
    } catch (AccessControlException e) {
    }
    // a permission which only allows entries in store.getBaseName()
    try {
        permissions.set(0, new JndiPermission(store.getBaseName() + "/*", JndiPermission.ACTION_LOOKUP));
        testActionWithPermission(JndiPermission.ACTION_LOOKUP, permissions, namingContext, name);
        fail("Should have failed due to missing permission");
    } catch (AccessControlException e) {
    }
    // permissions which are not absolute paths (do not include store base name, i.e. java:)
    try {
        permissions.set(0, new JndiPermission(name, JndiPermission.ACTION_LOOKUP));
        testActionWithPermission(JndiPermission.ACTION_LOOKUP, permissions, namingContext, name);
        fail("Should have failed due to missing permission");
    } catch (AccessControlException e) {
    }
    if (!"java:".equals(store.getBaseName().toString())) {
        try {
            permissions.set(0, new JndiPermission("/" + name, JndiPermission.ACTION_LOOKUP));
            testActionWithPermission(JndiPermission.ACTION_LOOKUP, permissions, namingContext, name);
            fail("Should have failed due to missing permission");
        } catch (AccessControlException e) {
        }
        try {
            permissions.set(0, new JndiPermission("/-", JndiPermission.ACTION_LOOKUP));
            testActionWithPermission(JndiPermission.ACTION_LOOKUP, permissions, namingContext, name);
            fail("Should have failed due to missing permission");
        } catch (AccessControlException e) {
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CompositeName(javax.naming.CompositeName) AccessControlException(java.security.AccessControlException) JndiPermission(org.wildfly.naming.java.permission.JndiPermission) 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