Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
22   203   5   2.75
12   74   0.55   8
8     1.5  
1    
 
 
  SimplePERMISTokenParser       Line # 83 22 5 38.1% 0.3809524
 
No Tests
 
1   
2    /*
3    * Copyright (c) 2006, University of Kent
4    * All rights reserved.
5    *
6    * Redistribution and use in source and binary forms, with or without
7    * modification, are permitted provided that the following conditions are met:
8    *
9    * Redistributions of source code must retain the above copyright notice, this
10    * list of conditions and the following disclaimer.
11    *
12    * Redistributions in binary form must reproduce the above copyright notice,
13    * this list of conditions and the following disclaimer in the documentation
14    * and/or other materials provided with the distribution.
15    *
16    * 1. Neither the name of the University of Kent nor the names of its
17    * contributors may be used to endorse or promote products derived from this
18    * software without specific prior written permission.
19    *
20    * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23    * PURPOSE ARE DISCLAIMED.
24    *
25    * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32    * POSSIBILITY OF SUCH DAMAGE.
33    *
34    * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
35    * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
36    * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
37    * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
38    * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
39    * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
40    * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
41    * SERIOUS FAULTS, IN THIS SOFTWARE.
42    *
43    * 5. This license is governed, except to the extent that local laws
44    * necessarily apply, by the laws of England and Wales.
45    *
46    * Author : Gansen Zhao <gz7@kent.ac.uk> and Romain Laborde <rl59@kent.ac.uk>
47    *
48    */
49   
50    package issrg.simplePERMIS;
51   
52    import issrg.pba.AuthzTokenParser;
53    import issrg.pba.rbac.SignatureVerifier;
54    import issrg.pba.*;
55    import issrg.pba.DefaultParsedToken;
56    import issrg.pba.ParsedToken;
57    import issrg.pba.rbac.RoleBasedAuthzTokenParser;
58    import issrg.pba.rbac.RoleHierarchyPolicy;
59    import issrg.pba.Credentials;
60    import issrg.pba.rbac.PermisCredentials;
61    import issrg.pba.rbac.RoleBasedCredentials;
62    import issrg.pba.rbac.ExpirableCredentials;
63    import issrg.pba.rbac.AnyTimeValidityPeriod;
64    import issrg.pba.repository.UserEntry;
65    import issrg.utils.repository.Entry;
66    import issrg.simplePERMIS.SimplePERMISPrincipal;
67   
68   
69    import java.util.Map;
70    import java.util.Hashtable;
71    import issrg.pba.PbaException;
72   
73    import org.apache.log4j.*;// added for logging
74    /**
75    *
76    * This class implements the RoleBasedAuthTokenParser interface. It extracts role attributes from
77    * SimplePERMISToken objects and creates parsed token objects. It is the default token parser
78    * defined in issrg.pba.rbac.CustomisePERMIS.
79    *
80    * @author Romain & Gansen
81    * @see issrg.pba.rbac.CustomisePERMIS
82    */
 
83    public class SimplePERMISTokenParser implements RoleBasedAuthzTokenParser{
84   
85    Logger logger = Logger.getLogger(SimplePERMISTokenParser.class);
86   
87    protected RoleHierarchyPolicy roleHierarchy=null;
88   
 
89  8 toggle public SimplePERMISTokenParser() {}
90   
91    /**
92    * Set the Role Hierarchy Policy. The policy defines the types of the roles, the
93    * values of the roles of each type, and the hierarchical relationship between
94    * them.
95    *
96    * @param rhp is a reference to the Role Hierarchy
97    */
 
98  8 toggle public void setRoleHierarchy(RoleHierarchyPolicy rhp) {
99  8 roleHierarchy = rhp;
100    }
101   
102    /**
103    * This method sets the Auth Token parsing rules.
104    * @param m is the parsing rules of type Map with a single entry with
105    * the key issrg.pba.rbac.RoleHierarchyPolicy.class and the value being the RoleHierarchyPolicy
106    * to be used by this SimplePERMISTokenParser.
107    */
 
108  8 toggle public void setAuthTokenParsingRules(Map m) {
109  8 setRoleHierarchy((RoleHierarchyPolicy) m.get(RoleHierarchyPolicy.class));
110    }
111   
112    /**
113    * This method returns the Authorisation Token Parsing Rules, as a Map with a single entry with
114    * the key issrg.pba.rbac.RoleHierarchyPolicy.class and the value being the RoleHierarchyPolicy
115    * used by this SimplePERMISTokenParser.
116    * @return The parsing rules of type Map.
117    */
 
118  0 toggle public Map getAuthTokenParsingRules(){
119  0 Map m = new Hashtable();
120  0 m.put(RoleHierarchyPolicy.class, roleHierarchy);
121  0 return m;
122    }
123   
124   
125    /**
126    * This method decodes the credentials of type SimplePERMISToken. If the credential is already
127    * parsed, it returns, otherwise, it returns an object of type ParsedToken.
128    * @param creds - The credential to be parsed. It should be an instance of SimplePERMISToken.
129    * @return The parsed form of the credential.
130    * @throws PbaException if the credential in input is not a SimplePERMISToken.
131    *
132    */
 
133  650 toggle public ParsedToken decode(Object creds) throws PbaException {
134  650 logger.debug(" to decode "+creds.getClass().getName());
135    // If it has already be decoded
136  0 if (creds instanceof DefaultParsedToken) return (ParsedToken)creds;
137    // If it hasn't be decoded
138    // If it is not a SimplePERMISToken instance we can't decode it
139  0 if (!(creds instanceof SimplePERMISToken)) throw new PbaException("SimplePERMISToken was expected, but "+(creds==null?"null":creds.getClass().getName())+" was found");
140    // If it is a SimplePERMISToken instance we decode it
141  650 SimplePERMISToken testCreds = (SimplePERMISToken)creds;
142    // holder testCreds.getEntry()
143  650 ParsedToken tok = new DefaultParsedToken(testCreds.getHolderEntry(),
144    testCreds.getIssuerTokenLocator(),
145    new ExpirableCredentials(
146    new PermisCredentials(roleHierarchy.getRole(
147    testCreds.getAttributeType(),
148    testCreds.getAttributeValue())
149    ),
150    new AnyTimeValidityPeriod()
151    )
152    );
153  650 logger.debug("return a parsered token from SimplePERMISTokenParser");
154  650 return tok;
155    }
156   
157    /**
158    * This method decodes the credentials of type SimplePERMISToken. If the credential is already
159    * parsed, it returns, otherwise, it returns an object of type ParsedToken.
160    *
161    * @param creds - The credential to be parsed. It should be an instance of SimplePERMISToken.
162    *@param notBefore - the token validity period starting date
163    *@param notAfter - the token validity period expiry date
164    * @return The parsed form of the credential.
165    * @throws PbaException if the credential in input is not a SimplePERMISToken.
166    *
167    */
 
168  0 toggle public ParsedToken decode(Object creds,java.util.Date notBefore,java.util.Date notAfter) throws PbaException {
169   
170    // If it has already be decoded
171  0 if (creds instanceof DefaultParsedToken) return (ParsedToken)creds;
172    // If it hasn't be decoded
173    // If it is not a SimplePERMISToken instance we can't decode it
174  0 if (!(creds instanceof SimplePERMISToken)) throw new PbaException("SimplePERMISToken was expected, but "+(creds==null?"null":creds.getClass().getName())+" was found");
175    // If it is a SimplePERMISToken instance we decode it
176  0 SimplePERMISToken testCreds = (SimplePERMISToken)creds;
177    // holder testCreds.getEntry()
178  0 ParsedToken tok = new DefaultParsedToken(testCreds.getHolderEntry(),
179    testCreds.getIssuerTokenLocator(),
180    new ExpirableCredentials(
181    new PermisCredentials(roleHierarchy.getRole(
182    testCreds.getAttributeType(),
183    testCreds.getAttributeValue())
184    ),
185    new issrg.pba.rbac.AbsoluteValidityPeriod(notBefore,notAfter)
186    )
187    );
188  0 return tok;
189    }
190   
191   
192   
193   
194    /**
195    * This method sets the signature verifier for the parser. Since SimplePERMISTokenParser
196    * does not care about signatures (SimplePERMISToken doesn't provide any signature), the method simply discards the input parameter
197    * and return true.
198    */
 
199  8 toggle public void setSignatureVerifier(SignatureVerifier sv){}
 
200  0 toggle public SignatureVerifier getSignatureVerifier(){
201  0 return null;
202    }
203    }