river-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter <j...@zeus.net.au>
Subject Neat little piece of code.
Date Wed, 11 Apr 2018 07:38:12 GMT
Hello Apache River,

Since there are some 1200 qa tests in River's QA test suite, ammending 
policy files can be quite a chore.

When you take into account that these tests can be run with different 
endpoints, JERI, JRMP, JSSE, Kerberos, and it can be persistant, 
activatable or transient, the number of tests explodes.

The old way of manually adding permissions by trial and error doesn't 
cut it, even my security policy file generator, which appends all 
missing permissions into a file, is a pain; after running so many tests, 
policy files contain thousands of lines and duplicates.

So I wrote this neat little tool appended below to tidy up policy 
files.   Now I can have policy files, with all permissions grants neatly 
arranged with far less hassle.

In the past we only ran the qa suite with JERI in transient mode, right 
now, I'm running a number of JSSE tests in transient mode.  Unusually 
when I run with JERI in activatable or transient mode, the tests, pass, 
as does JSSE in transient mode, however when I run the tests activatable 
with JSSE, I have test failures...



public class PolicyCondenser {

     public static void main(String [] args) throws Exception{
     PolicyCondenser condenser = new PolicyCondenser();
     for (int i = 0, l = args.length; i < l; i++){

     private PolicyCondenser()

     private static File policyFile(String filename) throws 

     File policyFile = new File(filename);
     if (!policyFile.exists()){
         try {
         } catch (IOException ex) {
         throw new RuntimeException("Unable to create a policy file: " + 
filename, ex);
         return policyFile;

     private void condense(String arg) throws Exception {
     File policy = policyFile(arg);
     File condensedPolicy = policyFile(arg + ".con");
     PolicyParser parser = new DefaultPolicyParser();
     Collection<PermissionGrant> grantsCol = 
parser.parse(policy.toURI().toURL(), System.getProperties());
     PermissionGrant [] grants = grantsCol.toArray(new 
     int length = grants.length;
     Collection<PermissionGrantBuilder> builders = new 
     for (int i = 0; i < length; i++){
         if (grants[i] == null) continue;
         PermissionGrantBuilder builder = grants[i].getBuilderTemplate();
         Collection<Permission> permissions = new 
TreeSet<Permission>(new PermissionComparator());
         for (int j = 0; j < length; j++){
         if (i == j || grants[j] == null) continue;
         if (grants[i].impliesEquivalent(grants[j])){
             grants[j] = null;
         grants[i] = null;
     PrintWriter pw = new PrintWriter(new BufferedWriter(new 
FileWriter(condensedPolicy, true)));
     Iterator<PermissionGrantBuilder> builderIt = builders.iterator();
         pw.print("grant ");


View raw message