289145 reload functionality to jetty policy an remove refresh() calls from constructor
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@860 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
d627905f4b
commit
1dd4d93527
|
@ -57,6 +57,7 @@ import org.eclipse.jetty.util.Scanner;
|
|||
public class JettyPolicy extends Policy
|
||||
{
|
||||
private static boolean __DEBUG = false;
|
||||
private static boolean __RELOAD = false;
|
||||
|
||||
// Policy files that are actively managed by the aggregate policy mechanism
|
||||
private final Set<String> _policies;
|
||||
|
@ -67,36 +68,42 @@ public class JettyPolicy extends Policy
|
|||
|
||||
private final PolicyContext _context = new PolicyContext();
|
||||
|
||||
private final Scanner scanner = new Scanner();
|
||||
private Boolean _initialized = false;
|
||||
|
||||
private boolean initialized = false;
|
||||
private Scanner _scanner;
|
||||
|
||||
public JettyPolicy(Set<String> policies, Map<String, String> properties)
|
||||
{
|
||||
System.out.println("Activating the JettyPolicy");
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
__RELOAD = Boolean.getBoolean("org.eclipse.jetty.policy.RELOAD");
|
||||
__DEBUG = Boolean.getBoolean("org.eclipse.jetty.policy.DEBUG");
|
||||
}
|
||||
catch (AccessControlException ace)
|
||||
{
|
||||
__RELOAD = false;
|
||||
__DEBUG = false;
|
||||
}
|
||||
|
||||
_policies = policies;
|
||||
_context.setProperties(properties);
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionCollection getPermissions(ProtectionDomain domain)
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
|
||||
refresh();
|
||||
if (!_initialized)
|
||||
{
|
||||
synchronized (_initialized)
|
||||
{
|
||||
// make sure we haven't been initialized since obtaining lock
|
||||
if (!_initialized)
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_cache.containsKey(domain))
|
||||
|
@ -158,11 +165,15 @@ public class JettyPolicy extends Policy
|
|||
@Override
|
||||
public PermissionCollection getPermissions(CodeSource codesource)
|
||||
{
|
||||
if (!initialized)
|
||||
if (!_initialized)
|
||||
{
|
||||
synchronized (this)
|
||||
synchronized (_initialized)
|
||||
{
|
||||
refresh();
|
||||
// make sure we haven't been initialized since obtaining lock
|
||||
if (!_initialized)
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,10 +233,15 @@ public class JettyPolicy extends Policy
|
|||
public boolean implies(ProtectionDomain domain, Permission permission) {
|
||||
PermissionCollection pc;
|
||||
|
||||
if (_cache == null) {
|
||||
synchronized (_cache)
|
||||
if (!_initialized)
|
||||
{
|
||||
synchronized (_initialized)
|
||||
{
|
||||
refresh();
|
||||
// make sure we haven't been initialized since obtaining lock
|
||||
if (!_initialized)
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,22 +301,21 @@ public class JettyPolicy extends Policy
|
|||
|
||||
try
|
||||
{
|
||||
if (!initialized)
|
||||
// initialize the reloading mechanism if enabled
|
||||
if (__RELOAD && _scanner == null)
|
||||
{
|
||||
initialize();
|
||||
initializeReloading();
|
||||
}
|
||||
|
||||
synchronized (_cache)
|
||||
{
|
||||
for (Iterator<Object> i = _cache.keySet().iterator(); i.hasNext();)
|
||||
{
|
||||
System.out.println(i.next().toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (__DEBUG)
|
||||
{
|
||||
System.out.println("refreshing policy files");
|
||||
synchronized (_cache)
|
||||
{
|
||||
for (Iterator<Object> i = _cache.keySet().iterator(); i.hasNext();)
|
||||
{
|
||||
System.out.println(i.next().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Set<PolicyBlock> clean = new HashSet<PolicyBlock>();
|
||||
|
@ -318,12 +333,7 @@ public class JettyPolicy extends Policy
|
|||
_grants.addAll(clean);
|
||||
_cache.clear();
|
||||
}
|
||||
|
||||
if (__DEBUG)
|
||||
{
|
||||
System.out.println("finished reloading policies");
|
||||
}
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -331,17 +341,9 @@ public class JettyPolicy extends Policy
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO make this optional MUST be only called from refresh or race condition
|
||||
*/
|
||||
private synchronized void initialize() throws Exception
|
||||
private void initializeReloading() throws Exception
|
||||
{
|
||||
|
||||
// if we have been initialized since we got lock, return
|
||||
if (initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_scanner = new Scanner();
|
||||
|
||||
List<File> scanDirs = new ArrayList<File>();
|
||||
|
||||
|
@ -351,33 +353,34 @@ public class JettyPolicy extends Policy
|
|||
scanDirs.add(policyFile.getParentFile());
|
||||
}
|
||||
|
||||
scanner.addListener(new Scanner.DiscreteListener()
|
||||
_scanner.addListener(new Scanner.DiscreteListener()
|
||||
{
|
||||
|
||||
public void fileRemoved(String filename) throws Exception
|
||||
{ // TODO Auto-generated method stub
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* will trigger when files are changed, not on load time, just when changed */
|
||||
public void fileChanged(String filename) throws Exception
|
||||
{
|
||||
if (filename.endsWith("policy"))
|
||||
if (filename.endsWith("policy")) // TODO match up to existing policies to avoid unnecessary reloads
|
||||
{
|
||||
System.out.println("JettyPolicy: refreshing policy files");
|
||||
refresh();
|
||||
System.out.println("JettyPolicy: finished refreshing policies");
|
||||
}
|
||||
}
|
||||
|
||||
public void fileAdded(String filename) throws Exception
|
||||
{ // TODO Auto-generated method stub
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
scanner.setScanDirs(scanDirs);
|
||||
scanner.start();
|
||||
scanner.setScanInterval(10);
|
||||
|
||||
initialized = true;
|
||||
_scanner.setScanDirs(scanDirs);
|
||||
_scanner.start();
|
||||
_scanner.setScanInterval(10);
|
||||
}
|
||||
|
||||
public void dump(PrintStream out)
|
||||
|
|
|
@ -51,6 +51,7 @@ public class JettyPolicyConfigurator
|
|||
System.out.println("Initializing Jetty Policy");
|
||||
|
||||
JettyPolicy jpolicy = new JettyPolicy( _policies, _properties );
|
||||
jpolicy.refresh();
|
||||
Policy.setPolicy(jpolicy);
|
||||
System.setSecurityManager(new SecurityManager());
|
||||
}
|
||||
|
|
|
@ -153,9 +153,9 @@ public class Config
|
|||
/**
|
||||
* Natural language sorting for key names.
|
||||
*/
|
||||
private Comparator<String> keySorter = new Comparator<String>()
|
||||
private final Comparator<String> keySorter = new Comparator<String>()
|
||||
{
|
||||
private Collator collator = Collator.getInstance();
|
||||
private final Collator collator = Collator.getInstance();
|
||||
|
||||
public int compare(String o1, String o2)
|
||||
{
|
||||
|
@ -167,11 +167,11 @@ public class Config
|
|||
|
||||
private static final String _version;
|
||||
private static boolean DEBUG = false;
|
||||
private Map<String, Classpath> _classpaths = new HashMap<String, Classpath>();
|
||||
private List<String> _xml = new ArrayList<String>();
|
||||
private Set<String> _policies = new HashSet<String>();
|
||||
private final Map<String, Classpath> _classpaths = new HashMap<String, Classpath>();
|
||||
private final List<String> _xml = new ArrayList<String>();
|
||||
private final Set<String> _policies = new HashSet<String>();
|
||||
private String _classname = null;
|
||||
private Set<String> _activeOptions = new TreeSet<String>(new Comparator<String>()
|
||||
private final Set<String> _activeOptions = new TreeSet<String>(new Comparator<String>()
|
||||
{
|
||||
// Make sure "*" is always at the end of the list
|
||||
public int compare(String o1, String o2)
|
||||
|
@ -187,7 +187,7 @@ public class Config
|
|||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
private Map<String, String> _properties = new HashMap<String, String>();
|
||||
private final Map<String, String> _properties = new HashMap<String, String>();
|
||||
private int argCount = 0;
|
||||
|
||||
private boolean addClasspathComponent(List<String> sections, String component)
|
||||
|
@ -959,6 +959,8 @@ public class Config
|
|||
|
||||
if (policyClass instanceof Policy)
|
||||
{
|
||||
Policy p = (Policy)policyClass;
|
||||
p.refresh();
|
||||
return (Policy)policyClass;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue