consolidate log and debug into methods I can handle logging issues in based on this being loaded at potentially different instances where logging permissions may not exist at the moment

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2662 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Jesse McConnell 2011-01-14 21:17:18 +00:00
parent 5a5e3ad482
commit 639223361a
2 changed files with 86 additions and 20 deletions

View File

@ -39,6 +39,7 @@ import java.util.Set;
import org.eclipse.jetty.policy.loader.DefaultPolicyLoader; import org.eclipse.jetty.policy.loader.DefaultPolicyLoader;
import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.Scanner;
import org.eclipse.jetty.util.log.Log;
/** /**
@ -123,16 +124,23 @@ public class JettyPolicy extends Policy
if (__DEBUG) if (__DEBUG)
{ {
System.out.println("----START----"); debug("----START----");
System.out.println("PDCS: " + policyBlock.getCodeSource()); debug("PDCS: " + policyBlock.getCodeSource());
System.out.println("CS: " + domain.getCodeSource()); debug("CS: " + domain.getCodeSource());
} }
// 1) if protection domain codesource is null, it is the global permissions (grant {}) // 1) if protection domain codesource is null, it is the global permissions (grant {})
// 2) if protection domain codesource implies target codesource and there are no prinicpals // 2) if protection domain codesource implies target codesource and there are no prinicpals
// 2) if protection domain codesource implies target codesource and principals align // 2) if protection domain codesource implies target codesource and principals align
if (grantPD.getCodeSource() == null || grantPD.getCodeSource().implies(domain.getCodeSource()) && grantPD.getPrincipals() == null || grantPD.getCodeSource().implies(domain.getCodeSource()) if (grantPD.getCodeSource() == null
&& validate(grantPD.getPrincipals(),domain.getPrincipals())) ||
grantPD.getCodeSource().implies(domain.getCodeSource())
&&
grantPD.getPrincipals() == null
||
grantPD.getCodeSource().implies(domain.getCodeSource())
&&
validate(grantPD.getPrincipals(),domain.getPrincipals()))
{ {
for (Enumeration<Permission> e = policyBlock.getPermissions().elements(); e.hasMoreElements();) for (Enumeration<Permission> e = policyBlock.getPermissions().elements(); e.hasMoreElements();)
@ -140,14 +148,14 @@ public class JettyPolicy extends Policy
Permission perm = e.nextElement(); Permission perm = e.nextElement();
if (__DEBUG) if (__DEBUG)
{ {
System.out.println("D: " + perm); debug("D: " + perm);
} }
perms.add(perm); perms.add(perm);
} }
} }
if (__DEBUG) if (__DEBUG)
{ {
System.out.println("----STOP----"); debug("----STOP----");
} }
} }
@ -182,13 +190,15 @@ public class JettyPolicy extends Policy
PolicyBlock policyBlock = i.next(); PolicyBlock policyBlock = i.next();
ProtectionDomain grantPD = policyBlock.toProtectionDomain(); ProtectionDomain grantPD = policyBlock.toProtectionDomain();
if (grantPD.getCodeSource() == null || grantPD.getCodeSource().implies(codesource)) if (grantPD.getCodeSource() == null
||
grantPD.getCodeSource().implies(codesource))
{ {
if (__DEBUG) if (__DEBUG)
{ {
System.out.println("----START----"); debug("----START----");
System.out.println("PDCS: " + grantPD.getCodeSource()); debug("PDCS: " + grantPD.getCodeSource());
System.out.println("CS: " + codesource); debug("CS: " + codesource);
} }
for (Enumeration<Permission> e = policyBlock.getPermissions().elements(); e.hasMoreElements();) for (Enumeration<Permission> e = policyBlock.getPermissions().elements(); e.hasMoreElements();)
@ -196,14 +206,14 @@ public class JettyPolicy extends Policy
Permission perm = e.nextElement(); Permission perm = e.nextElement();
if (__DEBUG) if (__DEBUG)
{ {
System.out.println("D: " + perm); debug("D: " + perm);
} }
perms.add(perm); perms.add(perm);
} }
if (__DEBUG) if (__DEBUG)
{ {
System.out.println("----STOP----"); debug("----STOP----");
} }
} }
} }
@ -251,6 +261,11 @@ public class JettyPolicy extends Policy
return true; return true;
} }
/**
* This call performs a refresh of the policy system, first processing the associated
* files and then replacing the policy cache.
*
*/
@Override @Override
public synchronized void refresh() public synchronized void refresh()
{ {
@ -269,7 +284,7 @@ public class JettyPolicy extends Policy
{ {
for (Iterator<Object> i = _cache.keySet().iterator(); i.hasNext();) for (Iterator<Object> i = _cache.keySet().iterator(); i.hasNext();)
{ {
System.out.println(i.next().toString()); log(i.next().toString());
} }
} }
} }
@ -297,6 +312,11 @@ public class JettyPolicy extends Policy
} }
} }
/**
* the scanning mechanism used to detect changes to the policy system and reload
*
* @throws Exception
*/
private void initializeReloading() throws Exception private void initializeReloading() throws Exception
{ {
_scanner = new Scanner(); _scanner = new Scanner();
@ -322,9 +342,9 @@ public class JettyPolicy extends Policy
{ {
if (filename.endsWith("policy")) // TODO match up to existing policies to avoid unnecessary reloads if (filename.endsWith("policy")) // TODO match up to existing policies to avoid unnecessary reloads
{ {
System.out.println("JettyPolicy: refreshing policy files"); log("JettyPolicy: refreshing policy files");
refresh(); refresh();
System.out.println("JettyPolicy: finished refreshing policies"); log("JettyPolicy: finished refreshing policies");
} }
} }
@ -342,7 +362,7 @@ public class JettyPolicy extends Policy
public void dump(PrintStream out) public void dump(PrintStream out)
{ {
PrintWriter write = new PrintWriter(out); PrintWriter write = new PrintWriter(out);
write.println("dumping policy settings"); write.println("JettyPolicy: policy settings dump");
synchronized (_cache) synchronized (_cache)
{ {
@ -367,4 +387,52 @@ public class JettyPolicy extends Policy
} }
return out; return out;
} }
/**
* Try and log to normal logging channels and should that not be allowed
* debug to system.out
*
* @param message
*/
private void debug( String message )
{
try
{
Log.debug(message);
}
catch ( AccessControlException ace )
{
System.out.println( "[DEBUG] " + message );
}
}
/**
* Try and log to normal logging channels and should that not be allowed
* log to system.out
*
* @param message
*/
private void log( String message )
{
log( message, null );
}
/**
* Try and log to normal logging channels and should that not be allowed
* log to system.out
*
* @param message
*/
private void log( String message, Throwable t )
{
try
{
Log.info(message, t);
}
catch ( AccessControlException ace )
{
System.out.println( message );
t.printStackTrace();
}
}
} }

View File

@ -47,9 +47,7 @@ public class JettyPolicyConfigurator
} }
public void initialize() public void initialize()
{ {
System.out.println("Initializing Jetty Policy");
JettyPolicy jpolicy = new JettyPolicy( _policies, _properties ); JettyPolicy jpolicy = new JettyPolicy( _policies, _properties );
jpolicy.refresh(); jpolicy.refresh();
Policy.setPolicy(jpolicy); Policy.setPolicy(jpolicy);