Search in sources :

Example 6 with AuthPermission

use of javax.security.auth.AuthPermission in project spring-framework by spring-projects.

the class CallbacksSecurityTests method testTrustedExecution.

@Test
public void testTrustedExecution() throws Exception {
    beanFactory.setSecurityContextProvider(null);
    Permissions perms = new Permissions();
    perms.add(new AuthPermission("getSubject"));
    ProtectionDomain pd = new ProtectionDomain(null, perms);
    new AccessControlContext(new ProtectionDomain[] { pd });
    final Subject subject = new Subject();
    subject.getPrincipals().add(new TestPrincipal("user1"));
    // request the beans from non-privileged code
    Subject.doAsPrivileged(subject, new PrivilegedAction<Object>() {

        @Override
        public Object run() {
            // sanity check
            assertEquals("user1", getCurrentSubjectName());
            assertEquals(false, NonPrivilegedBean.destroyed);
            beanFactory.getBean("trusted-spring-callbacks");
            beanFactory.getBean("trusted-custom-init-destroy");
            // the factory is a prototype - ask for multiple instances
            beanFactory.getBean("trusted-spring-factory");
            beanFactory.getBean("trusted-spring-factory");
            beanFactory.getBean("trusted-spring-factory");
            beanFactory.getBean("trusted-factory-bean");
            beanFactory.getBean("trusted-static-factory-method");
            beanFactory.getBean("trusted-factory-method");
            beanFactory.getBean("trusted-property-injection");
            beanFactory.getBean("trusted-working-property-injection");
            beanFactory.destroySingletons();
            assertEquals(true, NonPrivilegedBean.destroyed);
            return null;
        }
    }, provider.getAccessControlContext());
}
Also used : ProtectionDomain(java.security.ProtectionDomain) AccessControlContext(java.security.AccessControlContext) AuthPermission(javax.security.auth.AuthPermission) Permissions(java.security.Permissions) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 7 with AuthPermission

use of javax.security.auth.AuthPermission in project wildfly by wildfly.

the class AuthenticationTestCase method deployment.

/*
     * Authentication Scenarios
     *
     * Client -> Bean
     * Client -> Bean -> Bean
     * Client -> Bean (Re-auth) -> Bean
     * Client -> Servlet -> Bean
     * Client -> Servlet (Re-auth) -> Bean
     * Client -> Servlet -> Bean -> Bean
     * Client -> Servlet -> Bean (Re Auth) -> Bean
     */
@Deployment
public static Archive<?> deployment() {
    final Package currentPackage = AuthenticationTestCase.class.getPackage();
    // using JavaArchive doesn't work, because of a bug in Arquillian, it only deploys wars properly
    final WebArchive war = ShrinkWrap.create(WebArchive.class, "ejb3security.war").addPackage(WhoAmIBean.class.getPackage()).addPackage(EntryBean.class.getPackage()).addClass(WhoAmI.class).addClass(Util.class).addClass(Entry.class).addClasses(WhoAmIServlet.class, AuthenticationTestCase.class).addClasses(AbstractSecurityDomainSetup.class, EjbSecurityDomainSetup.class).addClass(TestSuiteEnvironment.class).addAsResource(currentPackage, "users.properties", "users.properties").addAsResource(currentPackage, "roles.properties", "roles.properties").addAsWebInfResource(currentPackage, "web.xml", "web.xml").addAsWebInfResource(currentPackage, "jboss-web.xml", "jboss-web.xml").addAsWebInfResource(currentPackage, "jboss-ejb3.xml", "jboss-ejb3.xml").addAsManifestResource(new StringAsset("Manifest-Version: 1.0\nDependencies: org.jboss.as.controller-client,org.jboss.dmr\n"), "MANIFEST.MF").addAsManifestResource(createPermissionsXmlAsset(// login module needs to modify pricipal to commit logging in
    new AuthPermission("modifyPrincipals"), // AuthenticationTestCase#testAuthenticatedCall calls org.jboss.security.client.JBossSecurityClient#performSimpleLogin
    new RuntimePermission("org.jboss.security.getSecurityContext"), new RuntimePermission("org.jboss.security.SecurityContextFactory.createSecurityContext"), new RuntimePermission("org.jboss.security.SecurityContextFactory.createUtil"), new RuntimePermission("org.jboss.security.plugins.JBossSecurityContext.setSubjectInfo"), new RuntimePermission("org.jboss.security.setSecurityContext"), // AuthenticationTestCase#execute calls ExecutorService#shutdownNow
    new RuntimePermission("modifyThread"), // AuthenticationTestCase#execute calls sun.net.www.http.HttpClient#openServer under the hood
    new SocketPermission(SERVER_HOST_PORT, "connect,resolve"), // TestSuiteEnvironment reads system properties
    new PropertyPermission("management.address", "read"), new PropertyPermission("node0", "read"), new PropertyPermission("jboss.http.port", "read")), "permissions.xml");
    war.addPackage(CommonCriteria.class.getPackage());
    return war;
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) PropertyPermission(java.util.PropertyPermission) AuthPermission(javax.security.auth.AuthPermission) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) SocketPermission(java.net.SocketPermission) Util(org.jboss.as.test.shared.integration.ejb.security.Util) WhoAmIBean(org.jboss.as.test.integration.ejb.security.base.WhoAmIBean) TestSuiteEnvironment(org.jboss.as.test.shared.TestSuiteEnvironment) CommonCriteria(org.jboss.as.test.categories.CommonCriteria) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 8 with AuthPermission

use of javax.security.auth.AuthPermission in project wildfly by wildfly.

the class IIOPSecurityInvocationTestCase method clientDeployment.

@Deployment(name = "client", testable = true)
@TargetsContainer("iiop-client")
public static Archive<?> clientDeployment() {
    /*
         * The @EJB annotation doesn't allow to specify the address dynamically. So, istead of
         *       @EJB(lookup = "corbaname:iiop:localhost:3628#IIOPTransactionalStatelessBean")
         *       private IIOPTransactionalHome home;
         * we need to do this trick to get the ${node0} sys prop into ejb-jar.xml
         * and have it injected that way.
         */
    String ejbJar = FileUtils.readFile(IIOPSecurityInvocationTestCase.class, "ejb-jar.xml");
    final Properties properties = new Properties();
    properties.putAll(System.getProperties());
    if (properties.containsKey("node1")) {
        properties.put("node1", NetworkUtils.formatPossibleIpv6Address((String) properties.get("node1")));
    }
    final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "client.jar");
    jar.addClasses(ClientEjb.class, IIOPSecurityStatelessHome.class, IIOPSecurityStatelessRemote.class, IIOPSecurityInvocationTestCase.class, Util.class).addAsManifestResource(IIOPSecurityInvocationTestCase.class.getPackage(), "jboss-ejb3.xml", "jboss-ejb3.xml").addAsManifestResource(new StringAsset(PropertiesValueResolver.replaceProperties(ejbJar, properties)), "ejb-jar.xml").addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(new AuthPermission("modifyPrincipals")), "permissions.xml");
    return jar;
}
Also used : StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) AuthPermission(javax.security.auth.AuthPermission) Util(org.jboss.as.test.shared.integration.ejb.security.Util) Properties(java.util.Properties) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Deployment(org.jboss.arquillian.container.test.api.Deployment) TargetsContainer(org.jboss.arquillian.container.test.api.TargetsContainer)

Example 9 with AuthPermission

use of javax.security.auth.AuthPermission in project scheduling by ow2-proactive.

the class RMDBManagerTest method setUp.

@Before
public void setUp() {
    PAResourceManagerProperties.RM_NODES_LOCK_RESTORATION.updateProperty("true");
    PAResourceManagerProperties.RM_ALIVE_EVENT_FREQUENCY.updateProperty("10000");
    dbManager = RMDBManager.createInMemoryRMDBManager();
    addNodeSourceData();
    owner = new Client();
    owner.setId(OWNER_ID);
    provider = new Client();
    provider.setId(PROVIDER_ID);
    permission = new AuthPermission(PERMISSION_NAME);
}
Also used : AuthPermission(javax.security.auth.AuthPermission) Client(org.ow2.proactive.resourcemanager.authentication.Client) Before(org.junit.Before)

Aggregations

AuthPermission (javax.security.auth.AuthPermission)9 Deployment (org.jboss.arquillian.container.test.api.Deployment)4 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)4 Util (org.jboss.as.test.shared.integration.ejb.security.Util)3 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)3 SocketPermission (java.net.SocketPermission)2 PropertyPermission (java.util.PropertyPermission)2 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)2 CommonCriteria (org.jboss.as.test.categories.CommonCriteria)2 TestSuiteEnvironment (org.jboss.as.test.shared.TestSuiteEnvironment)2 AccessControlContext (java.security.AccessControlContext)1 Permissions (java.security.Permissions)1 ProtectionDomain (java.security.ProtectionDomain)1 MessageFormat (java.text.MessageFormat)1 Properties (java.util.Properties)1 Subject (javax.security.auth.Subject)1 TargetsContainer (org.jboss.arquillian.container.test.api.TargetsContainer)1 WhoAmIBean (org.jboss.as.test.integration.ejb.security.base.WhoAmIBean)1 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)1 Before (org.junit.Before)1