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 |
|
package issrg.pba.rbac; |
55 |
|
|
56 |
|
import issrg.utils.repository.AttributeRepository; |
57 |
|
import issrg.saml.SAMLMetaInfo; |
58 |
|
import issrg.saml.SAMLSecurity; |
59 |
|
import issrg.security.SecurityException; |
60 |
|
import issrg.utils.repository.*; |
61 |
|
import issrg.utils.StringTokeniser; |
62 |
|
|
63 |
|
import java.net.*; |
64 |
|
import java.util.Hashtable; |
65 |
|
|
66 |
|
import org.apache.log4j.Logger; |
67 |
|
|
68 |
|
|
69 |
|
@author |
70 |
|
|
|
|
| 4.4% |
Uncovered Elements: 172 (180) |
Complexity: 31 |
Complexity Density: 0.32 |
|
71 |
|
public class SAMLURLHandler extends URLHandler { |
72 |
|
|
73 |
|
private static Logger logger = Logger.getLogger(SAMLURLHandler.class); |
74 |
|
public String configFile = null; |
75 |
|
private String protocol = null; |
76 |
|
private Hashtable params = new Hashtable(); |
77 |
|
|
78 |
|
|
79 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
80 |
2
|
public SAMLURLHandler(String protocolIn,String config) throws BadURLException {... |
81 |
2
|
this.protocol = protocolIn; |
82 |
2
|
this.configFile = config; |
83 |
2
|
String p = protocolIn.trim().toLowerCase(); |
84 |
0
|
if (p.indexOf("saml+")==-1) throw new BadURLException("wrong protocol in "+protocolIn); |
85 |
|
} |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.44 |
|
87 |
0
|
public AttributeRepository getRepository(String url) throws BadURLException {... |
88 |
0
|
try { |
89 |
0
|
SAMLMetaInfo info = new SAMLMetaInfo(); |
90 |
0
|
SAMLSecurity security = new SAMLSecurity(); |
91 |
0
|
url = this.initialise(url,info,security); |
92 |
0
|
URL up = new URL(url); |
93 |
0
|
return new SAMLRepository(up,info,security); |
94 |
|
} catch (MalformedURLException me) { |
95 |
0
|
throw new BadURLException("Wrong URL syntax: "+url+" is encountered"); |
96 |
|
} catch (SecurityException se) { |
97 |
0
|
throw new BadURLException("error:"+se); |
98 |
|
} catch (Exception e) { |
99 |
0
|
throw new BadURLException("error:"+e); |
100 |
|
} |
101 |
|
|
102 |
|
} |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 104 (104) |
Complexity: 18 |
Complexity Density: 0.28 |
|
104 |
0
|
public String initialise(String url,SAMLMetaInfo info,SAMLSecurity security) throws Exception {... |
105 |
0
|
logger.info("process meta data from the url "+url); |
106 |
0
|
if (this.configFile != null) info.load(this.configFile); |
107 |
|
|
108 |
0
|
int index = url.lastIndexOf("+"); |
109 |
0
|
if (index>0) url = url.substring(index+1); |
110 |
0
|
index = url.indexOf("?"); |
111 |
0
|
if (index>0) { |
112 |
0
|
String tmp = url; |
113 |
0
|
url = url.substring(0,index); |
114 |
0
|
String query = tmp.substring(index+1); |
115 |
0
|
update(params,info,query); |
116 |
|
} |
117 |
|
|
118 |
0
|
int login = info.getLoginMethod(); |
119 |
0
|
int authn = info.getAuthnMethod(); |
120 |
0
|
if (login==info.INTERACTIVE) security.login(authn); |
121 |
0
|
else if (login==info.PROGRAMMABLE) { |
122 |
0
|
if (authn == info.KEYSTORE) { |
123 |
0
|
String pass = (String)params.get("password"); |
124 |
0
|
if (pass==null) throw new Exception("password is required"); |
125 |
0
|
String file = (String)params.get("keystorefile"); |
126 |
0
|
if (file==null) throw new Exception("keystore file name is required"); |
127 |
0
|
String type = (String)params.get("keystoretype"); |
128 |
0
|
int t = type.toUpperCase().equals("JKS")?security.JKS:security.PKCS12; |
129 |
0
|
security.LoginByProg(file,pass,t); |
130 |
0
|
} else if (authn == info.KEYPAIR) { |
131 |
0
|
String key = (String)params.get("keyfile"); |
132 |
0
|
if (key==null) throw new Exception("private key file name is required"); |
133 |
0
|
String file = (String)params.get("pkcfile"); |
134 |
0
|
if (file==null) throw new Exception("PKC file name is required"); |
135 |
0
|
String type = (String)params.get("keytype"); |
136 |
0
|
int t = type.toUpperCase().equals("DSA")?security.DSA:security.RSA; |
137 |
0
|
security.LoginByProg(t,file,key); |
138 |
0
|
} else if (authn == info.ENCRYPTEDKEYPAIR) { |
139 |
0
|
String key = (String)params.get("keyfile"); |
140 |
0
|
if (key==null) throw new Exception("private key file name is required"); |
141 |
0
|
String file = (String)params.get("pkcfile"); |
142 |
0
|
if (file==null) throw new Exception("PKC file name is required"); |
143 |
0
|
String type = (String)params.get("keytype"); |
144 |
0
|
int t = type.toUpperCase().equals("DSA")?security.DSA:security.RSA; |
145 |
0
|
security.LoginByProg(t,file,key); |
146 |
0
|
String pass = (String)params.get("password"); |
147 |
0
|
if (pass==null) throw new Exception("password is required"); |
148 |
0
|
security.LoginByProg(t,file,key,pass); |
149 |
0
|
} else if (authn == info.PROXY) { |
150 |
0
|
String proxy = (String)params.get("proxyfile"); |
151 |
0
|
if (proxy==null) throw new Exception("proxy key file name is required"); |
152 |
0
|
security.LoginByProg(proxy); |
153 |
0
|
} else throw new Exception("illegal authn method"); |
154 |
0
|
} else throw new Exception("illegal login method"); |
155 |
0
|
URL t = new URL(url); |
156 |
0
|
info.setProtocol(t.getProtocol()); |
157 |
0
|
info.setHost(t.getHost()); |
158 |
0
|
info.setPort(t.getPort()); |
159 |
0
|
info.setFilePath(t.getPath()); |
160 |
0
|
return url; |
161 |
|
} |
162 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
163 |
2
|
public String getProtocol() {... |
164 |
2
|
return this.protocol; |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
|
|
| 0% |
Uncovered Elements: 54 (54) |
Complexity: 10 |
Complexity Density: 0.31 |
|
173 |
0
|
public void update(Hashtable table, SAMLMetaInfo info,String data) throws Exception {... |
174 |
|
|
175 |
0
|
String[] params = StringTokeniser.process(data,";"); |
176 |
0
|
String name = null; |
177 |
0
|
String value = null; |
178 |
0
|
for (int i=0; i<params.length; i++) { |
179 |
0
|
int index = params[i].indexOf("="); |
180 |
0
|
if (index == -1) { |
181 |
0
|
logger.debug("warning : "+params[i]+" is not defined"); |
182 |
0
|
continue; |
183 |
|
} else { |
184 |
0
|
name = params[i].substring(0,index).trim(); |
185 |
0
|
value = params[i].substring(index+1).trim(); |
186 |
0
|
logger.debug(name+" = "+value); |
187 |
0
|
if (name.equals("config")) { |
188 |
0
|
info.load(value); |
189 |
0
|
} else if (name.equals("authn")) { |
190 |
0
|
int v = new Integer(value).intValue(); |
191 |
0
|
info.setAuthnMethod(v); |
192 |
0
|
} else if (name.equals("login")) { |
193 |
0
|
int v = new Integer(value).intValue(); |
194 |
0
|
info.setLoginMethod(v); |
195 |
0
|
} else if (name.equals("querytype")) { |
196 |
0
|
int v = new Integer(value).intValue(); |
197 |
0
|
info.setQueryType(v); |
198 |
0
|
} else if (name.equals("attributes")) { |
199 |
0
|
String[] names = StringTokeniser.process(value,","); |
200 |
0
|
info.setAttributeNames(names); |
201 |
0
|
} else if (name.equals("signassertion")) { |
202 |
0
|
boolean v = (value.toLowerCase().equals("yes"))?true:false; |
203 |
0
|
info.setSignedAssertion(v); |
204 |
0
|
} else if (name.equals("signrequest")) { |
205 |
0
|
boolean v = (value.toLowerCase().equals("yes"))?true:false; |
206 |
0
|
info.setSignedRequest(v); |
207 |
0
|
} else table.put(name,value); |
208 |
|
} |
209 |
|
} |
210 |
|
} |
211 |
|
} |