Search in sources :

Example 16 with JndiPermission

use of org.wildfly.naming.java.permission.JndiPermission in project wildfly by wildfly.

the class NamingContextTestCase method testLookupLink.

@Test
public void testLookupLink() throws Exception {
    final Name name = new CompositeName("test");
    namingStore.bind(name, "testValue", String.class);
    final Name linkName = new CompositeName("link");
    namingStore.bind(linkName, new LinkRef("./test"));
    Object result = namingContext.lookup(linkName);
    assertEquals("testValue", result);
    //the same with security permissions
    result = testActionPermission(JndiPermission.ACTION_LOOKUP, Arrays.asList(new JndiPermission("test", "lookup")), namingContext, "link");
    assertEquals("testValue", result);
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, InitialContextFactory.class.getName());
    namingStore.rebind(linkName, new LinkRef(name));
    result = namingContext.lookup(linkName);
    assertEquals("testValue", result);
    //the same with security permissions
    result = testActionPermission(JndiPermission.ACTION_LOOKUP, Arrays.asList(new JndiPermission("test", "lookup")), namingContext, "link");
    assertEquals("testValue", result);
}
Also used : CompositeName(javax.naming.CompositeName) JndiPermission(org.wildfly.naming.java.permission.JndiPermission) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) LinkRef(javax.naming.LinkRef) Test(org.junit.Test)

Example 17 with JndiPermission

use of org.wildfly.naming.java.permission.JndiPermission in project wildfly by wildfly.

the class SharedBindingTestCase method deployOne.

@Deployment(name = BEAN_ONE_JAR_NAME, managed = false)
public static Archive<?> deployOne() {
    final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, BEAN_ONE_JAR_NAME + ".jar");
    jar.addClasses(BeanOne.class, TestResults.class);
    jar.addAsManifestResource(SharedBindingTestCase.class.getPackage(), "ejb-jar-one.xml", "ejb-jar.xml");
    jar.addAsManifestResource(createPermissionsXmlAsset(new JndiPermission("global/sharedbinds/two", "rebind")), "permissions.xml");
    return jar;
}
Also used : JndiPermission(org.wildfly.naming.java.permission.JndiPermission) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 18 with JndiPermission

use of org.wildfly.naming.java.permission.JndiPermission in project wildfly by wildfly.

the class SecurityHelper method testActionWithPermission.

public static Object testActionWithPermission(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, action));
    return runWithSecurityManager(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return performAction(action, namingContext, n, params);
        }
    }, getSecurityContextForJNDILookup(allPerms));
}
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 19 with JndiPermission

use of org.wildfly.naming.java.permission.JndiPermission in project wildfly by wildfly.

the class NamingContextTestCase method testLookupWitResolveResult.

@Test
public void testLookupWitResolveResult() throws Exception {
    namingStore.bind(new CompositeName("test/nested"), "test");
    final Reference reference = new Reference(String.class.getName(), new StringRefAddr("blahh", "test"), TestObjectFactoryWithNameResolution.class.getName(), null);
    namingStore.bind(new CompositeName("comp"), reference);
    Object result = namingContext.lookup(new CompositeName("comp/nested"));
    assertEquals("test", result);
    //the same with security permissions
    result = testActionPermission(JndiPermission.ACTION_LOOKUP, Arrays.asList(new JndiPermission("test/nested", "lookup")), namingContext, "comp/nested");
    assertEquals("test", result);
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) JndiPermission(org.wildfly.naming.java.permission.JndiPermission) Test(org.junit.Test)

Aggregations

JndiPermission (org.wildfly.naming.java.permission.JndiPermission)19 CompositeName (javax.naming.CompositeName)10 Deployment (org.jboss.arquillian.container.test.api.Deployment)8 Test (org.junit.Test)7 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)6 ArrayList (java.util.ArrayList)3 Name (javax.naming.Name)3 PrivilegedActionException (java.security.PrivilegedActionException)2 LinkRef (javax.naming.LinkRef)2 NamingException (javax.naming.NamingException)2 Reference (javax.naming.Reference)2 StringRefAddr (javax.naming.StringRefAddr)2 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)2 AccessControlContext (java.security.AccessControlContext)1 AccessControlException (java.security.AccessControlException)1 CodeSource (java.security.CodeSource)1 Permissions (java.security.Permissions)1 ProtectionDomain (java.security.ProtectionDomain)1 Certificate (java.security.cert.Certificate)1 MBeanPermission (javax.management.MBeanPermission)1