Search in sources :

Example 36 with Permission

use of java.security.Permission in project Payara by payara.

the class SMGlobalPolicyUtilTest method testFilePermission.

@Test
public void testFilePermission() {
    System.out.println("Starting testFilePermission");
    FilePermission fp1 = new FilePermission("-", "delete");
    FilePermission fp2 = new FilePermission("a/file.txt", "delete");
    Assert.assertTrue(fp1.implies(fp2));
    FilePermission fp3 = new FilePermission("*", "delete");
    FilePermission fp4 = new FilePermission("file.txt", "delete");
    Assert.assertTrue(fp3.implies(fp4));
    FilePermission fp5 = new FilePermission("/scratch/xyz/*", "delete");
    FilePermission fp6 = new FilePermission("/scratch/xyz/deleteit.txt", "delete");
    Assert.assertTrue(fp5.implies(fp6));
    FilePermission fp7 = new FilePermission("/scratch/xyz/", "delete");
    FilePermission fp8 = new FilePermission("/scratch/xyz", "delete");
    Assert.assertTrue(fp7.implies(fp8));
    Permission fp9 = new java.security.UnresolvedPermission("VoidPermission", "", "", null);
    Permission fp10 = new java.security.AllPermission();
    Assert.assertTrue(fp10.implies(fp9));
    Assert.assertTrue(!fp9.implies(fp10));
}
Also used : Permission(java.security.Permission) FilePermission(java.io.FilePermission) FilePermission(java.io.FilePermission) Test(org.junit.Test)

Example 37 with Permission

use of java.security.Permission in project Payara by payara.

the class SMGlobalPolicyUtilTest method dumpPermissions.

private int dumpPermissions(String type, String component, PermissionCollection pc) {
    int count = 0;
    if (pc == null) {
        System.out.println("Type= " + type + ", compnent= " + component + ", Permission is empty ");
        return count;
    }
    Enumeration<Permission> pen = pc.elements();
    while (pen.hasMoreElements()) {
        Permission p = pen.nextElement();
        System.out.println("Type= " + type + ", compnent= " + component + ", Permission p= " + p);
        count += 1;
    }
    return count;
}
Also used : Permission(java.security.Permission) FilePermission(java.io.FilePermission)

Example 38 with Permission

use of java.security.Permission in project Payara by payara.

the class PermissionsProcessor method processPermisssonsForPath.

protected static PermissionCollection processPermisssonsForPath(PermissionCollection originalPC, DeploymentContext dc) throws MalformedURLException {
    if (originalPC == null)
        return originalPC;
    Permissions revisedPC = new Permissions();
    Enumeration<Permission> pcEnum = originalPC.elements();
    while (pcEnum.hasMoreElements()) {
        Permission perm = pcEnum.nextElement();
        if (perm instanceof FilePermission) {
            processFilePermission(revisedPC, dc, (FilePermission) perm);
        } else
            revisedPC.add(perm);
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("Revised permissions = " + revisedPC);
    }
    return revisedPC;
}
Also used : Permissions(java.security.Permissions) Permission(java.security.Permission) FilePermission(java.io.FilePermission) FilePermission(java.io.FilePermission)

Example 39 with Permission

use of java.security.Permission in project Payara by payara.

the class MapValue method processConstraints.

public static void processConstraints(WebBundleDescriptor wbd, PolicyConfiguration pc) throws javax.security.jacc.PolicyContextException {
    if (logger.isLoggable(Level.FINE)) {
        logger.entering("WebPermissionUtil", "processConstraints");
        logger.log(Level.FINE, "JACC: constraint translation: CODEBASE = " + pc.getContextID());
    }
    HashMap qpMap = parseConstraints(wbd);
    HashMap<String, Permissions> roleMap = new HashMap<String, Permissions>();
    Permissions excluded = new Permissions();
    Permissions unchecked = new Permissions();
    boolean deny = wbd.isDenyUncoveredHttpMethods();
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "JACC: constraint capture: begin processing qualified url patterns" + " - uncovered http methods will be " + (deny ? "denied" : "permitted"));
    }
    // for each urlPatternSpec in the map
    Iterator it = qpMap.values().iterator();
    while (it.hasNext()) {
        MapValue m = (MapValue) it.next();
        if (!m.irrelevantByQualifier) {
            String name = m.urlPatternSpec.toString();
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "JACC: constraint capture: urlPattern: " + name);
            }
            // handle Uncovered Methods
            m.handleUncoveredMethods(deny);
            // handle excluded methods
            handleExcluded(excluded, m, name);
            // handle methods requiring role
            handleRoles(roleMap, m, name);
            // handle methods that are not auth constrained
            handleNoAuth(unchecked, m, name);
            // handle transport constraints
            handleConnections(unchecked, m, name);
        }
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, "JACC: constraint capture: end processing qualified url patterns");
        Enumeration e = excluded.elements();
        while (e.hasMoreElements()) {
            Permission p = (Permission) e.nextElement();
            String ptype = (p instanceof WebResourcePermission) ? "WRP  " : "WUDP ";
            logger.log(Level.FINE, "JACC: permission(excluded) type: " + ptype + " name: " + p.getName() + " actions: " + p.getActions());
        }
        e = unchecked.elements();
        while (e.hasMoreElements()) {
            Permission p = (Permission) e.nextElement();
            String ptype = (p instanceof WebResourcePermission) ? "WRP  " : "WUDP ";
            logger.log(Level.FINE, "JACC: permission(unchecked) type: " + ptype + " name: " + p.getName() + " actions: " + p.getActions());
        }
    }
    pc.addToExcludedPolicy(excluded);
    pc.addToUncheckedPolicy(unchecked);
    for (Map.Entry<String, Permissions> rVal : roleMap.entrySet()) {
        String role = rVal.getKey();
        Permissions pCollection = rVal.getValue();
        pc.addToRole(role, pCollection);
        if (logger.isLoggable(Level.FINE)) {
            Enumeration e = pCollection.elements();
            while (e.hasMoreElements()) {
                Permission p = (Permission) e.nextElement();
                String ptype = (p instanceof WebResourcePermission) ? "WRP  " : "WUDP ";
                logger.log(Level.FINE, "JACC: permission(" + role + ") type: " + ptype + " name: " + p.getName() + " actions: " + p.getActions());
            }
        }
    }
    if (logger.isLoggable(Level.FINE)) {
        logger.exiting("WebPermissionUtil", "processConstraints");
    }
}
Also used : WebResourcePermission(javax.security.jacc.WebResourcePermission) Permissions(java.security.Permissions) WebRoleRefPermission(javax.security.jacc.WebRoleRefPermission) WebUserDataPermission(javax.security.jacc.WebUserDataPermission) Permission(java.security.Permission) WebResourcePermission(javax.security.jacc.WebResourcePermission)

Example 40 with Permission

use of java.security.Permission in project Bytecoder by mirkosertic.

the class HttpURLConnection method getPermission.

/**
 * Returns a {@link SocketPermission} object representing the
 * permission necessary to connect to the destination host and port.
 *
 * @exception IOException if an error occurs while computing
 *            the permission.
 *
 * @return a {@code SocketPermission} object representing the
 *         permission necessary to connect to the destination
 *         host and port.
 */
public Permission getPermission() throws IOException {
    int port = url.getPort();
    port = port < 0 ? 80 : port;
    String host = url.getHost() + ":" + port;
    Permission permission = new SocketPermission(host, "connect");
    return permission;
}
Also used : Permission(java.security.Permission)

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