Search in sources :

Example 26 with Permission

use of java.security.Permission in project jdk8u_jdk by JetBrains.

the class JmxMBeanServer method checkMBeanPermission.

// SECURITY CHECKS
//----------------
private static void checkMBeanPermission(String classname, String member, ObjectName objectName, String actions) throws SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        Permission perm = new MBeanPermission(classname, member, objectName, actions);
        sm.checkPermission(perm);
    }
}
Also used : MBeanPermission(javax.management.MBeanPermission) MBeanPermission(javax.management.MBeanPermission) Permission(java.security.Permission) MBeanServerPermission(javax.management.MBeanServerPermission)

Example 27 with Permission

use of java.security.Permission in project jdk8u_jdk by JetBrains.

the class DefaultMBeanServerInterceptor method checkMBeanPermission.

private static void checkMBeanPermission(String classname, String member, ObjectName objectName, String actions) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        Permission perm = new MBeanPermission(classname, member, objectName, actions);
        sm.checkPermission(perm);
    }
}
Also used : MBeanPermission(javax.management.MBeanPermission) MBeanPermission(javax.management.MBeanPermission) MBeanTrustPermission(javax.management.MBeanTrustPermission) Permission(java.security.Permission)

Example 28 with Permission

use of java.security.Permission in project jdk8u_jdk by JetBrains.

the class MBeanServerFactory method checkPermission.

private static void checkPermission(String action) throws SecurityException {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        Permission perm = new MBeanServerPermission(action);
        sm.checkPermission(perm);
    }
}
Also used : Permission(java.security.Permission)

Example 29 with Permission

use of java.security.Permission in project jdk8u_jdk by JetBrains.

the class TokenStore method checkPerm.

private static void checkPerm(PolicyFile p, ProtectionDomain pd) throws Exception {
    boolean foundIt = false;
    Enumeration perms = p.getPermissions(pd).elements();
    while (perms.hasMoreElements()) {
        Permission perm = (Permission) perms.nextElement();
        if (!(perm instanceof AllPermission)) {
            throw new SecurityException("expected AllPermission");
        } else {
            foundIt = true;
        }
    }
    if (!foundIt) {
        throw new SecurityException("expected AllPermission");
    }
}
Also used : Permission(java.security.Permission) AllPermission(java.security.AllPermission) AllPermission(java.security.AllPermission)

Example 30 with Permission

use of java.security.Permission in project jdk8u_jdk by JetBrains.

the class Proc method start.

// Starts the proc
public Proc start() throws IOException {
    List<String> cmd = new ArrayList<>();
    if (launcher != null) {
        cmd.add(launcher);
    } else {
        cmd.add(new File(new File(System.getProperty("java.home"), "bin"), "java").getPath());
    }
    cmd.add("-cp");
    StringBuilder cp = new StringBuilder();
    for (URL url : ((URLClassLoader) Proc.class.getClassLoader()).getURLs()) {
        if (cp.length() != 0) {
            cp.append(File.pathSeparatorChar);
        }
        cp.append(url.getFile());
    }
    cmd.add(cp.toString());
    for (Entry<String, String> e : prop.entrySet()) {
        cmd.add("-D" + e.getKey() + "=" + e.getValue());
    }
    if (!perms.isEmpty()) {
        Path p = Files.createTempFile(Paths.get(".").toAbsolutePath(), "policy", null);
        StringBuilder sb = new StringBuilder();
        sb.append("grant {\n");
        for (Permission perm : perms) {
            // Sometimes a permission has no name or actions.
            // but it's safe to use an empty string.
            String s = String.format("%s \"%s\", \"%s\"", perm.getClass().getCanonicalName(), perm.getName().replace("\\", "\\\\").replace("\"", "\\\""), perm.getActions());
            sb.append("    permission ").append(s).append(";\n");
        }
        sb.append("};\n");
        Files.write(p, sb.toString().getBytes());
        cmd.add("-Djava.security.policy=" + p.toString());
    }
    cmd.add(clazz);
    for (String s : args) {
        cmd.add(s);
    }
    if (debug != null) {
        System.out.println("PROC: " + debug + " cmdline: " + cmd);
    }
    ProcessBuilder pb = new ProcessBuilder(cmd);
    for (Entry<String, String> e : env.entrySet()) {
        pb.environment().put(e.getKey(), e.getValue());
    }
    if (inheritIO) {
        pb.inheritIO();
    } else if (noDump) {
        pb.redirectError(ProcessBuilder.Redirect.INHERIT);
    } else {
        pb.redirectError(ProcessBuilder.Redirect.appendTo(new File(DFILE)));
    }
    p = pb.start();
    br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    return this;
}
Also used : Path(java.nio.file.Path) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) URL(java.net.URL) URLClassLoader(java.net.URLClassLoader) Permission(java.security.Permission) BufferedReader(java.io.BufferedReader) File(java.io.File)

Aggregations

Permission (java.security.Permission)236 Test (org.junit.Test)55 PermissionCollection (java.security.PermissionCollection)39 FilePermission (java.io.FilePermission)38 Permissions (java.security.Permissions)31 ProtectionDomain (java.security.ProtectionDomain)27 IOException (java.io.IOException)20 AllPermission (java.security.AllPermission)20 QuickTest (com.hazelcast.test.annotation.QuickTest)17 File (java.io.File)17 URL (java.net.URL)16 AccessControlException (java.security.AccessControlException)14 Principal (java.security.Principal)14 PropertyPermission (java.util.PropertyPermission)14 Policy (java.security.Policy)13 MBeanPermission (javax.management.MBeanPermission)13 AccessControlContext (java.security.AccessControlContext)12 CodeSource (java.security.CodeSource)11 SecurityPermission (java.security.SecurityPermission)11 ArrayList (java.util.ArrayList)10