fix property expansion for small expansions and add support back in for '/' expansion as per spec
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@499 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
ff0c4b3f2e
commit
1612cbc9be
|
@ -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<ProtectionDomain> i = pdMapping.keySet().iterator(); i.hasNext();)
|
||||
//{
|
||||
// System.out.println(i.next().toString());
|
||||
//}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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" );
|
||||
|
|
Loading…
Reference in New Issue