Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
15   143   5   1.88
14   38   0.8   8
8     1.5  
1    
 
 
  PermisTarget       Line # 49 15 5 64.9% 0.6486486
 
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.pba.rbac.LDAPDNPrincipal;
35    import issrg.utils.repository.Entry;
36   
37    /**
38    * The Permis version of the Target that uses LDAP DNs or URLs. The object also
39    * knows
40    * what object class it is of, and therefore can be used for performing the
41    * target domain match.
42    *
43    * @author A Otenko
44    * @author E Ball
45    * @author D W Chadwick
46    * @version 0.2
47    */
48   
 
49    public class PermisTarget implements issrg.pba.Target,
50    issrg.pba.rbac.policies.LDAPEntry{
51    private LDAPDNPrincipal DN=null;
52    private String [] OCS;// the ObjectClasses
53   
54    private Entry upi=null;
55   
 
56  0 toggle protected PermisTarget(){}
57   
58    /**
59    * This constructor builds a Target based on a distinguished name and a set
60    * of object classes.
61    *
62    * @param Name a string describing the LDAP distinguished name of the target
63    * @param ObjectClasses an array of strings that are the various LDAP
64    * objectclasses that the Target has. These can be represented as user
65    * friendly strings e.g. printer or as an OID string e.g. 1.2.3.4.5.6
66    * If the array is null, the Target is of any class (isObjectClass always
67    * returns true)
68    */
 
69  1487 toggle public PermisTarget(String Name,String [] ObjectClasses)
70    throws issrg.utils.RFC2253ParsingException {
71  1487 OCS=ObjectClasses;
72  1487 DN=new LDAPDNPrincipal(Name);
73    }
74   
75    /**
76    * This constructor builds a Target based on its URL. There must be a
77    * URLHandler registered that can create Entry from the URLs.
78    *
79    * @param url is the URL of the Target.
80    *
81    * @see CustomisePERMIS#addURLHandler(String), URLHandler#addProtocol(URLHandler)
82    */
 
83  56 toggle public PermisTarget(String url) throws BadURLException {
84  56 upi=URLHandler.getEntryByURL(url);
85  0 if (upi==null) throw new BadURLException("No URL handler has been found for "+url);
86    }
87   
88    /**
89    * This method returns the LDAP DN of the target as a string e.g. "ou=ISI,
90    * o=salford, c=gb"
91    *
92    * @return the string representation of the LDAP DN, or the URL (depending
93    * on the constructor used)
94    */
 
95  127 toggle public String getName(){
96  127 return DN==null?upi.getEntryName().getName():getDN().getName();
97    }
98   
99    /**
100    * This method returns the distinguished name of the target.
101    *
102    * @return the LDAPDNPrincipal representing the X500 name; can be null,
103    * if the Target is indetified by a URL
104    */
 
105  8281 toggle public LDAPDNPrincipal getDN(){
106  8281 return DN;
107    }
108   
109    /**
110    * Does the same as getDN(), if the Target has been initialised with LDAP DN;
111    * otherwise, returns the Entry for the URL.
112    */
 
113  37 toggle public java.security.Principal getEntryName(){
114  37 return DN==null?upi.getEntryName(): getDN();
115    }
116   
117    /**
118    * This checks to see if this target is of the indicated ObjectClass
119    *
120    * @param Class the ObjectClass to be tested against
121    *
122    * @return true if the target is of the specified object class
123    */
 
124  840 toggle public boolean isObjectClass(String Class){
125  840 if (OCS==null) return true;
126   
127  0 for(int i=0; i<OCS.length; i++){
128  0 if (OCS[i].intern()==Class.intern()) return true;
129    }
130  0 return false;
131    }
132   
133    /**
134    * This method returns Target ADI. Targets return LDAPEntry for PermisRBAC
135    * objects as their ADI.
136    *
137    * @return the reference to the LDAPEntry object that describes the LDAP Entry
138    * of the target, or returns an Entry corresponding to the URL
139    */
 
140  1359 toggle public Object getTargetADI(){
141  1359 return DN==null?upi: this;
142    }
143    }