| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
package issrg.pba; |
| 56 |
|
|
| 57 |
|
import issrg.pba.rbac.RoleBasedAuthzTokenParser; |
| 58 |
|
import issrg.pba.rbac.RoleHierarchyPolicy; |
| 59 |
|
import issrg.pba.rbac.SignatureVerifier; |
| 60 |
|
import issrg.pba.PbaException; |
| 61 |
|
import issrg.pba.RawCredential; |
| 62 |
|
|
| 63 |
|
import java.util.Hashtable; |
| 64 |
|
import java.util.Vector; |
| 65 |
|
import java.util.Enumeration; |
| 66 |
|
|
| 67 |
|
import org.apache.log4j.*; |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
@author |
| 71 |
|
|
|
|
|
| 18.6% |
Uncovered Elements: 114 (140) |
Complexity: 21 |
Complexity Density: 0.36 |
|
| 72 |
|
public class MultiAuthzTokenParser implements RoleBasedAuthzTokenParser { |
| 73 |
|
|
| 74 |
|
private static Logger logger = Logger.getLogger("issrg.pba.MultiAuthzTokenParser"); |
| 75 |
|
private RoleHierarchyPolicy roleHierarchy = null; |
| 76 |
|
private SignatureVerifier SV = null; |
| 77 |
|
private Hashtable map = new Hashtable(); |
| 78 |
|
private Vector registration = new Vector(); |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
private static String[] tokenParsers = { |
| 83 |
|
"issrg.pba.rbac.x509.RoleBasedACParser", |
| 84 |
|
"issrg.pba.rbac.x509.RoleBasedACBase64Parser", |
| 85 |
|
"issrg.shibboleth.ShibbolethAuthTokenParser", |
| 86 |
|
"issrg.simplePERMIS.SimplePERMISTokenParser", |
| 87 |
|
"issrg.utils.saml.SAMLAATokenParser", |
| 88 |
|
"issrg.voms.VOMSSAMLAATokenParser" |
| 89 |
|
}; |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 2 |
Complexity Density: 0.12 |
|
| 93 |
4
|
public MultiAuthzTokenParser() {... |
| 94 |
28
|
for (int i=0; i<tokenParsers.length; i++) { |
| 95 |
24
|
this.registration.add(tokenParsers[i]); |
| 96 |
24
|
logger.debug("register "+tokenParsers[i]); |
| 97 |
|
} |
| 98 |
4
|
this.map.put("issrg.utils.repository.VirtualBase64Repository", "issrg.pba.rbac.x509.RoleBasedACBase64Parser"); |
| 99 |
4
|
logger.debug("issrg.utils.repository.VirtualBase64Repository <= issrg.pba.rbac.x509.RoleBasedACBase64Parser"); |
| 100 |
4
|
this.map.put("issrg.utils.repository.VirtualRepository", "issrg.pba.rbac.x509.RoleBasedACParser"); |
| 101 |
4
|
logger.debug("issrg.utils.repository.VirtualRepository <= issrg.pba.rbac.x509.RoleBasedACParser"); |
| 102 |
4
|
this.map.put("issrg.utils.repository.WebDAVRepository", "issrg.pba.rbac.x509.RoleBasedACParser"); |
| 103 |
4
|
logger.debug("issrg.utils.repository.WebDAVRepository <= issrg.pba.rbac.x509.RoleBasedACParser"); |
| 104 |
4
|
this.map.put("issrg.utils.repository.LDAPRepository", "issrg.pba.rbac.x509.RoleBasedACParser"); |
| 105 |
4
|
logger.debug("issrg.utils.repository.LDAPRepository <= issrg.pba.rbac.x509.RoleBasedACParser"); |
| 106 |
4
|
this.map.put("issrg.utils.repository.FileRepository", "issrg.pba.rbac.x509.RoleBasedACParser"); |
| 107 |
4
|
logger.debug("issrg.utils.repository.FileRepository <= issrg.pba.rbac.x509.RoleBasedACParser"); |
| 108 |
4
|
this.map.put("issrg.utils.repository.SAMLRepository", "issrg.utils.saml.SAMLAATokenParser"); |
| 109 |
4
|
logger.debug("issrg.utils.repository.SAMLRepository <= issrg.utils.saml.SAMLAATokenParser"); |
| 110 |
4
|
this.map.put("issrg.voms.VOMSSAMLRepository", "issrg.voms.VOMSSAMLAATokenParser"); |
| 111 |
4
|
logger.debug("issrg.voms.VOMSSAMLRepository <= issrg.voms.VOMSSAMLAATokenParser"); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
@param |
| 119 |
|
|
| 120 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 121 |
2
|
public void setRoleHierarchy(RoleHierarchyPolicy rhpn){... |
| 122 |
2
|
this.roleHierarchy = rhpn; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| 129 |
|
|
| 130 |
|
|
| 131 |
|
@return |
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 137 |
0
|
public java.util.Map getAuthTokenParsingRules(){... |
| 138 |
0
|
java.util.Map m = new java.util.Hashtable(); |
| 139 |
0
|
if (roleHierarchy!=null) m.put(issrg.pba.rbac.RoleHierarchyPolicy.class, roleHierarchy); |
| 140 |
0
|
return m; |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
|
|
| 147 |
|
@param |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 151 |
2
|
public void setSignatureVerifier(SignatureVerifier signatureVerifier){... |
| 152 |
2
|
this.SV = signatureVerifier; |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
| 158 |
|
@return |
| 159 |
|
|
| 160 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 161 |
0
|
public SignatureVerifier getSignatureVerifier(){... |
| 162 |
0
|
return SV; |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
|
|
| 168 |
|
|
| 169 |
|
|
| 170 |
|
@param |
| 171 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 172 |
2
|
public void setAuthTokenParsingRules(java.util.Map m){... |
| 173 |
2
|
setRoleHierarchy((RoleHierarchyPolicy) m.get(RoleHierarchyPolicy.class)); |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
@return |
| 180 |
|
|
| 181 |
|
@throws |
| 182 |
|
|
| 183 |
|
|
| 184 |
|
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 5 |
Complexity Density: 0.23 |
|
| 185 |
0
|
public ParsedToken decode(Object token) throws PbaException {... |
| 186 |
0
|
logger.debug(this.getClass().getName()+".decode()"); |
| 187 |
0
|
if (token == null) return null; |
| 188 |
0
|
if (this.roleHierarchy==null) |
| 189 |
0
|
throw new PbaException("Failed to decode an object: no Role Hierarchy was specified"); |
| 190 |
0
|
if (!RawCredential.class.isAssignableFrom(token.getClass())) { |
| 191 |
0
|
logger.debug("the token is not a RawCredential object"); |
| 192 |
0
|
throw new issrg.pba.PbaException("Failed to decode an object: it is not a RAWCredential"); |
| 193 |
|
} |
| 194 |
|
|
| 195 |
0
|
Object credential = ((RawCredential)token).getCredential(); |
| 196 |
0
|
String repositoryType = ((RawCredential)token).getType(); |
| 197 |
0
|
logger.debug("To find a token parser for "+repositoryType); |
| 198 |
0
|
String parserType = this.getParserByType(repositoryType); |
| 199 |
0
|
logger.debug("the parser is "+parserType); |
| 200 |
|
|
| 201 |
0
|
AuthzTokenParser authParser; |
| 202 |
|
|
| 203 |
0
|
try { |
| 204 |
0
|
Class authTokenParser = Class.forName(parserType); |
| 205 |
0
|
authParser = (AuthzTokenParser)authTokenParser.newInstance(); |
| 206 |
0
|
authParser.setAuthTokenParsingRules(this.getAuthTokenParsingRules()); |
| 207 |
0
|
authParser.setSignatureVerifier(this.getSignatureVerifier()); |
| 208 |
|
} catch (Exception e) { |
| 209 |
0
|
throw new PbaException("unknow repository type :"+e); |
| 210 |
|
} |
| 211 |
|
|
| 212 |
0
|
ParsedToken p = authParser.decode(credential); |
| 213 |
0
|
return p; |
| 214 |
|
} |
| 215 |
|
|
| 216 |
|
|
| 217 |
|
|
| 218 |
|
|
| 219 |
|
|
| 220 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 221 |
0
|
private String getParserByType(String type) throws PbaException {... |
| 222 |
0
|
String parser = (String)this.map.get(type); |
| 223 |
0
|
if (parser != null) return parser; |
| 224 |
0
|
if (this.registered(type)) return type; |
| 225 |
0
|
throw new PbaException("can not find a parser for "+type); |
| 226 |
|
} |
| 227 |
|
|
| 228 |
|
|
| 229 |
|
|
| 230 |
|
@param |
| 231 |
|
@return |
| 232 |
|
|
| 233 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 234 |
0
|
private boolean registered(String type) {... |
| 235 |
0
|
for (int i=0; i<this.registration.size(); i++) { |
| 236 |
0
|
if (type.equals(this.registration.get(i))) return true; |
| 237 |
|
} |
| 238 |
0
|
return false; |
| 239 |
|
} |
| 240 |
|
|
| 241 |
|
|
| 242 |
|
|
| 243 |
|
@param |
| 244 |
|
|
| 245 |
|
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 6 |
Complexity Density: 0.46 |
|
| 246 |
0
|
public void register(String className) {... |
| 247 |
0
|
String name = className.trim(); |
| 248 |
0
|
if (this.registration.isEmpty()) this.registration.add(name); |
| 249 |
|
else { |
| 250 |
0
|
boolean found = false; |
| 251 |
0
|
for (int i=0; i<this.registration.size(); i++) { |
| 252 |
0
|
String parser = (String)this.registration.get(i); |
| 253 |
0
|
if (name.equals(parser)) found = true; |
| 254 |
0
|
if (found) break; |
| 255 |
|
} |
| 256 |
0
|
if (found) return; |
| 257 |
0
|
this.registration.add(name); |
| 258 |
|
} |
| 259 |
|
} |
| 260 |
|
|
| 261 |
|
|
| 262 |
|
|
| 263 |
|
@param |
| 264 |
|
|
| 265 |
|
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 6 |
Complexity Density: 0.35 |
|
| 266 |
0
|
public void unregister(String className) {... |
| 267 |
0
|
String name = className.trim(); |
| 268 |
0
|
Vector keys = new Vector(); |
| 269 |
0
|
if (this.registration.isEmpty()) return; |
| 270 |
0
|
else this.registration.remove(name); |
| 271 |
0
|
Enumeration enumer = this.map.keys(); |
| 272 |
0
|
while (enumer.hasMoreElements()) { |
| 273 |
0
|
String key = (String)enumer.nextElement(); |
| 274 |
0
|
String value = (String)this.map.get(key); |
| 275 |
0
|
if (name.equals(value)) keys.add(key); |
| 276 |
|
} |
| 277 |
0
|
if (keys.isEmpty()) return; |
| 278 |
0
|
String[] keyArry = new String[keys.size()]; |
| 279 |
0
|
keyArry = (String[])keys.toArray(keyArry); |
| 280 |
0
|
for (int i=0; i<keyArry.length; i++) this.map.remove(keyArry[i]); |
| 281 |
|
} |
| 282 |
|
|
| 283 |
|
|
| 284 |
|
|
| 285 |
|
@param |
| 286 |
|
@param |
| 287 |
|
|
| 288 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 289 |
0
|
public void associate(String repository,String parser) {... |
| 290 |
0
|
String key = repository.trim(); |
| 291 |
0
|
String value = parser.trim(); |
| 292 |
0
|
this.map.put(key,value); |
| 293 |
|
} |
| 294 |
|
} |
| 295 |
|
|