Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
173   300   64   21.62
126   229   0.41   8
8     8.88  
1    
 
 
  Interpreter       Line # 63 173 64 32.2% 0.32247558
 
No Tests
 
1    /*
2    * Copyright (c) 2006, University of Kent
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * Redistributions of source code must retain the above copyright notice, this
9    * list of conditions and the following disclaimer.
10    *
11    * Redistributions in binary form must reproduce the above copyright notice,
12    * this list of conditions and the following disclaimer in the documentation
13    * and/or other materials provided with the distribution.
14    *
15    * 1. Neither the name of the University of Kent nor the names of its
16    * contributors may be used to endorse or promote products derived from this
17    * software without specific prior written permission.
18    *
19    * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22    * PURPOSE ARE DISCLAIMED.
23    *
24    * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31    * POSSIBILITY OF SUCH DAMAGE.
32    *
33    * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
34    * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
35    * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
36    * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
37    * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
38    * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
39    * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
40    * SERIOUS FAULTS, IN THIS SOFTWARE.
41    *
42    * 5. This license is governed, except to the extent that local laws
43    * necessarily apply, by the laws of England and Wales.
44    */
45    /*
46    * Interpreter.java
47    *
48    * Created on 10 April 2006, 11:22
49    *
50    * To change this template, choose Tools | Template Manager
51    * and open the template in the editor.
52    */
53   
54    package issrg.utils.handler;
55   
56    import org.w3c.dom.*;
57    import java.util.ArrayList;
58    import java.util.Iterator;
59    /**
60    *
61    * @author ls97
62    */
 
63    public class Interpreter {
64   
65    public static int PUSH = 0;
66    public static int PULL = 1;
67    public static int INDETERMINATE = 2;
68   
69    private Node context;
70    /** Creates a new instance of Interpreter */
 
71  2 toggle public Interpreter(Node contextIn) {
72  2 this.context = contextIn;
73    }
74    /**
75    * return a valid subject DN; otherwise an empty string is returned
76    *
77    */
 
78  2 toggle public int getModel() {
79  2 if (this.context.getNodeName().equals("wst:RequestSecurityToken")) {
80  2 NodeList list = this.context.getChildNodes();
81  6 for (int i=0; i<list.getLength();i++) {
82  6 Node node = list.item(i);
83  6 if (node.getNodeName().equals("wst:Claims")) {
84  2 NamedNodeMap map = node.getAttributes();
85  2 for (int k=0; k<map.getLength(); k++) {
86  2 Node statement = map.item(k);
87  2 if (statement.getNodeName().equals("Dialect")) {
88  2 String value = statement.getNodeValue();
89  2 if (value.equals("urn:oasis:names:tc:SAML:2.0:assertion:AttributeStatementType"))
90  0 return this.PUSH;
91  2 if (value.equals("urn:oasis:names:tc:SAML:2.0:assertion:AuthnStatementType"))
92  2 return this.PULL;
93    }
94    }
95    }
96    }
97    }
98  0 return this.INDETERMINATE;
99    }
100   
 
101  4 toggle private Node getSamlAssertion() {
102  4 NodeList nodes=this.context.getChildNodes();
103  12 for (int i=0; i<nodes.getLength();i++) {
104  12 Node node = nodes.item(i);
105  0 if (Text.class.isAssignableFrom(node.getClass())) continue;
106  12 if (node.getNodeName().equals("wst:Claims")) {
107  4 NodeList children = node.getChildNodes();
108  4 for (int l=0; l<children.getLength(); l++) {
109  4 Node child = children.item(l);
110  0 if (Text.class.isAssignableFrom(child.getClass())) continue;
111  4 if (child.getNodeName().equals("saml:Assertion")) return child;
112    }
113    }
114    }
115  0 return null;
116    }
117   
 
118  2 toggle public String getSubjectDN() {
119  2 Node assertion = this.getSamlAssertion();
120  0 if (assertion==null) return null;
121  2 NodeList children = assertion.getChildNodes();
122  4 for (int i=0; i<children.getLength(); i++) {
123  4 Node node = children.item(i);
124  0 if (Text.class.isAssignableFrom(node.getClass())) continue;
125  4 if (node.getNodeName().equals("saml:Subject")) {
126  2 NodeList j = node.getChildNodes();
127  2 for (int k=0; k<j.getLength(); k++) {
128  2 Node gN = j.item(k);
129  0 if (Text.class.isAssignableFrom(gN.getClass())) continue;
130  2 if (gN.getNodeName().equals("saml:NameID")) {
131  2 NodeList fL = gN.getChildNodes();
132  2 if (fL.getLength()==1) {
133  2 Node fN = fL.item(0);
134  2 if (Text.class.isAssignableFrom(fN.getClass())) {
135  2 Text text = (Text)fN;
136  2 String str = text.getNodeValue();
137  2 return str.trim();
138    }
139    }
140    }
141    }
142    }
143    }
144  0 return null;
145    }
146   
 
147  0 toggle private String getBinaryCertificate(Node nodeIn) {
148  0 String buf = null;
149  0 if (!nodeIn.getNodeName().equals("wsse:BinarySecurityToken")) return null;
150  0 NodeList nodes=nodeIn.getChildNodes();
151  0 if (nodes.getLength()==1){
152  0 Node child = nodes.item(0);
153  0 if (Text.class.isAssignableFrom(child.getClass())) {
154  0 String result = ((Text)child).getNodeValue();
155  0 buf = result.trim();
156  0 return buf;
157    }
158    }
159  0 return buf;
160    }
161   
 
162  2 toggle public String getContextRef() {
163  2 if (this.context.getNodeName().equals("wst:RequestSecurityToken")) {
164  2 NamedNodeMap nodeMap = this.context.getAttributes();
165  4 for (int i=0;i<nodeMap.getLength();i++) {
166  2 Node node = nodeMap.item(i);
167  2 if (node.getNodeName().equals("Context")) {
168  0 String val = node.getNodeValue();
169  0 return val.trim();
170    }
171    }
172    }
173  2 return null;
174    }
175   
 
176  0 toggle public AttributeStatement[] getAttributeStatements() {
177  0 ArrayList statements = new ArrayList();
178  0 Node assertion = this.getSamlAssertion();
179  0 NodeList nodes = assertion.getChildNodes();
180  0 for (int i=0; i<nodes.getLength(); i++) {
181  0 Node node = nodes.item(i);
182  0 if (Text.class.isAssignableFrom(node.getClass())) continue;
183  0 if (node.getNodeName().equals("saml:AttributeStatement")) {
184  0 AttributeStatement attStatement = new AttributeStatement();
185  0 ArrayList list = new ArrayList();
186  0 NodeList children = node.getChildNodes();
187  0 for (int l=0;l<children.getLength();l++) {
188  0 Node ggchild = children.item(l);
189  0 if (Text.class.isAssignableFrom(ggchild.getClass())) continue;
190  0 if (ggchild.getNodeName().equals("saml:Attribute")) {
191  0 NamedNodeMap map = ggchild.getAttributes();
192  0 for (int m=0;m<map.getLength();m++) {
193  0 Node att = map.item(m);
194  0 if (att.getNodeName().equals("Name")) {
195  0 if (att.getNodeValue().equals("Repository")) {
196  0 attStatement.setAttributeName("Repository");
197  0 NodeList gggNodes = ggchild.getChildNodes();
198  0 for (int n=0;n<gggNodes.getLength();n++) {
199  0 Node gggnode = gggNodes.item(n);
200  0 if (Text.class.isAssignableFrom(gggnode.getClass())) continue;
201  0 if (gggnode.getNodeName().equals("saml:AttributeValue")) {
202  0 NodeList soapNodes = gggnode.getChildNodes();
203  0 if (soapNodes.getLength()==1) {
204  0 Node soap = soapNodes.item(0);
205  0 if (Text.class.isAssignableFrom(soap.getClass())) {
206  0 String result = ((Text)soap).getNodeValue();
207  0 attStatement.setRepository(result.trim());
208    }
209    }
210    }
211    }
212    } else {
213  0 attStatement.setAttributeName(att.getNodeValue());
214  0 NodeList gggNodes = ggchild.getChildNodes();
215  0 for (int n=0;n<gggNodes.getLength();n++) {
216  0 Node gggnode = gggNodes.item(n);
217  0 if (Text.class.isAssignableFrom(gggnode.getClass())) continue;
218  0 if (gggnode.getNodeName().equals("saml:AttributeValue")) {
219  0 NodeList soapNodes = gggnode.getChildNodes();
220  0 for (int j=0; j<soapNodes.getLength(); j++) {
221  0 Node value = soapNodes.item(j);
222  0 if (Text.class.isAssignableFrom(value.getClass())) continue;
223  0 list.add(this.getBinaryCertificate(value));
224    }
225    }
226    }
227    }
228    }
229    }
230    }
231    }
232  0 String[] binary = new String[list.size()];
233  0 binary = (String[])list.toArray(binary);
234  0 attStatement.setBinaryTokens(binary);
235  0 statements.add(attStatement);
236    }
237    }
238  0 AttributeStatement [] as = new AttributeStatement[statements.size()];
239  0 as = (AttributeStatement[])statements.toArray(as);
240  0 return as;
241    }
242   
 
243  2 toggle public SubjectAttributeReference[] getSubAttrRefs() {
244  2 ArrayList references = new ArrayList();
245  2 Node assertion = this.getSamlAssertion();
246  2 NodeList nodes = assertion.getChildNodes();
247  8 for (int i=0; i<nodes.getLength(); i++) {
248  6 Node node = nodes.item(i);
249  0 if (Text.class.isAssignableFrom(node.getClass())) continue;
250  6 if (node.getNodeName().equals("saml:Advice")) {
251  0 ArrayList list = new ArrayList();
252  0 NodeList children = node.getChildNodes();
253  0 for (int l=0;l<children.getLength();l++) {
254  0 Node ggchild = children.item(l);
255  0 if (Text.class.isAssignableFrom(ggchild.getClass())) continue;
256  0 if (ggchild.getNodeName().equals("SubjectAttributeReferenceAdvice")) {
257  0 NodeList gggNodes = ggchild.getChildNodes();
258  0 for (int m=0;m<gggNodes.getLength();m++) {
259  0 Node gggnode = gggNodes.item(m);
260  0 if (Text.class.isAssignableFrom(gggnode.getClass())) continue;
261  0 if (gggnode.getNodeName().equals("ogsa-saml2:SubjectAttributeReference")) {
262  0 NamedNodeMap map = gggnode.getAttributes();
263  0 for (int n=0; n<map.getLength(); n++) {
264  0 Node attr = map.item(n);
265  0 if (attr.getNodeName().equals("Reference")) {
266  0 String uri = attr.getNodeValue();
267  0 NodeList attrChildren = attr.getChildNodes();
268  0 ArrayList atts = new ArrayList();
269  0 for (int j=0; j<attrChildren.getLength(); j++) {
270  0 Node g4Node = attrChildren.item(j);
271  0 if (Text.class.isAssignableFrom(g4Node.getClass())) continue;
272  0 if (g4Node.getNodeName().equals("saml:AttributeDesignator")) {
273  0 NamedNodeMap attOfAttrDes = g4Node.getAttributes();
274  0 for (int k=0; k<attOfAttrDes.getLength(); k++) {
275  0 Node attType = attOfAttrDes.item(k);
276  0 if (attType.getNodeName().equals("AttributeName")) {
277  0 String val = attType.getNodeValue();
278  0 val = val.trim();
279  0 atts.add(val);
280    }
281    }
282    }
283    }
284  0 String[] attNames = new String[atts.size()];
285  0 attNames = (String[])atts.toArray(attNames);
286  0 SubjectAttributeReference subAttRef = new SubjectAttributeReference(uri,attNames);
287  0 references.add(subAttRef);
288    }
289    }
290    }
291    }
292    }
293    }
294    }
295    }
296  2 SubjectAttributeReference [] sar = new SubjectAttributeReference[references.size()];
297  2 sar = (SubjectAttributeReference[])references.toArray(sar);
298  2 return sar;
299    }
300    }