Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
24   160   5   1.6
6   60   0.79   15
15     1.27  
1    
 
 
  URLPrincipal       Line # 47 24 5 64.4% 0.64444447
 
No Tests
 
1    /*
2    * Copyright (c) 2000-2005, University of Salford
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    * Neither the name of the University of Salford 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    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29    * POSSIBILITY OF SUCH DAMAGE.
30    */
31   
32    package issrg.pba.rbac;
33   
34    import issrg.utils.ParsedURL;
35   
36    /**
37    * This class implements a Principal interface, so it can be used as an
38    * identifier. It also implements an Entry interface, so it can be used
39    * for Domain matching as well.
40    *
41    * <p>Some of the methods do not have any description, because they simply
42    * redirect the calls to ParsedURL object, so refer to the description of that
43    * class to see the meaning of the results.
44    *
45    * @author A.Otenko
46    */
 
47    public class URLPrincipal implements java.security.Principal,
48    issrg.utils.repository.Entry {
49    ParsedURL pu;
50    int port=-1; // no port has been specified
51   
 
52  0 toggle protected URLPrincipal(){}
53   
54    /**
55    * This constructor builds a URLPrincipal out of a URL string, and assumes
56    * the defaul port is unknown (getPort() will return -1, if the URL does not
57    * specify the port number).
58    *
59    * <p>This is equivalent to new URLPrincipal(url, -1);
60    *
61    * @param url is the string URL
62    *
63    * @throws BadURLException if the url is not a well-formed HTTP or FILE URL
64    */
 
65  9 toggle public URLPrincipal(String url) throws BadURLException {
66  9 this(url, -1);
67    }
68   
69    /**
70    * This constructor builds a URLPrincipal given a URL string, and a default
71    * port number.
72    *
73    * @param url is the string URL
74    * @param defaultPort is the number of the default port to assume if URL does
75    * not
76    * specify any port number
77    *
78    * @throws BadURLException if the url is not a well-formed HTTP or FILE URL
79    */
 
80  66 toggle public URLPrincipal(String url, int defaultPort) throws BadURLException {
81  66 Exception e=null;
82   
83  66 pu=ParsedURL.parseURL(url);
84  66 try{
85  66 if (pu!=null)
86  0 if (pu.getPort()!=null) port=Integer.parseInt(pu.getPort()); // try to parse the port number
87  66 else port=defaultPort; // pu.getPort()==null - use default port
88    } catch (NumberFormatException nfe){
89  0 pu=null; // next line will throw an exception
90  0 e=nfe;
91    }
92   
93  0 if (pu==null) throw new BadURLException("Malformed URL: "+url, e); // embed root cause, if any
94    }
95   
96    /**
97    * This method returns a normalised URL (i.e.&nbsp;the path is without '.' and
98    * '..' elements, etc.)
99    */
 
100  119 toggle public String getName(){
101  119 return pu.getNormalizedURL();
102    }
103   
 
104  1023 toggle public java.security.Principal getEntryName(){
105  1023 return this;
106    }
107   
108   
 
109  510 toggle public String getProtocol(){
110  510 return pu.getProtocol();
111    }
112   
 
113  906 toggle public String getUserName(){
114  906 return pu.getUserName();
115    }
116   
 
117  906 toggle public String getPassword(){
118  906 return pu.getPassword();
119    }
120   
 
121  770 toggle public String getHost(){
122  770 return pu.getHost();
123    }
124   
125    /**
126    * This method returns a port number. Returns -1, if no port has been
127    * specified
128    * in the URL or in the constructor (use default).
129    *
130    * @return the port number, or -1, if no port has been specified in the URL
131    */
 
132  453 toggle public int getPort(){
133  453 return port;
134    }
135   
 
136  453 toggle public String [] getPath(){
137  453 return pu.getPath();
138    }
139   
 
140  0 toggle public String [] getOriginalPath(){
141  0 return pu.getOriginalPath();
142    }
143   
 
144  0 toggle public String getAnchor(){
145  0 return pu.getAnchor();
146    }
147   
 
148  0 toggle public String getQuery(){
149  0 return pu.getQuery();
150    }
151   
152    /**
153    * This method returns the whole original URL; normalised URL can be obtained
154    * using getName() method.
155    */
 
156  0 toggle public String getURL(){
157  0 return pu.getURL();
158    }
159   
160    }