Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
74   227   17   9.25
16   125   0.32   8
8     3  
1    
 
 
  PushSimplePERMISTokenWithEmptyDN       Line # 32 74 17 73.5% 0.7346939
 
No Tests
 
1    /*
2    * PushSimpePERMISTokenWithEmptyDN.java
3    *
4    * Created on 01 August 2007, 16:00
5    *
6    * To change this template, choose Tools | Template Manager
7    * and open the template in the editor.
8    */
9   
10    package issrg.test.emptyDN;
11   
12    import issrg.pba.PbaException;
13    import issrg.pba.Response;
14    import issrg.pba.rbac.PermisAction;
15    import issrg.pba.rbac.PermisRBAC;
16    import issrg.pba.rbac.PermisTarget;
17    import issrg.simplePERMIS.SimplePERMISPolicyFinder;
18    import issrg.simplePERMIS.SimplePERMISToken;
19    import issrg.simplePERMIS.SimplePERMISTokenParser;
20    import issrg.utils.repository.Entry;
21    import issrg.pba.Subject;
22    import issrg.utils.handler.Config;
23    import issrg.utils.handler.ConfigException;
24   
25    import java.util.*;
26    import java.io.*;
27   
28    /**
29    *
30    * @author Linying Su
31    */
 
32    public class PushSimplePERMISTokenWithEmptyDN {
33   
34    /** Creates a new instance of PushSimpePERMISTokenWithEmptyDN */
 
35  0 toggle public PushSimplePERMISTokenWithEmptyDN() {
36    }
37    private SimplePERMISTokenParser testParserTok = null;
38   
39    private static PermisRBAC adf = null;
40    private static SimplePERMISPolicyFinder ssampf=null;
41   
42    private static Subject subject=null;
43    private static PermisAction action=null;
44    private static PermisTarget target=null;
45    private static PrintStream out = System.out;
46    private static InputStream in = null;
47    /**
48    * this method is used to test Simple Permis to pull subject attributes with an empty DN
49    * it should return an empty set.
50    */
51   
 
52  1 toggle public static void main(String[] args) {
53   
54  1 System.setProperty("line.separator", "\r\n");
55   
56  1 String policy = null;
57  1 String role = null;
58  1 String action = null;
59  1 String target = null;
60   
61  1 if (args.length==2){
62  1 Config config = new Config();
63  1 try{
64  1 in = new FileInputStream(config.getURL(args[0]));
65  1 out = new PrintStream(new FileOutputStream(args[1]));
66   
67  1 Properties props = new Properties();
68  1 props.load(in);
69  1 policy = props.getProperty("policy");
70  1 role = props.getProperty("role");
71  1 action = props.getProperty("action");
72  1 target = props.getProperty("target");
73   
74  1 in.close();
75   
76    } catch(IOException ioe){
77  0 out.println("This shouldn't have happened! "+ioe.getMessage());
78    } catch(ConfigException ce){
79  0 out.println("This shouldn't have happened! "+ce.getMessage());
80    }
81    }
82   
83    /*
84    policy = "/home/policy/permis/policyForRegressiontest.xml";
85    role = "researcher";
86    action = "stop";
87    target = "CN=simu,OU=GlobusTest,O=Grid";
88   
89    try {
90    out = new PrintStream(new FileOutputStream("EmptyDNPushSimP.out"));
91    } catch (FileNotFoundException fe) {
92    System.out.println("error: "+fe);
93    }
94    */
95   
96  1 if (loadPolicy(policy)) out.println("policy is loaded");
97  1 if (constructADF()) out.println("PDP is created");
98  1 if (constructSubject(role)) out.println("Subject (role = "+role+") is created");
99  1 if (constructAction(action)) out.println("Action (name = "+action+") is created");
100  1 if (constructTarget(target)) out.println("Target (DN = "+target+") is created");
101  1 try {
102  1 Response res = consult();
103  1 if (res.isAuthorised()) out.println("Permit");
104  0 else out.println("Deny");
105    } catch (PbaException pe) {
106  0 out.println("error: "+pe);
107    }
108  1 out.close();
109    }
110   
111    /**
112    * This function loads the specified policy from an plain xml file.
113    *
114    * @param pathNameofPolicy - The Full file name of the policy file. The file name shall include
115    * the path to allow java vm to locate the file.
116    */
 
117  1 toggle public static boolean loadPolicy(String pathNameofPolicy){
118  1 try{
119  1 ssampf = new SimplePERMISPolicyFinder(pathNameofPolicy);
120    }catch (Exception e){
121  0 out.println("Exception was thrown in loading policy!");
122  0 out.println(e.getMessage());
123  0 ssampf=null;
124    }catch(Throwable th){
125  0 out.println("Throwable was thrown in loading policy!");
126  0 out.println(th.getMessage());
127  0 ssampf=null;
128    }
129   
130  1 if (ssampf == null){
131  0 out.println("Null PolicyFinder was returned!");
132  0 return false;
133    }
134  1 return true;
135    }
136   
137    /**
138    * Contruct the Authorization Decision Function object. This shall be after the policy is loaded.
139    * @return True -- when sucessfully construct the ADF. Otherwise false.
140    */
 
141  1 toggle public static boolean constructADF(){
142    //public static boolean constructADF() throws PbaException {
143  1 try{
144  1 adf = new PermisRBAC(ssampf);
145    } catch(PbaException pe){
146  0 out.println(pe.getMessage());
147  0 return false;
148    }
149   
150  1 return true;
151    }
152   
153   
154    /**
155    * Construct a permis subject object that represents the subject who is going to perform the action
156    * @param userDN user's DN
157    * @param roleValue the value of user's permisRole attribute
158    * @param issuerLDAPDN the DN of the issuer of the role
159    */
 
160  1 toggle public static boolean constructSubject(String roleValue){
161   
162    //create subject
163   
164  1 subject=null;
165   
166  1 SimplePERMISToken subjectToken=null;
167   
168   
169  1 String roleType = "";
170   
171  1 roleType = "permisRole";
172   
173  1 subjectToken = new SimplePERMISToken("", "", roleType, roleValue);
174   
175  1 Vector newCreds = new Vector();
176   
177    // create the credentials of principal, i.e., (user <-> roles) issued by issuer
178    // In this case the credentials will be decoded when when getCreds method is launched
179    // Credentials can also be decoded here doing newCreds.add(testParserTok.decode(principal));
180   
181  1 newCreds.add(subjectToken);
182  1 try{
183    // create the subject, i.e. the entity (the roles) recognized by permis to take the decisions.
184  1 subject = adf.getCreds(subjectToken.getHolderEntry().getEntryName(), newCreds.toArray());
185    }catch(PbaException pbaE){
186  0 subject=null;
187  0 return false;
188    }
189   
190  1 return true;
191    }
192   
 
193  1 toggle public static boolean constructAction(String actionName){
194   
195    //create action
196  1 action=null;
197    //String strAction = "";
198    //actionName = "Action0";
199    //System.out.println("action : " +strAction);
200  1 action = new PermisAction(actionName);
201   
202  1 return true;
203    }
204   
 
205  1 toggle public static boolean constructTarget(String targetDN){
206    //create target
207  1 target = null;
208    //String targetDN = "";
209    //targetDN = "cn=object0, o=permis, c=gb";
210    //System.out.println("targetDN : " +targetDN);
211  1 try{
212  1 target = new PermisTarget(targetDN, null);
213    }catch(issrg.utils.RFC2253ParsingException rfcExc){
214  0 return false;
215    }
216   
217  1 return true;
218    //return false;
219    }
220   
221   
 
222  1 toggle public static Response consult() throws PbaException{
223   
224  1 return adf.authzDecision(subject,action,target,null);
225   
226    }
227    }