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));
}
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;
}
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;
}
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");
}
}
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;
}
Aggregations