Search in sources :

Example 1 with ManagementPermission

use of java.lang.management.ManagementPermission in project elasticsearch by elastic.

the class JvmInfo method jvmInfo.

public static JvmInfo jvmInfo() {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new ManagementPermission("monitor"));
        sm.checkPropertyAccess("*");
    }
    return INSTANCE;
}
Also used : ManagementPermission(java.lang.management.ManagementPermission)

Example 2 with ManagementPermission

use of java.lang.management.ManagementPermission in project ignite by apache.

the class SecuritySubjectPermissionsTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    if (System.getSecurityManager() == null) {
        Policy.setPolicy(new Policy() {

            @Override
            public PermissionCollection getPermissions(CodeSource cs) {
                Permissions res = new Permissions();
                res.add(new RuntimePermission("*"));
                res.add(new MBeanServerPermission("*"));
                res.add(new MBeanPermission("*", "*"));
                res.add(new MBeanTrustPermission("*"));
                res.add(new ReflectPermission("*"));
                res.add(new SSLPermission("*"));
                res.add(new ManagementPermission("monitor"));
                res.add(new ManagementPermission("control"));
                res.add(new SerializablePermission("*"));
                res.add(new SecurityPermission("*"));
                res.add(new SocketPermission("*", "connect,accept,listen,resolve"));
                res.add(new FilePermission("<<ALL FILES>>", "read,write,delete,execute,readlink"));
                res.add(new PropertyPermission("*", "read,write"));
                res.add(new TestPermission("common"));
                return res;
            }
        });
        System.setSecurityManager(new SecurityManager());
        setupSM = true;
    }
}
Also used : Policy(java.security.Policy) PermissionCollection(java.security.PermissionCollection) PropertyPermission(java.util.PropertyPermission) MBeanPermission(javax.management.MBeanPermission) SocketPermission(java.net.SocketPermission) ManagementPermission(java.lang.management.ManagementPermission) SSLPermission(javax.net.ssl.SSLPermission) CodeSource(java.security.CodeSource) FilePermission(java.io.FilePermission) MBeanServerPermission(javax.management.MBeanServerPermission) MBeanTrustPermission(javax.management.MBeanTrustPermission) Permissions(java.security.Permissions) ReflectPermission(java.lang.reflect.ReflectPermission) SerializablePermission(java.io.SerializablePermission) SecurityPermission(java.security.SecurityPermission)

Example 3 with ManagementPermission

use of java.lang.management.ManagementPermission in project openj9 by eclipse.

the class TestManagementPermission method testManagementPermissionStringString.

/*
	 * Class under test for void ManagementPermission(String, String)
	 */
@Test
public final void testManagementPermissionStringString() {
    // Normal cases.
    ManagementPermission mp = new ManagementPermission("monitor", "");
    AssertJUnit.assertNotNull(mp);
    mp = new ManagementPermission("control", null);
    AssertJUnit.assertNotNull(mp);
    // Bad input - null name
    try {
        mp = new ManagementPermission(null, null);
        Assert.fail("Should have thrown NPE for null name.");
    } catch (Exception e) {
    }
    // Bad input - unwanted name
    try {
        mp = new ManagementPermission("Sunset", null);
        Assert.fail("Should have thrown IllegalArgumentException for incorrect name.");
    } catch (Exception e) {
    }
    // Bad input - correct name but in incorrect type
    try {
        mp = new ManagementPermission("Monitor", null);
        Assert.fail("Should have thrown IllegalArgumentException for upper-case name.");
    } catch (Exception e) {
    }
    // Bad input - action not one of "" or null
    try {
        mp = new ManagementPermission("monitor", "You broke my heart Fredo.");
        Assert.fail("Should have thrown IllegalArgumentException for bad action.");
    } catch (Exception e) {
    }
}
Also used : ManagementPermission(java.lang.management.ManagementPermission) Test(org.testng.annotations.Test)

Example 4 with ManagementPermission

use of java.lang.management.ManagementPermission in project openj9 by eclipse.

the class TestManagementPermission method testManagementPermissionString.

/*
	 * Class under test for void ManagementPermission(String)
	 */
@Test
public final void testManagementPermissionString() {
    // Normal cases.
    ManagementPermission mp = new ManagementPermission("monitor");
    AssertJUnit.assertNotNull(mp);
    mp = new ManagementPermission("control");
    AssertJUnit.assertNotNull(mp);
    // Bad input - null name
    try {
        mp = new ManagementPermission(null);
        Assert.fail("Should have thrown NPE for null name.");
    } catch (Exception e) {
    }
    // Bad input - unwanted name
    try {
        mp = new ManagementPermission("Sunset");
        Assert.fail("Should have thrown IllegalArgumentException for incorrect name.");
    } catch (Exception e) {
    }
    // Bad input - correct name but in incorrect type
    try {
        mp = new ManagementPermission("Monitor");
        Assert.fail("Should have thrown IllegalArgumentException for upper-case name.");
    } catch (Exception e) {
    }
}
Also used : ManagementPermission(java.lang.management.ManagementPermission) Test(org.testng.annotations.Test)

Aggregations

ManagementPermission (java.lang.management.ManagementPermission)4 Test (org.testng.annotations.Test)2 FilePermission (java.io.FilePermission)1 SerializablePermission (java.io.SerializablePermission)1 ReflectPermission (java.lang.reflect.ReflectPermission)1 SocketPermission (java.net.SocketPermission)1 CodeSource (java.security.CodeSource)1 PermissionCollection (java.security.PermissionCollection)1 Permissions (java.security.Permissions)1 Policy (java.security.Policy)1 SecurityPermission (java.security.SecurityPermission)1 PropertyPermission (java.util.PropertyPermission)1 MBeanPermission (javax.management.MBeanPermission)1 MBeanServerPermission (javax.management.MBeanServerPermission)1 MBeanTrustPermission (javax.management.MBeanTrustPermission)1 SSLPermission (javax.net.ssl.SSLPermission)1