Search in sources :

Example 11 with CompositeName

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

the class SecurityHelper method testActionWithoutPermission.

public static void testActionWithoutPermission(final int action, final Collection<JndiPermission> additionalRequiredPerms, final NamingContext namingContext, final String name, final Object... params) throws Exception {
    final CompositeName n = name == null ? new CompositeName() : new CompositeName(name);
    final String sn = name == null ? "" : name;
    ArrayList<JndiPermission> allPerms = new ArrayList<JndiPermission>(additionalRequiredPerms);
    allPerms.add(new JndiPermission(sn, not(action)));
    try {
        runWithSecurityManager(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                return performAction(action, namingContext, n, params);
            }
        }, getSecurityContextForJNDILookup(allPerms));
        fail("Naming operation " + action + " should not have been permitted");
    } catch (SecurityException e) {
    //expected
    }
}
Also used : CompositeName(javax.naming.CompositeName) ArrayList(java.util.ArrayList) JndiPermission(org.wildfly.naming.java.permission.JndiPermission) PrivilegedActionException(java.security.PrivilegedActionException) NamingException(javax.naming.NamingException)

Example 12 with CompositeName

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

the class ServiceBasedNamingStoreTestCase method testStoredContext.

@Test
public void testStoredContext() throws Exception {
    final ServiceName bindingName = ServiceName.JBOSS.append("foo-stored").append("again");
    bindObject(bindingName, new Context() {

        @Override
        public Object lookup(Name name) throws NamingException {
            if ("blah/blah2".equals(name.toString())) {
                return new Integer(5);
            }
            return null;
        }

        @Override
        public Object lookup(String name) throws NamingException {
            return lookup(new CompositeName(name));
        }

        @Override
        public void bind(Name name, Object obj) throws NamingException {
        }

        @Override
        public void bind(String name, Object obj) throws NamingException {
        }

        @Override
        public void rebind(Name name, Object obj) throws NamingException {
        }

        @Override
        public void rebind(String name, Object obj) throws NamingException {
        }

        @Override
        public void unbind(Name name) throws NamingException {
        }

        @Override
        public void unbind(String name) throws NamingException {
        }

        @Override
        public void rename(Name oldName, Name newName) throws NamingException {
        }

        @Override
        public void rename(String oldName, String newName) throws NamingException {
        }

        @Override
        public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
            return null;
        }

        @Override
        public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
            return null;
        }

        @Override
        public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
            if (!"hi/there".equals(name.toString()))
                throw new IllegalArgumentException("Expected hi/there");
            return null;
        }

        @Override
        public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
            return null;
        }

        @Override
        public void destroySubcontext(Name name) throws NamingException {
        }

        @Override
        public void destroySubcontext(String name) throws NamingException {
        }

        @Override
        public Context createSubcontext(Name name) throws NamingException {
            return null;
        }

        @Override
        public Context createSubcontext(String name) throws NamingException {
            return null;
        }

        @Override
        public Object lookupLink(Name name) throws NamingException {
            return null;
        }

        @Override
        public Object lookupLink(String name) throws NamingException {
            return null;
        }

        @Override
        public NameParser getNameParser(Name name) throws NamingException {
            return null;
        }

        @Override
        public NameParser getNameParser(String name) throws NamingException {
            return null;
        }

        @Override
        public Name composeName(Name name, Name prefix) throws NamingException {
            return null;
        }

        @Override
        public String composeName(String name, String prefix) throws NamingException {
            return null;
        }

        @Override
        public Object addToEnvironment(String propName, Object propVal) throws NamingException {
            return null;
        }

        @Override
        public Object removeFromEnvironment(String propName) throws NamingException {
            return null;
        }

        @Override
        public Hashtable<?, ?> getEnvironment() throws NamingException {
            return null;
        }

        @Override
        public void close() throws NamingException {
        }

        @Override
        public String getNameInNamespace() throws NamingException {
            return null;
        }
    });
    final NamingContext ctx = new NamingContext(new CompositeName(), store, null);
    final Object obj = ctx.lookup(new CompositeName("foo-stored/again/blah/blah2"));
    ctx.listBindings("foo-stored/again/hi/there");
    assertNotNull(obj);
    assertEquals(new Integer(5), obj);
}
Also used : StopContext(org.jboss.msc.service.StopContext) Context(javax.naming.Context) StartContext(org.jboss.msc.service.StartContext) Hashtable(java.util.Hashtable) CompositeName(javax.naming.CompositeName) NamingEnumeration(javax.naming.NamingEnumeration) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) ServiceName(org.jboss.msc.service.ServiceName) NamingException(javax.naming.NamingException) NameParser(javax.naming.NameParser) Test(org.junit.Test)

Example 13 with CompositeName

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

the class ServiceBasedNamingStoreTestCase method testLookupBase.

@Test
public void testLookupBase() throws Exception {
    final Object obj = store.lookup(new CompositeName());
    assertNotNull(obj);
}
Also used : CompositeName(javax.naming.CompositeName) Test(org.junit.Test)

Example 14 with CompositeName

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

the class ServiceBasedNamingStoreTestCase method testLookupBindingUsingNestedContext.

@Test
public void testLookupBindingUsingNestedContext() throws Exception {
    final ServiceName bindingName = ServiceName.JBOSS.append("foo", "bar", "baz", "TestBean");
    final Object value = new Object();
    bindObject(bindingName, value);
    Object context = store.lookup(new CompositeName("foo"));
    assertNotNull(context);
    assertTrue(context instanceof Context);
    Object obj = Context.class.cast(context).lookup(new CompositeName("bar/baz/TestBean"));
    assertNotNull(obj);
    assertEquals(value, obj);
    context = Context.class.cast(context).lookup(new CompositeName("bar"));
    obj = Context.class.cast(context).lookup(new CompositeName("baz/TestBean"));
    assertNotNull(obj);
    assertEquals(value, obj);
    context = Context.class.cast(context).lookup(new CompositeName("baz"));
    obj = Context.class.cast(context).lookup(new CompositeName("TestBean"));
    assertNotNull(obj);
    assertEquals(value, obj);
}
Also used : StopContext(org.jboss.msc.service.StopContext) Context(javax.naming.Context) StartContext(org.jboss.msc.service.StartContext) ServiceName(org.jboss.msc.service.ServiceName) CompositeName(javax.naming.CompositeName) Test(org.junit.Test)

Example 15 with CompositeName

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

the class ServiceBasedNamingStoreTestCase method testLookupNestedContext.

@Test
public void testLookupNestedContext() throws Exception {
    final ServiceName bindingName = ServiceName.JBOSS.append("foo", "bar", "baz", "TestBean");
    store.add(bindingName);
    store.add(ServiceName.JBOSS.append("foos", "bar"));
    store.add(ServiceName.JBOSS.append("fo", "bar"));
    store.add(ServiceName.JBOSS.append("foo", "ba"));
    store.add(ServiceName.JBOSS.append("foo", "bart"));
    store.add(ServiceName.JBOSS.append("foo", "bar", "ba"));
    store.add(ServiceName.JBOSS.append("foo", "bar", "bazt"));
    store.add(ServiceName.JBOSS.append("foo", "bar", "art"));
    Object obj = store.lookup(new CompositeName("foo"));
    assertNotNull(obj);
    assertTrue(obj instanceof Context);
    obj = Context.class.cast(obj).lookup(new CompositeName("bar"));
    assertNotNull(obj);
    assertTrue(obj instanceof Context);
    obj = Context.class.cast(obj).lookup(new CompositeName("baz"));
    assertNotNull(obj);
    assertTrue(obj instanceof Context);
}
Also used : StopContext(org.jboss.msc.service.StopContext) Context(javax.naming.Context) StartContext(org.jboss.msc.service.StartContext) ServiceName(org.jboss.msc.service.ServiceName) CompositeName(javax.naming.CompositeName) 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