diff --git a/jetty-policy/src/main/java/org/eclipse/jetty/policy/JettyPolicy.java b/jetty-policy/src/main/java/org/eclipse/jetty/policy/JettyPolicy.java index 9f0b18678d7..9b8bfea38d4 100644 --- a/jetty-policy/src/main/java/org/eclipse/jetty/policy/JettyPolicy.java +++ b/jetty-policy/src/main/java/org/eclipse/jetty/policy/JettyPolicy.java @@ -18,6 +18,8 @@ package org.eclipse.jetty.policy; import java.io.File; import java.io.FileInputStream; +import java.io.PrintStream; +import java.io.PrintWriter; import java.security.CodeSource; import java.security.Permission; import java.security.PermissionCollection; @@ -58,12 +60,12 @@ import org.eclipse.jetty.policy.loader.DefaultPolicyLoader; public class JettyPolicy extends Policy { // Policy files that are actively managed by the aggregate policy mechanism - private Set _policies; + private final Set _policies; - private Map pdMapping = + private final Map pdMapping = Collections.synchronizedMap( new HashMap() ); - private PolicyContext _context = new PolicyContext(); + private final PolicyContext _context = new PolicyContext(); public JettyPolicy( Set policies, Map properties ) { @@ -74,13 +76,14 @@ public class JettyPolicy extends Policy refresh(); } + @Override public PermissionCollection getPermissions( ProtectionDomain domain ) { PermissionCollection perms = new Permissions(); for ( Iterator i = pdMapping.keySet().iterator(); i.hasNext(); ) { - ProtectionDomain pd = (ProtectionDomain) i.next(); + ProtectionDomain pd = i.next(); if ( pd.getCodeSource() == null || pd.getCodeSource().implies( domain.getCodeSource() ) && pd.getPrincipals() == null || validate( pd.getPrincipals(), domain.getPrincipals() ) ) { @@ -107,13 +110,14 @@ public class JettyPolicy extends Policy return perms; } + @Override public PermissionCollection getPermissions( CodeSource codesource ) { PermissionCollection perms = new Permissions(); for ( Iterator i = pdMapping.keySet().iterator(); i.hasNext(); ) { - ProtectionDomain pd = (ProtectionDomain) i.next(); + ProtectionDomain pd = i.next(); if ( pd.getCodeSource() == null || pd.getCodeSource().implies( codesource ) ) { @@ -168,6 +172,7 @@ public class JettyPolicy extends Policy return true; } + @Override public void refresh() { try @@ -190,4 +195,18 @@ public class JettyPolicy extends Policy e.printStackTrace(); } } + + public void dump( PrintStream out ) + { + PrintWriter write = new PrintWriter( out ); + write.println("dumping policy settings"); + + for( Iterator i = pdMapping.keySet().iterator(); i.hasNext(); ) + { + ProtectionDomain domain = i.next(); + PolicyBlock block = pdMapping.get( domain ); + write.println(domain.toString()); + } + write.flush(); + } }