Search in sources :

Example 6 with SocketPermission

use of java.net.SocketPermission in project jdk8u_jdk by JetBrains.

the class DGCImplInsulation method main.

public static void main(String[] args) throws Exception {
    TestLibrary.suggestSecurityManager(null);
    Permissions perms = new Permissions();
    perms.add(new SocketPermission("*:1024-", "listen"));
    AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(new CodeSource(null, (Certificate[]) null), perms) });
    Remote impl = new DGCImplInsulation();
    ;
    try {
        Remote stub = (Remote) java.security.AccessController.doPrivileged(new ExportAction(impl));
        System.err.println("exported remote object; local stub: " + stub);
        MarshalledObject mobj = new MarshalledObject(stub);
        stub = (Remote) mobj.get();
        System.err.println("marshalled/unmarshalled stub: " + stub);
        ReferenceQueue refQueue = new ReferenceQueue();
        Reference weakRef = new WeakReference(impl, refQueue);
        impl = null;
        System.gc();
        if (refQueue.remove(TIMEOUT) == weakRef) {
            throw new RuntimeException("TEST FAILED: remote object garbage collected");
        } else {
            System.err.println("TEST PASSED");
            stub = null;
            System.gc();
            Thread.sleep(2000);
            System.gc();
        }
    } finally {
        try {
            UnicastRemoteObject.unexportObject(impl, true);
        } catch (Exception e) {
        }
    }
}
Also used : ProtectionDomain(java.security.ProtectionDomain) ReferenceQueue(java.lang.ref.ReferenceQueue) Reference(java.lang.ref.Reference) WeakReference(java.lang.ref.WeakReference) SocketPermission(java.net.SocketPermission) Remote(java.rmi.Remote) CodeSource(java.security.CodeSource) AccessControlContext(java.security.AccessControlContext) MarshalledObject(java.rmi.MarshalledObject) WeakReference(java.lang.ref.WeakReference) Permissions(java.security.Permissions) Certificate(java.security.cert.Certificate)

Example 7 with SocketPermission

use of java.net.SocketPermission in project wildfly by wildfly.

the class DynamicMessageListenerTestCase method createDeplyoment.

@Deployment
public static Archive createDeplyoment() {
    final EnterpriseArchive ear = create(EnterpriseArchive.class, "ear-with-rar.ear").addAsModule(create(JavaArchive.class, "telnet-ra.rar").addAsManifestResource(TelnetResourceAdapter.class.getPackage(), "ra.xml", "ra.xml").addPackages(true, TelnetResourceAdapter.class.getPackage(), TelnetListener.class.getPackage(), TelnetServer.class.getPackage())).addAsModule(create(JavaArchive.class, "mdb.jar").addClasses(MyMdb.class));
    ear.addAsManifestResource(createPermissionsXmlAsset(// Cmd (TelnetServer package) uses PropertyEditorManager#registerEditor during static initialization
    new PropertyPermission("*", "read,write"), // TelnetServer binds socket and accepts connections
    new SocketPermission("*", "accept,listen")), "permissions.xml");
    return ear;
}
Also used : EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) TelnetResourceAdapter(org.jboss.as.test.integration.ejb.mdb.dynamic.adapter.TelnetResourceAdapter) PropertyPermission(java.util.PropertyPermission) TelnetListener(org.jboss.as.test.integration.ejb.mdb.dynamic.api.TelnetListener) SocketPermission(java.net.SocketPermission) MyMdb(org.jboss.as.test.integration.ejb.mdb.dynamic.application.MyMdb) TelnetServer(org.jboss.as.test.integration.ejb.mdb.dynamic.impl.TelnetServer) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 8 with SocketPermission

use of java.net.SocketPermission in project wildfly by wildfly.

the class LdapUrlInSearchBaseTestCase method deployment.

// Public methods --------------------------------------------------------
/**
     * Creates {@link WebArchive} with the {@link OKServlet}.
     *
     * @return
     */
@Deployment
public static WebArchive deployment() {
    final WebArchive war = ShrinkWrap.create(WebArchive.class, "ldap-test.war");
    war.addClasses(LdapUrlTestServlet.class);
    war.addAsManifestResource(createPermissionsXmlAsset(new SocketPermission("*:10389", "connect,resolve")), "permissions.xml");
    return war;
}
Also used : WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) SocketPermission(java.net.SocketPermission) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 9 with SocketPermission

use of java.net.SocketPermission in project wildfly by wildfly.

the class JMXConnectorTestCase method createTestArchive.

@Deployment
public static JavaArchive createTestArchive() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, CB_DEPLOYMENT_NAME);
    archive.addClass(ConnectedBean.class);
    archive.addClass(ConnectedBeanInterface.class);
    archive.addAsManifestResource(createPermissionsXmlAsset(new SocketPermission("*:*", "connect,resolve")), "permissions.xml");
    return archive;
}
Also used : SocketPermission(java.net.SocketPermission) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 10 with SocketPermission

use of java.net.SocketPermission 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, EjbElytronDomainSetup.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 principal 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.wildfly.test.integration.elytron.ejb.base.WhoAmIBean) TestSuiteEnvironment(org.jboss.as.test.shared.TestSuiteEnvironment) CommonCriteria(org.jboss.as.test.categories.CommonCriteria) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Aggregations

SocketPermission (java.net.SocketPermission)45 Deployment (org.jboss.arquillian.container.test.api.Deployment)13 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)10 AccessControlContext (java.security.AccessControlContext)9 PropertyPermission (java.util.PropertyPermission)9 FilePermission (java.io.FilePermission)8 Test (org.testng.annotations.Test)8 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)7 URL (java.net.URL)6 IOException (java.io.IOException)5 DatagramSocket (java.net.DatagramSocket)5 InetAddress (java.net.InetAddress)4 InetSocketAddress (java.net.InetSocketAddress)4 MulticastSocket (java.net.MulticastSocket)4 ServerSocket (java.net.ServerSocket)3 Permissions (java.security.Permissions)3 PrivilegedActionException (java.security.PrivilegedActionException)3 Properties (java.util.Properties)3 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)3 File (java.io.File)2