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 cb513935f07..9f0b18678d7 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 @@ -179,6 +179,11 @@ public class JettyPolicy extends Policy File policyFile = new File( i.next() ); pdMapping.putAll( DefaultPolicyLoader.load( new FileInputStream( policyFile ), _context ) ); } + + //for ( Iterator i = pdMapping.keySet().iterator(); i.hasNext();) + //{ + // System.out.println(i.next().toString()); + //} } catch ( Exception e ) { diff --git a/jetty-policy/src/main/java/org/eclipse/jetty/policy/PolicyContext.java b/jetty-policy/src/main/java/org/eclipse/jetty/policy/PolicyContext.java index 88d35c5eda9..2f01c4099f1 100644 --- a/jetty-policy/src/main/java/org/eclipse/jetty/policy/PolicyContext.java +++ b/jetty-policy/src/main/java/org/eclipse/jetty/policy/PolicyContext.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.policy; //You may elect to redistribute this code under either of these licenses. //======================================================================== +import java.io.File; import java.security.KeyStore; import java.security.Principal; import java.security.cert.Certificate; @@ -29,6 +30,12 @@ public class PolicyContext private Principal[] principals; private KeyStore keystore; + public PolicyContext() + { + // special property case for resolving ${/} to native separator + properties.put( "/", File.separator ); + } + public void addProperty( String name, String value ) { this.properties.put( name, value ); @@ -68,13 +75,17 @@ public class PolicyContext while (s!=null) { - i1=s.indexOf("${",i2); + System.out.println("Reviewing: " + s ); + //i1=s.indexOf("${",i2); + i1=s.indexOf("${"); + System.out.println("i1:" + i1); if (i1<0) { break; } i2=s.indexOf("}",i1+2); + System.out.println("i2:" + i2); if (i2<0) { break; @@ -83,6 +94,8 @@ public class PolicyContext String property=getProperty(s.substring(i1+2,i2)); s=s.substring(0,i1)+property+s.substring(i2+1); + + System.out.println("expanded to: " + s); } return s; @@ -95,7 +108,7 @@ public class PolicyContext while (s!=null) { - i1=s.indexOf("${{",i2); + i1=s.indexOf("${{"); if (i1<0) { break; diff --git a/jetty-policy/src/test/java/org/eclipse/jetty/policy/TestPolicyContext.java b/jetty-policy/src/test/java/org/eclipse/jetty/policy/TestPolicyContext.java index 265e588bb7c..1846b5e9ee8 100644 --- a/jetty-policy/src/test/java/org/eclipse/jetty/policy/TestPolicyContext.java +++ b/jetty-policy/src/test/java/org/eclipse/jetty/policy/TestPolicyContext.java @@ -103,6 +103,19 @@ public class TestPolicyContext assertEquals( __PRINCIPAL, perm.getName() ); } + public void testFileSeparatorExpansion() throws Exception + { + PolicyContext context = new PolicyContext(); + context.addProperty( "foo", "bar" ); + + assertEquals(File.separator, context.evaluate( "${/}" ) ); + + assertEquals(File.separator + "bar" + File.separator, context.evaluate( "${/}${foo}${/}" ) ); + + + assertEquals(File.separator + File.separator, context.evaluate( "${/}${/}" ) ); + } + private String getWorkingDirectory() { String cwd = System.getProperty( "basedir" );