author | michaelm |
Mon, 14 Oct 2013 22:09:15 +0100 | |
changeset 20787 | ab071ce90368 |
parent 20754 | 3d7b2fafc34b |
child 20886 | 9630bb813a6c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14182
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
10336
diff
changeset
|
2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
5609
cc144006eb2a
6951599: Rename package of security tools for modularization
mchung
parents:
3483
diff
changeset
|
26 |
package sun.security.tools.policytool; |
2 | 27 |
|
28 |
import java.io.*; |
|
29 |
import java.util.LinkedList; |
|
30 |
import java.util.ListIterator; |
|
31 |
import java.util.Vector; |
|
32 |
import java.util.Enumeration; |
|
33 |
import java.net.URL; |
|
34 |
import java.net.MalformedURLException; |
|
35 |
import java.lang.reflect.*; |
|
36 |
import java.text.Collator; |
|
37 |
import java.text.MessageFormat; |
|
38 |
import sun.security.util.PropertyExpander; |
|
39 |
import sun.security.util.PropertyExpander.ExpandException; |
|
40 |
import java.awt.*; |
|
41 |
import java.awt.event.*; |
|
42 |
import java.security.cert.Certificate; |
|
43 |
import java.security.cert.CertificateException; |
|
44 |
import java.security.*; |
|
45 |
import sun.security.provider.*; |
|
46 |
import sun.security.util.PolicyUtil; |
|
47 |
import javax.security.auth.x500.X500Principal; |
|
48 |
||
49 |
/** |
|
50 |
* PolicyTool may be used by users and administrators to configure the |
|
51 |
* overall java security policy (currently stored in the policy file). |
|
7532 | 52 |
* Using PolicyTool administrators may add and remove policies from |
2 | 53 |
* the policy file. <p> |
54 |
* |
|
55 |
* @see java.security.Policy |
|
56 |
* @since 1.2 |
|
57 |
*/ |
|
58 |
||
59 |
public class PolicyTool { |
|
60 |
||
61 |
// for i18n |
|
62 |
static final java.util.ResourceBundle rb = |
|
14182
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
10336
diff
changeset
|
63 |
java.util.ResourceBundle.getBundle( |
3041082abb40
7194449: String resources for Key Tool and Policy Tool should be in their respective packages
sflores
parents:
10336
diff
changeset
|
64 |
"sun.security.tools.policytool.Resources"); |
2 | 65 |
static final Collator collator = Collator.getInstance(); |
66 |
static { |
|
67 |
// this is for case insensitive string comparisons |
|
68 |
collator.setStrength(Collator.PRIMARY); |
|
69 |
}; |
|
70 |
||
71 |
// anyone can add warnings |
|
72 |
Vector<String> warnings; |
|
73 |
boolean newWarning = false; |
|
74 |
||
75 |
// set to true if policy modified. |
|
76 |
// this way upon exit we know if to ask the user to save changes |
|
77 |
boolean modified = false; |
|
78 |
||
79 |
private static final boolean testing = false; |
|
20754
3d7b2fafc34b
8025967: addition of -Werror broke the old build
valeriep
parents:
17692
diff
changeset
|
80 |
private static final Class<?>[] TWOPARAMS = { String.class, String.class }; |
3d7b2fafc34b
8025967: addition of -Werror broke the old build
valeriep
parents:
17692
diff
changeset
|
81 |
private static final Class<?>[] ONEPARAMS = { String.class }; |
3d7b2fafc34b
8025967: addition of -Werror broke the old build
valeriep
parents:
17692
diff
changeset
|
82 |
private static final Class<?>[] NOPARAMS = {}; |
2 | 83 |
/* |
84 |
* All of the policy entries are read in from the |
|
85 |
* policy file and stored here. Updates to the policy entries |
|
86 |
* using addEntry() and removeEntry() are made here. To ultimately save |
|
87 |
* the policy entries back to the policy file, the SavePolicy button |
|
88 |
* must be clicked. |
|
89 |
**/ |
|
90 |
private static String policyFileName = null; |
|
91 |
private Vector<PolicyEntry> policyEntries = null; |
|
92 |
private PolicyParser parser = null; |
|
93 |
||
94 |
/* The public key alias information is stored here. */ |
|
95 |
private KeyStore keyStore = null; |
|
96 |
private String keyStoreName = " "; |
|
97 |
private String keyStoreType = " "; |
|
98 |
private String keyStoreProvider = " "; |
|
99 |
private String keyStorePwdURL = " "; |
|
100 |
||
101 |
/* standard PKCS11 KeyStore type */ |
|
102 |
private static final String P11KEYSTORE = "PKCS11"; |
|
103 |
||
104 |
/* reserved word for PKCS11 KeyStores */ |
|
105 |
private static final String NONE = "NONE"; |
|
106 |
||
107 |
/** |
|
108 |
* default constructor |
|
109 |
*/ |
|
110 |
private PolicyTool() { |
|
111 |
policyEntries = new Vector<PolicyEntry>(); |
|
112 |
parser = new PolicyParser(); |
|
113 |
warnings = new Vector<String>(); |
|
114 |
} |
|
115 |
||
116 |
/** |
|
117 |
* get the PolicyFileName |
|
118 |
*/ |
|
119 |
String getPolicyFileName() { |
|
120 |
return policyFileName; |
|
121 |
} |
|
122 |
||
123 |
/** |
|
124 |
* set the PolicyFileName |
|
125 |
*/ |
|
126 |
void setPolicyFileName(String policyFileName) { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
127 |
PolicyTool.policyFileName = policyFileName; |
2 | 128 |
} |
129 |
||
130 |
/** |
|
131 |
* clear keyStore info |
|
132 |
*/ |
|
133 |
void clearKeyStoreInfo() { |
|
134 |
this.keyStoreName = null; |
|
135 |
this.keyStoreType = null; |
|
136 |
this.keyStoreProvider = null; |
|
137 |
this.keyStorePwdURL = null; |
|
138 |
||
139 |
this.keyStore = null; |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* get the keyStore URL name |
|
144 |
*/ |
|
145 |
String getKeyStoreName() { |
|
146 |
return keyStoreName; |
|
147 |
} |
|
148 |
||
149 |
/** |
|
150 |
* get the keyStore Type |
|
151 |
*/ |
|
152 |
String getKeyStoreType() { |
|
153 |
return keyStoreType; |
|
154 |
} |
|
155 |
||
156 |
/** |
|
157 |
* get the keyStore Provider |
|
158 |
*/ |
|
159 |
String getKeyStoreProvider() { |
|
160 |
return keyStoreProvider; |
|
161 |
} |
|
162 |
||
163 |
/** |
|
164 |
* get the keyStore password URL |
|
165 |
*/ |
|
166 |
String getKeyStorePwdURL() { |
|
167 |
return keyStorePwdURL; |
|
168 |
} |
|
169 |
||
170 |
/** |
|
171 |
* Open and read a policy file |
|
172 |
*/ |
|
173 |
void openPolicy(String filename) throws FileNotFoundException, |
|
174 |
PolicyParser.ParsingException, |
|
175 |
KeyStoreException, |
|
176 |
CertificateException, |
|
177 |
InstantiationException, |
|
178 |
MalformedURLException, |
|
179 |
IOException, |
|
180 |
NoSuchAlgorithmException, |
|
181 |
IllegalAccessException, |
|
182 |
NoSuchMethodException, |
|
183 |
UnrecoverableKeyException, |
|
184 |
NoSuchProviderException, |
|
185 |
ClassNotFoundException, |
|
186 |
PropertyExpander.ExpandException, |
|
187 |
InvocationTargetException { |
|
188 |
||
189 |
newWarning = false; |
|
190 |
||
191 |
// start fresh - blow away the current state |
|
192 |
policyEntries = new Vector<PolicyEntry>(); |
|
193 |
parser = new PolicyParser(); |
|
194 |
warnings = new Vector<String>(); |
|
195 |
setPolicyFileName(null); |
|
196 |
clearKeyStoreInfo(); |
|
197 |
||
198 |
// see if user is opening a NEW policy file |
|
199 |
if (filename == null) { |
|
200 |
modified = false; |
|
201 |
return; |
|
202 |
} |
|
203 |
||
204 |
// Read in the policy entries from the file and |
|
205 |
// populate the parser vector table. The parser vector |
|
206 |
// table only holds the entries as strings, so it only |
|
207 |
// guarantees that the policies are syntactically |
|
208 |
// correct. |
|
209 |
setPolicyFileName(filename); |
|
210 |
parser.read(new FileReader(filename)); |
|
211 |
||
212 |
// open the keystore |
|
213 |
openKeyStore(parser.getKeyStoreUrl(), parser.getKeyStoreType(), |
|
214 |
parser.getKeyStoreProvider(), parser.getStorePassURL()); |
|
215 |
||
216 |
// Update the local vector with the same policy entries. |
|
217 |
// This guarantees that the policy entries are not only |
|
218 |
// syntactically correct, but semantically valid as well. |
|
219 |
Enumeration<PolicyParser.GrantEntry> enum_ = parser.grantElements(); |
|
220 |
while (enum_.hasMoreElements()) { |
|
221 |
PolicyParser.GrantEntry ge = enum_.nextElement(); |
|
222 |
||
223 |
// see if all the signers have public keys |
|
224 |
if (ge.signedBy != null) { |
|
225 |
||
226 |
String signers[] = parseSigners(ge.signedBy); |
|
227 |
for (int i = 0; i < signers.length; i++) { |
|
228 |
PublicKey pubKey = getPublicKeyAlias(signers[i]); |
|
229 |
if (pubKey == null) { |
|
230 |
newWarning = true; |
|
231 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
232 |
("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured.")); |
2 | 233 |
Object[] source = {signers[i]}; |
234 |
warnings.addElement(form.format(source)); |
|
235 |
} |
|
236 |
} |
|
237 |
} |
|
238 |
||
239 |
// check to see if the Principals are valid |
|
240 |
ListIterator<PolicyParser.PrincipalEntry> prinList = |
|
241 |
ge.principals.listIterator(0); |
|
242 |
while (prinList.hasNext()) { |
|
243 |
PolicyParser.PrincipalEntry pe = prinList.next(); |
|
244 |
try { |
|
245 |
verifyPrincipal(pe.getPrincipalClass(), |
|
246 |
pe.getPrincipalName()); |
|
247 |
} catch (ClassNotFoundException fnfe) { |
|
248 |
newWarning = true; |
|
249 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
250 |
("Warning.Class.not.found.class")); |
2 | 251 |
Object[] source = {pe.getPrincipalClass()}; |
252 |
warnings.addElement(form.format(source)); |
|
253 |
} |
|
254 |
} |
|
255 |
||
256 |
// check to see if the Permissions are valid |
|
257 |
Enumeration<PolicyParser.PermissionEntry> perms = |
|
258 |
ge.permissionElements(); |
|
259 |
while (perms.hasMoreElements()) { |
|
260 |
PolicyParser.PermissionEntry pe = perms.nextElement(); |
|
261 |
try { |
|
262 |
verifyPermission(pe.permission, pe.name, pe.action); |
|
263 |
} catch (ClassNotFoundException fnfe) { |
|
264 |
newWarning = true; |
|
265 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
266 |
("Warning.Class.not.found.class")); |
2 | 267 |
Object[] source = {pe.permission}; |
268 |
warnings.addElement(form.format(source)); |
|
269 |
} catch (InvocationTargetException ite) { |
|
270 |
newWarning = true; |
|
271 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
272 |
("Warning.Invalid.argument.s.for.constructor.arg")); |
2 | 273 |
Object[] source = {pe.permission}; |
274 |
warnings.addElement(form.format(source)); |
|
275 |
} |
|
276 |
||
277 |
// see if all the permission signers have public keys |
|
278 |
if (pe.signedBy != null) { |
|
279 |
||
280 |
String signers[] = parseSigners(pe.signedBy); |
|
281 |
||
282 |
for (int i = 0; i < signers.length; i++) { |
|
283 |
PublicKey pubKey = getPublicKeyAlias(signers[i]); |
|
284 |
if (pubKey == null) { |
|
285 |
newWarning = true; |
|
286 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
287 |
("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured.")); |
2 | 288 |
Object[] source = {signers[i]}; |
289 |
warnings.addElement(form.format(source)); |
|
290 |
} |
|
291 |
} |
|
292 |
} |
|
293 |
} |
|
294 |
PolicyEntry pEntry = new PolicyEntry(this, ge); |
|
295 |
policyEntries.addElement(pEntry); |
|
296 |
} |
|
297 |
||
298 |
// just read in the policy -- nothing has been modified yet |
|
299 |
modified = false; |
|
300 |
} |
|
301 |
||
302 |
||
303 |
/** |
|
304 |
* Save a policy to a file |
|
305 |
*/ |
|
306 |
void savePolicy(String filename) |
|
307 |
throws FileNotFoundException, IOException { |
|
308 |
// save the policy entries to a file |
|
309 |
parser.setKeyStoreUrl(keyStoreName); |
|
310 |
parser.setKeyStoreType(keyStoreType); |
|
311 |
parser.setKeyStoreProvider(keyStoreProvider); |
|
312 |
parser.setStorePassURL(keyStorePwdURL); |
|
313 |
parser.write(new FileWriter(filename)); |
|
314 |
modified = false; |
|
315 |
} |
|
316 |
||
317 |
/** |
|
318 |
* Open the KeyStore |
|
319 |
*/ |
|
320 |
void openKeyStore(String name, |
|
321 |
String type, |
|
322 |
String provider, |
|
323 |
String pwdURL) throws KeyStoreException, |
|
324 |
NoSuchAlgorithmException, |
|
325 |
UnrecoverableKeyException, |
|
326 |
IOException, |
|
327 |
CertificateException, |
|
328 |
NoSuchProviderException, |
|
329 |
ExpandException { |
|
330 |
||
331 |
if (name == null && type == null && |
|
332 |
provider == null && pwdURL == null) { |
|
333 |
||
334 |
// policy did not specify a keystore during open |
|
335 |
// or use wants to reset keystore values |
|
336 |
||
337 |
this.keyStoreName = null; |
|
338 |
this.keyStoreType = null; |
|
339 |
this.keyStoreProvider = null; |
|
340 |
this.keyStorePwdURL = null; |
|
341 |
||
342 |
// caller will set (tool.modified = true) if appropriate |
|
343 |
||
344 |
return; |
|
345 |
} |
|
346 |
||
347 |
URL policyURL = null; |
|
348 |
if (policyFileName != null) { |
|
349 |
File pfile = new File(policyFileName); |
|
350 |
policyURL = new URL("file:" + pfile.getCanonicalPath()); |
|
351 |
} |
|
352 |
||
353 |
// although PolicyUtil.getKeyStore may properly handle |
|
354 |
// defaults and property expansion, we do it here so that |
|
355 |
// if the call is successful, we can set the proper values |
|
356 |
// (PolicyUtil.getKeyStore does not return expanded values) |
|
357 |
||
358 |
if (name != null && name.length() > 0) { |
|
359 |
name = PropertyExpander.expand(name).replace |
|
360 |
(File.separatorChar, '/'); |
|
361 |
} |
|
362 |
if (type == null || type.length() == 0) { |
|
363 |
type = KeyStore.getDefaultType(); |
|
364 |
} |
|
365 |
if (pwdURL != null && pwdURL.length() > 0) { |
|
366 |
pwdURL = PropertyExpander.expand(pwdURL).replace |
|
367 |
(File.separatorChar, '/'); |
|
368 |
} |
|
369 |
||
370 |
try { |
|
371 |
this.keyStore = PolicyUtil.getKeyStore(policyURL, |
|
372 |
name, |
|
373 |
type, |
|
374 |
provider, |
|
375 |
pwdURL, |
|
376 |
null); |
|
377 |
} catch (IOException ioe) { |
|
378 |
||
379 |
// copied from sun.security.pkcs11.SunPKCS11 |
|
380 |
String MSG = "no password provided, and no callback handler " + |
|
381 |
"available for retrieving password"; |
|
382 |
||
383 |
Throwable cause = ioe.getCause(); |
|
384 |
if (cause != null && |
|
385 |
cause instanceof javax.security.auth.login.LoginException && |
|
386 |
MSG.equals(cause.getMessage())) { |
|
387 |
||
388 |
// throw a more friendly exception message |
|
389 |
throw new IOException(MSG); |
|
390 |
} else { |
|
391 |
throw ioe; |
|
392 |
} |
|
393 |
} |
|
394 |
||
395 |
this.keyStoreName = name; |
|
396 |
this.keyStoreType = type; |
|
397 |
this.keyStoreProvider = provider; |
|
398 |
this.keyStorePwdURL = pwdURL; |
|
399 |
||
400 |
// caller will set (tool.modified = true) |
|
401 |
} |
|
402 |
||
403 |
/** |
|
404 |
* Add a Grant entry to the overall policy at the specified index. |
|
405 |
* A policy entry consists of a CodeSource. |
|
406 |
*/ |
|
407 |
boolean addEntry(PolicyEntry pe, int index) { |
|
408 |
||
409 |
if (index < 0) { |
|
410 |
// new entry -- just add it to the end |
|
411 |
policyEntries.addElement(pe); |
|
412 |
parser.add(pe.getGrantEntry()); |
|
413 |
} else { |
|
414 |
// existing entry -- replace old one |
|
415 |
PolicyEntry origPe = policyEntries.elementAt(index); |
|
416 |
parser.replace(origPe.getGrantEntry(), pe.getGrantEntry()); |
|
417 |
policyEntries.setElementAt(pe, index); |
|
418 |
} |
|
419 |
return true; |
|
420 |
} |
|
421 |
||
422 |
/** |
|
423 |
* Add a Principal entry to an existing PolicyEntry at the specified index. |
|
424 |
* A Principal entry consists of a class, and name. |
|
425 |
* |
|
426 |
* If the principal already exists, it is not added again. |
|
427 |
*/ |
|
428 |
boolean addPrinEntry(PolicyEntry pe, |
|
429 |
PolicyParser.PrincipalEntry newPrin, |
|
430 |
int index) { |
|
431 |
||
432 |
// first add the principal to the Policy Parser entry |
|
433 |
PolicyParser.GrantEntry grantEntry = pe.getGrantEntry(); |
|
434 |
if (grantEntry.contains(newPrin) == true) |
|
435 |
return false; |
|
436 |
||
437 |
LinkedList<PolicyParser.PrincipalEntry> prinList = |
|
438 |
grantEntry.principals; |
|
439 |
if (index != -1) |
|
440 |
prinList.set(index, newPrin); |
|
441 |
else |
|
442 |
prinList.add(newPrin); |
|
443 |
||
444 |
modified = true; |
|
445 |
return true; |
|
446 |
} |
|
447 |
||
448 |
/** |
|
449 |
* Add a Permission entry to an existing PolicyEntry at the specified index. |
|
450 |
* A Permission entry consists of a permission, name, and actions. |
|
451 |
* |
|
452 |
* If the permission already exists, it is not added again. |
|
453 |
*/ |
|
454 |
boolean addPermEntry(PolicyEntry pe, |
|
455 |
PolicyParser.PermissionEntry newPerm, |
|
456 |
int index) { |
|
457 |
||
458 |
// first add the permission to the Policy Parser Vector |
|
459 |
PolicyParser.GrantEntry grantEntry = pe.getGrantEntry(); |
|
460 |
if (grantEntry.contains(newPerm) == true) |
|
461 |
return false; |
|
462 |
||
463 |
Vector<PolicyParser.PermissionEntry> permList = |
|
464 |
grantEntry.permissionEntries; |
|
465 |
if (index != -1) |
|
466 |
permList.setElementAt(newPerm, index); |
|
467 |
else |
|
468 |
permList.addElement(newPerm); |
|
469 |
||
470 |
modified = true; |
|
471 |
return true; |
|
472 |
} |
|
473 |
||
474 |
/** |
|
475 |
* Remove a Permission entry from an existing PolicyEntry. |
|
476 |
*/ |
|
477 |
boolean removePermEntry(PolicyEntry pe, |
|
478 |
PolicyParser.PermissionEntry perm) { |
|
479 |
||
480 |
// remove the Permission from the GrantEntry |
|
481 |
PolicyParser.GrantEntry ppge = pe.getGrantEntry(); |
|
482 |
modified = ppge.remove(perm); |
|
483 |
return modified; |
|
484 |
} |
|
485 |
||
486 |
/** |
|
487 |
* remove an entry from the overall policy |
|
488 |
*/ |
|
489 |
boolean removeEntry(PolicyEntry pe) { |
|
490 |
||
491 |
parser.remove(pe.getGrantEntry()); |
|
492 |
modified = true; |
|
493 |
return (policyEntries.removeElement(pe)); |
|
494 |
} |
|
495 |
||
496 |
/** |
|
497 |
* retrieve all Policy Entries |
|
498 |
*/ |
|
499 |
PolicyEntry[] getEntry() { |
|
500 |
||
501 |
if (policyEntries.size() > 0) { |
|
502 |
PolicyEntry entries[] = new PolicyEntry[policyEntries.size()]; |
|
503 |
for (int i = 0; i < policyEntries.size(); i++) |
|
504 |
entries[i] = policyEntries.elementAt(i); |
|
505 |
return entries; |
|
506 |
} |
|
507 |
return null; |
|
508 |
} |
|
509 |
||
510 |
/** |
|
511 |
* Retrieve the public key mapped to a particular name. |
|
512 |
* If the key has expired, a KeyException is thrown. |
|
513 |
*/ |
|
514 |
PublicKey getPublicKeyAlias(String name) throws KeyStoreException { |
|
515 |
if (keyStore == null) { |
|
516 |
return null; |
|
517 |
} |
|
518 |
||
519 |
Certificate cert = keyStore.getCertificate(name); |
|
520 |
if (cert == null) { |
|
521 |
return null; |
|
522 |
} |
|
523 |
PublicKey pubKey = cert.getPublicKey(); |
|
524 |
return pubKey; |
|
525 |
} |
|
526 |
||
527 |
/** |
|
528 |
* Retrieve all the alias names stored in the certificate database |
|
529 |
*/ |
|
530 |
String[] getPublicKeyAlias() throws KeyStoreException { |
|
531 |
||
532 |
int numAliases = 0; |
|
533 |
String aliases[] = null; |
|
534 |
||
535 |
if (keyStore == null) { |
|
536 |
return null; |
|
537 |
} |
|
538 |
Enumeration<String> enum_ = keyStore.aliases(); |
|
539 |
||
540 |
// first count the number of elements |
|
541 |
while (enum_.hasMoreElements()) { |
|
542 |
enum_.nextElement(); |
|
543 |
numAliases++; |
|
544 |
} |
|
545 |
||
546 |
if (numAliases > 0) { |
|
547 |
// now copy them into an array |
|
548 |
aliases = new String[numAliases]; |
|
549 |
numAliases = 0; |
|
550 |
enum_ = keyStore.aliases(); |
|
551 |
while (enum_.hasMoreElements()) { |
|
552 |
aliases[numAliases] = new String(enum_.nextElement()); |
|
553 |
numAliases++; |
|
554 |
} |
|
555 |
} |
|
556 |
return aliases; |
|
557 |
} |
|
558 |
||
559 |
/** |
|
560 |
* This method parses a single string of signers separated by commas |
|
561 |
* ("jordan, duke, pippen") into an array of individual strings. |
|
562 |
*/ |
|
563 |
String[] parseSigners(String signedBy) { |
|
564 |
||
565 |
String signers[] = null; |
|
566 |
int numSigners = 1; |
|
567 |
int signedByIndex = 0; |
|
568 |
int commaIndex = 0; |
|
569 |
int signerNum = 0; |
|
570 |
||
571 |
// first pass thru "signedBy" counts the number of signers |
|
572 |
while (commaIndex >= 0) { |
|
573 |
commaIndex = signedBy.indexOf(',', signedByIndex); |
|
574 |
if (commaIndex >= 0) { |
|
575 |
numSigners++; |
|
576 |
signedByIndex = commaIndex + 1; |
|
577 |
} |
|
578 |
} |
|
579 |
signers = new String[numSigners]; |
|
580 |
||
581 |
// second pass thru "signedBy" transfers signers to array |
|
582 |
commaIndex = 0; |
|
583 |
signedByIndex = 0; |
|
584 |
while (commaIndex >= 0) { |
|
585 |
if ((commaIndex = signedBy.indexOf(',', signedByIndex)) >= 0) { |
|
586 |
// transfer signer and ignore trailing part of the string |
|
587 |
signers[signerNum] = |
|
588 |
signedBy.substring(signedByIndex, commaIndex).trim(); |
|
589 |
signerNum++; |
|
590 |
signedByIndex = commaIndex + 1; |
|
591 |
} else { |
|
592 |
// we are at the end of the string -- transfer signer |
|
593 |
signers[signerNum] = signedBy.substring(signedByIndex).trim(); |
|
594 |
} |
|
595 |
} |
|
596 |
return signers; |
|
597 |
} |
|
598 |
||
599 |
/** |
|
600 |
* Check to see if the Principal contents are OK |
|
601 |
*/ |
|
602 |
void verifyPrincipal(String type, String name) |
|
603 |
throws ClassNotFoundException, |
|
604 |
InstantiationException |
|
605 |
{ |
|
606 |
if (type.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS) || |
|
15013
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
14182
diff
changeset
|
607 |
type.equals(PolicyParser.PrincipalEntry.REPLACE_NAME)) { |
2 | 608 |
return; |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
609 |
} |
2 | 610 |
Class<?> PRIN = Class.forName("java.security.Principal"); |
611 |
Class<?> pc = Class.forName(type, true, |
|
612 |
Thread.currentThread().getContextClassLoader()); |
|
613 |
if (!PRIN.isAssignableFrom(pc)) { |
|
614 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
615 |
("Illegal.Principal.Type.type")); |
2 | 616 |
Object[] source = {type}; |
617 |
throw new InstantiationException(form.format(source)); |
|
618 |
} |
|
619 |
||
620 |
if (ToolDialog.X500_PRIN_CLASS.equals(pc.getName())) { |
|
621 |
// PolicyParser checks validity of X500Principal name |
|
622 |
// - PolicyTool needs to as well so that it doesn't store |
|
623 |
// an invalid name that can't be read in later |
|
624 |
// |
|
625 |
// this can throw an IllegalArgumentException |
|
626 |
X500Principal newP = new X500Principal(name); |
|
627 |
} |
|
628 |
} |
|
629 |
||
630 |
/** |
|
631 |
* Check to see if the Permission contents are OK |
|
632 |
*/ |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
633 |
@SuppressWarnings("fallthrough") |
2 | 634 |
void verifyPermission(String type, |
635 |
String name, |
|
636 |
String actions) |
|
637 |
throws ClassNotFoundException, |
|
638 |
InstantiationException, |
|
639 |
IllegalAccessException, |
|
640 |
NoSuchMethodException, |
|
641 |
InvocationTargetException |
|
642 |
{ |
|
643 |
||
644 |
//XXX we might want to keep a hash of created factories... |
|
645 |
Class<?> pc = Class.forName(type, true, |
|
646 |
Thread.currentThread().getContextClassLoader()); |
|
647 |
Constructor<?> c = null; |
|
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
7532
diff
changeset
|
648 |
Vector<String> objects = new Vector<>(2); |
2 | 649 |
if (name != null) objects.add(name); |
650 |
if (actions != null) objects.add(actions); |
|
651 |
switch (objects.size()) { |
|
652 |
case 0: |
|
653 |
try { |
|
654 |
c = pc.getConstructor(NOPARAMS); |
|
655 |
break; |
|
656 |
} catch (NoSuchMethodException ex) { |
|
657 |
// proceed to the one-param constructor |
|
658 |
objects.add(null); |
|
659 |
} |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
660 |
/* fall through */ |
2 | 661 |
case 1: |
662 |
try { |
|
663 |
c = pc.getConstructor(ONEPARAMS); |
|
664 |
break; |
|
665 |
} catch (NoSuchMethodException ex) { |
|
666 |
// proceed to the two-param constructor |
|
667 |
objects.add(null); |
|
668 |
} |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
669 |
/* fall through */ |
2 | 670 |
case 2: |
671 |
c = pc.getConstructor(TWOPARAMS); |
|
672 |
break; |
|
673 |
} |
|
674 |
Object parameters[] = objects.toArray(); |
|
675 |
Permission p = (Permission)c.newInstance(parameters); |
|
676 |
} |
|
677 |
||
678 |
/* |
|
679 |
* Parse command line arguments. |
|
680 |
*/ |
|
681 |
static void parseArgs(String args[]) { |
|
682 |
/* parse flags */ |
|
683 |
int n = 0; |
|
684 |
||
685 |
for (n=0; (n < args.length) && args[n].startsWith("-"); n++) { |
|
686 |
||
687 |
String flags = args[n]; |
|
688 |
||
689 |
if (collator.compare(flags, "-file") == 0) { |
|
690 |
if (++n == args.length) usage(); |
|
691 |
policyFileName = args[n]; |
|
692 |
} else { |
|
693 |
MessageFormat form = new MessageFormat(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
694 |
("Illegal.option.option")); |
2 | 695 |
Object[] source = { flags }; |
696 |
System.err.println(form.format(source)); |
|
697 |
usage(); |
|
698 |
} |
|
699 |
} |
|
700 |
} |
|
701 |
||
702 |
static void usage() { |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
703 |
System.out.println(rb.getString("Usage.policytool.options.")); |
2 | 704 |
System.out.println(); |
705 |
System.out.println(rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
706 |
(".file.file.policy.file.location")); |
2 | 707 |
System.out.println(); |
708 |
||
709 |
System.exit(1); |
|
710 |
} |
|
711 |
||
712 |
/** |
|
713 |
* run the PolicyTool |
|
714 |
*/ |
|
715 |
public static void main(String args[]) { |
|
716 |
parseArgs(args); |
|
717 |
ToolWindow tw = new ToolWindow(new PolicyTool()); |
|
718 |
tw.displayToolWindow(args); |
|
719 |
} |
|
720 |
||
721 |
// split instr to words according to capitalization, |
|
722 |
// like, AWTControl -> A W T Control |
|
723 |
// this method is for easy pronounciation |
|
724 |
static String splitToWords(String instr) { |
|
725 |
return instr.replaceAll("([A-Z])", " $1"); |
|
726 |
} |
|
727 |
||
728 |
} |
|
729 |
||
730 |
/** |
|
731 |
* Each entry in the policy configuration file is represented by a |
|
732 |
* PolicyEntry object. |
|
733 |
* |
|
734 |
* A PolicyEntry is a (CodeSource,Permission) pair. The |
|
735 |
* CodeSource contains the (URL, PublicKey) that together identify |
|
736 |
* where the Java bytecodes come from and who (if anyone) signed |
|
737 |
* them. The URL could refer to localhost. The URL could also be |
|
738 |
* null, meaning that this policy entry is given to all comers, as |
|
739 |
* long as they match the signer field. The signer could be null, |
|
740 |
* meaning the code is not signed. |
|
741 |
* |
|
742 |
* The Permission contains the (Type, Name, Action) triplet. |
|
743 |
* |
|
744 |
*/ |
|
745 |
class PolicyEntry { |
|
746 |
||
747 |
private CodeSource codesource; |
|
748 |
private PolicyTool tool; |
|
749 |
private PolicyParser.GrantEntry grantEntry; |
|
750 |
private boolean testing = false; |
|
751 |
||
752 |
/** |
|
753 |
* Create a PolicyEntry object from the information read in |
|
754 |
* from a policy file. |
|
755 |
*/ |
|
756 |
PolicyEntry(PolicyTool tool, PolicyParser.GrantEntry ge) |
|
757 |
throws MalformedURLException, NoSuchMethodException, |
|
758 |
ClassNotFoundException, InstantiationException, IllegalAccessException, |
|
759 |
InvocationTargetException, CertificateException, |
|
760 |
IOException, NoSuchAlgorithmException, UnrecoverableKeyException { |
|
761 |
||
762 |
this.tool = tool; |
|
763 |
||
764 |
URL location = null; |
|
765 |
||
766 |
// construct the CodeSource |
|
767 |
if (ge.codeBase != null) |
|
768 |
location = new URL(ge.codeBase); |
|
769 |
this.codesource = new CodeSource(location, |
|
770 |
(java.security.cert.Certificate[]) null); |
|
771 |
||
772 |
if (testing) { |
|
773 |
System.out.println("Adding Policy Entry:"); |
|
774 |
System.out.println(" CodeBase = " + location); |
|
775 |
System.out.println(" Signers = " + ge.signedBy); |
|
776 |
System.out.println(" with " + ge.principals.size() + |
|
777 |
" Principals"); |
|
778 |
} |
|
779 |
||
780 |
this.grantEntry = ge; |
|
781 |
} |
|
782 |
||
783 |
/** |
|
784 |
* get the codesource associated with this PolicyEntry |
|
785 |
*/ |
|
786 |
CodeSource getCodeSource() { |
|
787 |
return codesource; |
|
788 |
} |
|
789 |
||
790 |
/** |
|
791 |
* get the GrantEntry associated with this PolicyEntry |
|
792 |
*/ |
|
793 |
PolicyParser.GrantEntry getGrantEntry() { |
|
794 |
return grantEntry; |
|
795 |
} |
|
796 |
||
797 |
/** |
|
798 |
* convert the header portion, i.e. codebase, signer, principals, of |
|
799 |
* this policy entry into a string |
|
800 |
*/ |
|
801 |
String headerToString() { |
|
802 |
String pString = principalsToString(); |
|
803 |
if (pString.length() == 0) { |
|
804 |
return codebaseToString(); |
|
805 |
} else { |
|
806 |
return codebaseToString() + ", " + pString; |
|
807 |
} |
|
808 |
} |
|
809 |
||
810 |
/** |
|
811 |
* convert the Codebase/signer portion of this policy entry into a string |
|
812 |
*/ |
|
813 |
String codebaseToString() { |
|
814 |
||
815 |
String stringEntry = new String(); |
|
816 |
||
817 |
if (grantEntry.codeBase != null && |
|
818 |
grantEntry.codeBase.equals("") == false) |
|
819 |
stringEntry = stringEntry.concat |
|
820 |
("CodeBase \"" + |
|
821 |
grantEntry.codeBase + |
|
822 |
"\""); |
|
823 |
||
824 |
if (grantEntry.signedBy != null && |
|
825 |
grantEntry.signedBy.equals("") == false) |
|
826 |
stringEntry = ((stringEntry.length() > 0) ? |
|
827 |
stringEntry.concat(", SignedBy \"" + |
|
828 |
grantEntry.signedBy + |
|
829 |
"\"") : |
|
830 |
stringEntry.concat("SignedBy \"" + |
|
831 |
grantEntry.signedBy + |
|
832 |
"\"")); |
|
833 |
||
834 |
if (stringEntry.length() == 0) |
|
835 |
return new String("CodeBase <ALL>"); |
|
836 |
return stringEntry; |
|
837 |
} |
|
838 |
||
839 |
/** |
|
840 |
* convert the Principals portion of this policy entry into a string |
|
841 |
*/ |
|
842 |
String principalsToString() { |
|
843 |
String result = ""; |
|
844 |
if ((grantEntry.principals != null) && |
|
845 |
(!grantEntry.principals.isEmpty())) { |
|
846 |
StringBuffer buffer = new StringBuffer(200); |
|
847 |
ListIterator<PolicyParser.PrincipalEntry> list = |
|
848 |
grantEntry.principals.listIterator(); |
|
849 |
while (list.hasNext()) { |
|
850 |
PolicyParser.PrincipalEntry pppe = list.next(); |
|
851 |
buffer.append(" Principal " + pppe.getDisplayClass() + " " + |
|
852 |
pppe.getDisplayName(true)); |
|
853 |
if (list.hasNext()) buffer.append(", "); |
|
854 |
} |
|
855 |
result = buffer.toString(); |
|
856 |
} |
|
857 |
return result; |
|
858 |
} |
|
859 |
||
860 |
/** |
|
861 |
* convert this policy entry into a PolicyParser.PermissionEntry |
|
862 |
*/ |
|
863 |
PolicyParser.PermissionEntry toPermissionEntry(Permission perm) { |
|
864 |
||
865 |
String actions = null; |
|
866 |
||
867 |
// get the actions |
|
868 |
if (perm.getActions() != null && |
|
869 |
perm.getActions().trim() != "") |
|
870 |
actions = perm.getActions(); |
|
871 |
||
872 |
PolicyParser.PermissionEntry pe = new PolicyParser.PermissionEntry |
|
873 |
(perm.getClass().getName(), |
|
874 |
perm.getName(), |
|
875 |
actions); |
|
876 |
return pe; |
|
877 |
} |
|
878 |
} |
|
879 |
||
880 |
/** |
|
881 |
* The main window for the PolicyTool |
|
882 |
*/ |
|
883 |
class ToolWindow extends Frame { |
|
884 |
// use serialVersionUID from JDK 1.2.2 for interoperability |
|
885 |
private static final long serialVersionUID = 5682568601210376777L; |
|
886 |
||
887 |
/* external paddings */ |
|
888 |
public static final Insets TOP_PADDING = new Insets(25,0,0,0); |
|
889 |
public static final Insets BOTTOM_PADDING = new Insets(0,0,25,0); |
|
890 |
public static final Insets LITE_BOTTOM_PADDING = new Insets(0,0,10,0); |
|
891 |
public static final Insets LR_PADDING = new Insets(0,10,0,10); |
|
892 |
public static final Insets TOP_BOTTOM_PADDING = new Insets(15, 0, 15, 0); |
|
893 |
public static final Insets L_TOP_BOTTOM_PADDING = new Insets(5,10,15,0); |
|
894 |
public static final Insets LR_BOTTOM_PADDING = new Insets(0,10,5,10); |
|
895 |
public static final Insets L_BOTTOM_PADDING = new Insets(0,10,5,0); |
|
896 |
public static final Insets R_BOTTOM_PADDING = new Insets(0,0,5,10); |
|
897 |
||
898 |
/* buttons and menus */ |
|
899 |
public static final String NEW_POLICY_FILE = |
|
900 |
PolicyTool.rb.getString("New"); |
|
901 |
public static final String OPEN_POLICY_FILE = |
|
902 |
PolicyTool.rb.getString("Open"); |
|
903 |
public static final String SAVE_POLICY_FILE = |
|
904 |
PolicyTool.rb.getString("Save"); |
|
905 |
public static final String SAVE_AS_POLICY_FILE = |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
906 |
PolicyTool.rb.getString("Save.As"); |
2 | 907 |
public static final String VIEW_WARNINGS = |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
908 |
PolicyTool.rb.getString("View.Warning.Log"); |
2 | 909 |
public static final String QUIT = |
910 |
PolicyTool.rb.getString("Exit"); |
|
911 |
public static final String ADD_POLICY_ENTRY = |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
912 |
PolicyTool.rb.getString("Add.Policy.Entry"); |
2 | 913 |
public static final String EDIT_POLICY_ENTRY = |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
914 |
PolicyTool.rb.getString("Edit.Policy.Entry"); |
2 | 915 |
public static final String REMOVE_POLICY_ENTRY = |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
916 |
PolicyTool.rb.getString("Remove.Policy.Entry"); |
2 | 917 |
public static final String EDIT_KEYSTORE = |
918 |
PolicyTool.rb.getString("Edit"); |
|
919 |
public static final String ADD_PUBKEY_ALIAS = |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
920 |
PolicyTool.rb.getString("Add.Public.Key.Alias"); |
2 | 921 |
public static final String REMOVE_PUBKEY_ALIAS = |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
922 |
PolicyTool.rb.getString("Remove.Public.Key.Alias"); |
2 | 923 |
|
924 |
/* gridbag index for components in the main window (MW) */ |
|
925 |
public static final int MW_FILENAME_LABEL = 0; |
|
926 |
public static final int MW_FILENAME_TEXTFIELD = 1; |
|
927 |
public static final int MW_PANEL = 2; |
|
928 |
public static final int MW_ADD_BUTTON = 0; |
|
929 |
public static final int MW_EDIT_BUTTON = 1; |
|
930 |
public static final int MW_REMOVE_BUTTON = 2; |
|
931 |
public static final int MW_POLICY_LIST = 3; // follows MW_PANEL |
|
932 |
||
933 |
private PolicyTool tool; |
|
934 |
||
935 |
/** |
|
936 |
* Constructor |
|
937 |
*/ |
|
938 |
ToolWindow(PolicyTool tool) { |
|
939 |
this.tool = tool; |
|
940 |
} |
|
941 |
||
942 |
/** |
|
943 |
* Initialize the PolicyTool window with the necessary components |
|
944 |
*/ |
|
945 |
private void initWindow() { |
|
946 |
||
947 |
// create the top menu bar |
|
948 |
MenuBar menuBar = new MenuBar(); |
|
949 |
||
950 |
// create a File menu |
|
951 |
Menu menu = new Menu(PolicyTool.rb.getString("File")); |
|
952 |
menu.add(NEW_POLICY_FILE); |
|
953 |
menu.add(OPEN_POLICY_FILE); |
|
954 |
menu.add(SAVE_POLICY_FILE); |
|
955 |
menu.add(SAVE_AS_POLICY_FILE); |
|
956 |
menu.add(VIEW_WARNINGS); |
|
957 |
menu.add(QUIT); |
|
958 |
menu.addActionListener(new FileMenuListener(tool, this)); |
|
959 |
menuBar.add(menu); |
|
960 |
setMenuBar(menuBar); |
|
961 |
||
962 |
// create a KeyStore menu |
|
963 |
menu = new Menu(PolicyTool.rb.getString("KeyStore")); |
|
964 |
menu.add(EDIT_KEYSTORE); |
|
965 |
menu.addActionListener(new MainWindowListener(tool, this)); |
|
966 |
menuBar.add(menu); |
|
967 |
setMenuBar(menuBar); |
|
968 |
||
969 |
||
970 |
// policy entry listing |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
971 |
Label label = new Label(PolicyTool.rb.getString("Policy.File.")); |
2 | 972 |
addNewComponent(this, label, MW_FILENAME_LABEL, |
973 |
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
974 |
TOP_BOTTOM_PADDING); |
|
975 |
TextField tf = new TextField(50); |
|
976 |
tf.getAccessibleContext().setAccessibleName( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
977 |
PolicyTool.rb.getString("Policy.File.")); |
2 | 978 |
tf.setEditable(false); |
979 |
addNewComponent(this, tf, MW_FILENAME_TEXTFIELD, |
|
980 |
1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
981 |
TOP_BOTTOM_PADDING); |
|
982 |
||
983 |
||
984 |
// add ADD/REMOVE/EDIT buttons in a new panel |
|
985 |
Panel panel = new Panel(); |
|
986 |
panel.setLayout(new GridBagLayout()); |
|
987 |
||
988 |
Button button = new Button(ADD_POLICY_ENTRY); |
|
989 |
button.addActionListener(new MainWindowListener(tool, this)); |
|
990 |
addNewComponent(panel, button, MW_ADD_BUTTON, |
|
991 |
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
992 |
LR_PADDING); |
|
993 |
||
994 |
button = new Button(EDIT_POLICY_ENTRY); |
|
995 |
button.addActionListener(new MainWindowListener(tool, this)); |
|
996 |
addNewComponent(panel, button, MW_EDIT_BUTTON, |
|
997 |
1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
998 |
LR_PADDING); |
|
999 |
||
1000 |
button = new Button(REMOVE_POLICY_ENTRY); |
|
1001 |
button.addActionListener(new MainWindowListener(tool, this)); |
|
1002 |
addNewComponent(panel, button, MW_REMOVE_BUTTON, |
|
1003 |
2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
1004 |
LR_PADDING); |
|
1005 |
||
1006 |
addNewComponent(this, panel, MW_PANEL, |
|
1007 |
0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
1008 |
BOTTOM_PADDING); |
|
1009 |
||
1010 |
||
1011 |
String policyFile = tool.getPolicyFileName(); |
|
1012 |
if (policyFile == null) { |
|
1013 |
String userHome; |
|
1014 |
userHome = java.security.AccessController.doPrivileged( |
|
1015 |
new sun.security.action.GetPropertyAction("user.home")); |
|
1016 |
policyFile = userHome + File.separatorChar + ".java.policy"; |
|
1017 |
} |
|
1018 |
||
1019 |
try { |
|
1020 |
// open the policy file |
|
1021 |
tool.openPolicy(policyFile); |
|
1022 |
||
1023 |
// display the policy entries via the policy list textarea |
|
1024 |
List list = new List(40, false); |
|
1025 |
list.addActionListener(new PolicyListListener(tool, this)); |
|
1026 |
PolicyEntry entries[] = tool.getEntry(); |
|
1027 |
if (entries != null) { |
|
1028 |
for (int i = 0; i < entries.length; i++) |
|
1029 |
list.add(entries[i].headerToString()); |
|
1030 |
} |
|
1031 |
TextField newFilename = (TextField) |
|
1032 |
getComponent(MW_FILENAME_TEXTFIELD); |
|
1033 |
newFilename.setText(policyFile); |
|
1034 |
initPolicyList(list); |
|
1035 |
||
1036 |
} catch (FileNotFoundException fnfe) { |
|
1037 |
// add blank policy listing |
|
1038 |
List list = new List(40, false); |
|
1039 |
list.addActionListener(new PolicyListListener(tool, this)); |
|
1040 |
initPolicyList(list); |
|
1041 |
tool.setPolicyFileName(null); |
|
1042 |
tool.modified = false; |
|
1043 |
setVisible(true); |
|
1044 |
||
1045 |
// just add warning |
|
1046 |
tool.warnings.addElement(fnfe.toString()); |
|
1047 |
||
1048 |
} catch (Exception e) { |
|
1049 |
// add blank policy listing |
|
1050 |
List list = new List(40, false); |
|
1051 |
list.addActionListener(new PolicyListListener(tool, this)); |
|
1052 |
initPolicyList(list); |
|
1053 |
tool.setPolicyFileName(null); |
|
1054 |
tool.modified = false; |
|
1055 |
setVisible(true); |
|
1056 |
||
1057 |
// display the error |
|
1058 |
MessageFormat form = new MessageFormat(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1059 |
("Could.not.open.policy.file.policyFile.e.toString.")); |
2 | 1060 |
Object[] source = {policyFile, e.toString()}; |
1061 |
displayErrorDialog(null, form.format(source)); |
|
1062 |
} |
|
1063 |
} |
|
1064 |
||
1065 |
||
1066 |
/** |
|
1067 |
* Add a component to the PolicyTool window |
|
1068 |
*/ |
|
1069 |
void addNewComponent(Container container, Component component, |
|
1070 |
int index, int gridx, int gridy, int gridwidth, int gridheight, |
|
1071 |
double weightx, double weighty, int fill, Insets is) { |
|
1072 |
||
1073 |
// add the component at the specified gridbag index |
|
1074 |
container.add(component, index); |
|
1075 |
||
1076 |
// set the constraints |
|
1077 |
GridBagLayout gbl = (GridBagLayout)container.getLayout(); |
|
1078 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
1079 |
gbc.gridx = gridx; |
|
1080 |
gbc.gridy = gridy; |
|
1081 |
gbc.gridwidth = gridwidth; |
|
1082 |
gbc.gridheight = gridheight; |
|
1083 |
gbc.weightx = weightx; |
|
1084 |
gbc.weighty = weighty; |
|
1085 |
gbc.fill = fill; |
|
1086 |
if (is != null) gbc.insets = is; |
|
1087 |
gbl.setConstraints(component, gbc); |
|
1088 |
} |
|
1089 |
||
1090 |
||
1091 |
/** |
|
1092 |
* Add a component to the PolicyTool window without external padding |
|
1093 |
*/ |
|
1094 |
void addNewComponent(Container container, Component component, |
|
1095 |
int index, int gridx, int gridy, int gridwidth, int gridheight, |
|
1096 |
double weightx, double weighty, int fill) { |
|
1097 |
||
1098 |
// delegate with "null" external padding |
|
1099 |
addNewComponent(container, component, index, gridx, gridy, |
|
1100 |
gridwidth, gridheight, weightx, weighty, |
|
1101 |
fill, null); |
|
1102 |
} |
|
1103 |
||
1104 |
||
1105 |
/** |
|
1106 |
* Init the policy_entry_list TEXTAREA component in the |
|
1107 |
* PolicyTool window |
|
1108 |
*/ |
|
1109 |
void initPolicyList(List policyList) { |
|
1110 |
||
1111 |
// add the policy list to the window |
|
1112 |
addNewComponent(this, policyList, MW_POLICY_LIST, |
|
1113 |
0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.BOTH); |
|
1114 |
} |
|
1115 |
||
1116 |
/** |
|
1117 |
* Replace the policy_entry_list TEXTAREA component in the |
|
1118 |
* PolicyTool window with an updated one. |
|
1119 |
*/ |
|
1120 |
void replacePolicyList(List policyList) { |
|
1121 |
||
1122 |
// remove the original list of Policy Entries |
|
1123 |
// and add the new list of entries |
|
1124 |
List list = (List)getComponent(MW_POLICY_LIST); |
|
1125 |
list.removeAll(); |
|
1126 |
String newItems[] = policyList.getItems(); |
|
1127 |
for (int i = 0; i < newItems.length; i++) |
|
1128 |
list.add(newItems[i]); |
|
1129 |
} |
|
1130 |
||
1131 |
/** |
|
1132 |
* display the main PolicyTool window |
|
1133 |
*/ |
|
1134 |
void displayToolWindow(String args[]) { |
|
1135 |
||
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1136 |
setTitle(PolicyTool.rb.getString("Policy.Tool")); |
2 | 1137 |
setResizable(true); |
1138 |
addWindowListener(new ToolWindowListener(this)); |
|
1139 |
setBounds(135, 80, 500, 500); |
|
1140 |
setLayout(new GridBagLayout()); |
|
1141 |
||
1142 |
initWindow(); |
|
1143 |
||
1144 |
// display it |
|
1145 |
setVisible(true); |
|
1146 |
||
1147 |
if (tool.newWarning == true) { |
|
1148 |
displayStatusDialog(this, PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1149 |
("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information.")); |
2 | 1150 |
} |
1151 |
} |
|
1152 |
||
1153 |
/** |
|
1154 |
* displays a dialog box describing an error which occurred. |
|
1155 |
*/ |
|
1156 |
void displayErrorDialog(Window w, String error) { |
|
1157 |
ToolDialog ed = new ToolDialog |
|
1158 |
(PolicyTool.rb.getString("Error"), tool, this, true); |
|
1159 |
||
1160 |
// find where the PolicyTool gui is |
|
1161 |
Point location = ((w == null) ? |
|
1162 |
getLocationOnScreen() : w.getLocationOnScreen()); |
|
1163 |
ed.setBounds(location.x + 50, location.y + 50, 600, 100); |
|
1164 |
ed.setLayout(new GridBagLayout()); |
|
1165 |
||
1166 |
Label label = new Label(error); |
|
1167 |
addNewComponent(ed, label, 0, |
|
1168 |
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); |
|
1169 |
||
1170 |
Button okButton = new Button(PolicyTool.rb.getString("OK")); |
|
1171 |
okButton.addActionListener(new ErrorOKButtonListener(ed)); |
|
1172 |
addNewComponent(ed, okButton, 1, |
|
1173 |
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); |
|
1174 |
||
1175 |
ed.pack(); |
|
1176 |
ed.setVisible(true); |
|
1177 |
} |
|
1178 |
||
1179 |
/** |
|
1180 |
* displays a dialog box describing an error which occurred. |
|
1181 |
*/ |
|
1182 |
void displayErrorDialog(Window w, Throwable t) { |
|
1183 |
if (t instanceof NoDisplayException) { |
|
1184 |
return; |
|
1185 |
} |
|
1186 |
displayErrorDialog(w, t.toString()); |
|
1187 |
} |
|
1188 |
||
1189 |
/** |
|
1190 |
* displays a dialog box describing the status of an event |
|
1191 |
*/ |
|
1192 |
void displayStatusDialog(Window w, String status) { |
|
1193 |
ToolDialog sd = new ToolDialog |
|
1194 |
(PolicyTool.rb.getString("Status"), tool, this, true); |
|
1195 |
||
1196 |
// find the location of the PolicyTool gui |
|
1197 |
Point location = ((w == null) ? |
|
1198 |
getLocationOnScreen() : w.getLocationOnScreen()); |
|
1199 |
sd.setBounds(location.x + 50, location.y + 50, 500, 100); |
|
1200 |
sd.setLayout(new GridBagLayout()); |
|
1201 |
||
1202 |
Label label = new Label(status); |
|
1203 |
addNewComponent(sd, label, 0, |
|
1204 |
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); |
|
1205 |
||
1206 |
Button okButton = new Button(PolicyTool.rb.getString("OK")); |
|
1207 |
okButton.addActionListener(new StatusOKButtonListener(sd)); |
|
1208 |
addNewComponent(sd, okButton, 1, |
|
1209 |
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); |
|
1210 |
sd.pack(); |
|
1211 |
sd.setVisible(true); |
|
1212 |
} |
|
1213 |
||
1214 |
/** |
|
1215 |
* display the warning log |
|
1216 |
*/ |
|
1217 |
void displayWarningLog(Window w) { |
|
1218 |
||
1219 |
ToolDialog wd = new ToolDialog |
|
1220 |
(PolicyTool.rb.getString("Warning"), tool, this, true); |
|
1221 |
||
1222 |
// find the location of the PolicyTool gui |
|
1223 |
Point location = ((w == null) ? |
|
1224 |
getLocationOnScreen() : w.getLocationOnScreen()); |
|
1225 |
wd.setBounds(location.x + 50, location.y + 50, 500, 100); |
|
1226 |
wd.setLayout(new GridBagLayout()); |
|
1227 |
||
1228 |
TextArea ta = new TextArea(); |
|
1229 |
ta.setEditable(false); |
|
1230 |
for (int i = 0; i < tool.warnings.size(); i++) { |
|
1231 |
ta.append(tool.warnings.elementAt(i)); |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1232 |
ta.append(PolicyTool.rb.getString("NEWLINE")); |
2 | 1233 |
} |
1234 |
addNewComponent(wd, ta, 0, |
|
1235 |
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
1236 |
BOTTOM_PADDING); |
|
1237 |
ta.setFocusable(false); |
|
1238 |
||
1239 |
Button okButton = new Button(PolicyTool.rb.getString("OK")); |
|
1240 |
okButton.addActionListener(new CancelButtonListener(wd)); |
|
1241 |
addNewComponent(wd, okButton, 1, |
|
1242 |
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, |
|
1243 |
LR_PADDING); |
|
1244 |
||
1245 |
wd.pack(); |
|
1246 |
wd.setVisible(true); |
|
1247 |
} |
|
1248 |
||
1249 |
char displayYesNoDialog(Window w, String title, String prompt, String yes, String no) { |
|
1250 |
||
1251 |
final ToolDialog tw = new ToolDialog |
|
1252 |
(title, tool, this, true); |
|
1253 |
Point location = ((w == null) ? |
|
1254 |
getLocationOnScreen() : w.getLocationOnScreen()); |
|
1255 |
tw.setBounds(location.x + 75, location.y + 100, 400, 150); |
|
1256 |
tw.setLayout(new GridBagLayout()); |
|
1257 |
||
1258 |
TextArea ta = new TextArea(prompt, 10, 50, TextArea.SCROLLBARS_VERTICAL_ONLY); |
|
1259 |
ta.setEditable(false); |
|
1260 |
addNewComponent(tw, ta, 0, |
|
1261 |
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); |
|
1262 |
ta.setFocusable(false); |
|
1263 |
||
1264 |
Panel panel = new Panel(); |
|
1265 |
panel.setLayout(new GridBagLayout()); |
|
1266 |
||
1267 |
// StringBuffer to store button press. Must be final. |
|
1268 |
final StringBuffer chooseResult = new StringBuffer(); |
|
1269 |
||
1270 |
Button button = new Button(yes); |
|
1271 |
button.addActionListener(new ActionListener() { |
|
1272 |
public void actionPerformed(ActionEvent e) { |
|
1273 |
chooseResult.append('Y'); |
|
1274 |
tw.setVisible(false); |
|
1275 |
tw.dispose(); |
|
1276 |
} |
|
1277 |
}); |
|
1278 |
addNewComponent(panel, button, 0, |
|
1279 |
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, |
|
1280 |
LR_PADDING); |
|
1281 |
||
1282 |
button = new Button(no); |
|
1283 |
button.addActionListener(new ActionListener() { |
|
1284 |
public void actionPerformed(ActionEvent e) { |
|
1285 |
chooseResult.append('N'); |
|
1286 |
tw.setVisible(false); |
|
1287 |
tw.dispose(); |
|
1288 |
} |
|
1289 |
}); |
|
1290 |
addNewComponent(panel, button, 1, |
|
1291 |
1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, |
|
1292 |
LR_PADDING); |
|
1293 |
||
1294 |
addNewComponent(tw, panel, 1, |
|
1295 |
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); |
|
1296 |
||
1297 |
tw.pack(); |
|
1298 |
tw.setVisible(true); |
|
1299 |
if (chooseResult.length() > 0) { |
|
1300 |
return chooseResult.charAt(0); |
|
1301 |
} else { |
|
1302 |
// I did encounter this once, don't why. |
|
1303 |
return 'N'; |
|
1304 |
} |
|
1305 |
} |
|
1306 |
||
1307 |
} |
|
1308 |
||
1309 |
/** |
|
1310 |
* General dialog window |
|
1311 |
*/ |
|
1312 |
class ToolDialog extends Dialog { |
|
1313 |
// use serialVersionUID from JDK 1.2.2 for interoperability |
|
1314 |
private static final long serialVersionUID = -372244357011301190L; |
|
1315 |
||
1316 |
/* necessary constants */ |
|
1317 |
public static final int NOACTION = 0; |
|
1318 |
public static final int QUIT = 1; |
|
1319 |
public static final int NEW = 2; |
|
1320 |
public static final int OPEN = 3; |
|
1321 |
||
1322 |
public static final String ALL_PERM_CLASS = |
|
1323 |
"java.security.AllPermission"; |
|
1324 |
public static final String FILE_PERM_CLASS = |
|
1325 |
"java.io.FilePermission"; |
|
1326 |
||
1327 |
public static final String X500_PRIN_CLASS = |
|
1328 |
"javax.security.auth.x500.X500Principal"; |
|
1329 |
||
1330 |
/* popup menus */ |
|
1331 |
public static final String PERM = |
|
1332 |
PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1333 |
("Permission."); |
2 | 1334 |
|
1335 |
public static final String PRIN_TYPE = |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1336 |
PolicyTool.rb.getString("Principal.Type."); |
2 | 1337 |
public static final String PRIN_NAME = |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1338 |
PolicyTool.rb.getString("Principal.Name."); |
2 | 1339 |
|
1340 |
/* more popu menus */ |
|
1341 |
public static final String PERM_NAME = |
|
1342 |
PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1343 |
("Target.Name."); |
2 | 1344 |
|
1345 |
/* and more popup menus */ |
|
1346 |
public static final String PERM_ACTIONS = |
|
1347 |
PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1348 |
("Actions."); |
2 | 1349 |
|
1350 |
/* gridbag index for display PolicyEntry (PE) components */ |
|
1351 |
public static final int PE_CODEBASE_LABEL = 0; |
|
1352 |
public static final int PE_CODEBASE_TEXTFIELD = 1; |
|
1353 |
public static final int PE_SIGNEDBY_LABEL = 2; |
|
1354 |
public static final int PE_SIGNEDBY_TEXTFIELD = 3; |
|
1355 |
||
1356 |
public static final int PE_PANEL0 = 4; |
|
1357 |
public static final int PE_ADD_PRIN_BUTTON = 0; |
|
1358 |
public static final int PE_EDIT_PRIN_BUTTON = 1; |
|
1359 |
public static final int PE_REMOVE_PRIN_BUTTON = 2; |
|
1360 |
||
1361 |
public static final int PE_PRIN_LABEL = 5; |
|
1362 |
public static final int PE_PRIN_LIST = 6; |
|
1363 |
||
1364 |
public static final int PE_PANEL1 = 7; |
|
1365 |
public static final int PE_ADD_PERM_BUTTON = 0; |
|
1366 |
public static final int PE_EDIT_PERM_BUTTON = 1; |
|
1367 |
public static final int PE_REMOVE_PERM_BUTTON = 2; |
|
1368 |
||
1369 |
public static final int PE_PERM_LIST = 8; |
|
1370 |
||
1371 |
public static final int PE_PANEL2 = 9; |
|
1372 |
public static final int PE_CANCEL_BUTTON = 1; |
|
1373 |
public static final int PE_DONE_BUTTON = 0; |
|
1374 |
||
1375 |
/* the gridbag index for components in the Principal Dialog (PRD) */ |
|
1376 |
public static final int PRD_DESC_LABEL = 0; |
|
1377 |
public static final int PRD_PRIN_CHOICE = 1; |
|
1378 |
public static final int PRD_PRIN_TEXTFIELD = 2; |
|
1379 |
public static final int PRD_NAME_LABEL = 3; |
|
1380 |
public static final int PRD_NAME_TEXTFIELD = 4; |
|
1381 |
public static final int PRD_CANCEL_BUTTON = 6; |
|
1382 |
public static final int PRD_OK_BUTTON = 5; |
|
1383 |
||
1384 |
/* the gridbag index for components in the Permission Dialog (PD) */ |
|
1385 |
public static final int PD_DESC_LABEL = 0; |
|
1386 |
public static final int PD_PERM_CHOICE = 1; |
|
1387 |
public static final int PD_PERM_TEXTFIELD = 2; |
|
1388 |
public static final int PD_NAME_CHOICE = 3; |
|
1389 |
public static final int PD_NAME_TEXTFIELD = 4; |
|
1390 |
public static final int PD_ACTIONS_CHOICE = 5; |
|
1391 |
public static final int PD_ACTIONS_TEXTFIELD = 6; |
|
1392 |
public static final int PD_SIGNEDBY_LABEL = 7; |
|
1393 |
public static final int PD_SIGNEDBY_TEXTFIELD = 8; |
|
1394 |
public static final int PD_CANCEL_BUTTON = 10; |
|
1395 |
public static final int PD_OK_BUTTON = 9; |
|
1396 |
||
1397 |
/* modes for KeyStore */ |
|
1398 |
public static final int EDIT_KEYSTORE = 0; |
|
1399 |
||
1400 |
/* the gridbag index for components in the Change KeyStore Dialog (KSD) */ |
|
1401 |
public static final int KSD_NAME_LABEL = 0; |
|
1402 |
public static final int KSD_NAME_TEXTFIELD = 1; |
|
1403 |
public static final int KSD_TYPE_LABEL = 2; |
|
1404 |
public static final int KSD_TYPE_TEXTFIELD = 3; |
|
1405 |
public static final int KSD_PROVIDER_LABEL = 4; |
|
1406 |
public static final int KSD_PROVIDER_TEXTFIELD = 5; |
|
1407 |
public static final int KSD_PWD_URL_LABEL = 6; |
|
1408 |
public static final int KSD_PWD_URL_TEXTFIELD = 7; |
|
1409 |
public static final int KSD_CANCEL_BUTTON = 9; |
|
1410 |
public static final int KSD_OK_BUTTON = 8; |
|
1411 |
||
1412 |
/* the gridbag index for components in the User Save Changes Dialog (USC) */ |
|
1413 |
public static final int USC_LABEL = 0; |
|
1414 |
public static final int USC_PANEL = 1; |
|
1415 |
public static final int USC_YES_BUTTON = 0; |
|
1416 |
public static final int USC_NO_BUTTON = 1; |
|
1417 |
public static final int USC_CANCEL_BUTTON = 2; |
|
1418 |
||
1419 |
/* gridbag index for the ConfirmRemovePolicyEntryDialog (CRPE) */ |
|
1420 |
public static final int CRPE_LABEL1 = 0; |
|
1421 |
public static final int CRPE_LABEL2 = 1; |
|
1422 |
public static final int CRPE_PANEL = 2; |
|
1423 |
public static final int CRPE_PANEL_OK = 0; |
|
1424 |
public static final int CRPE_PANEL_CANCEL = 1; |
|
1425 |
||
1426 |
/* some private static finals */ |
|
1427 |
private static final int PERMISSION = 0; |
|
1428 |
private static final int PERMISSION_NAME = 1; |
|
1429 |
private static final int PERMISSION_ACTIONS = 2; |
|
1430 |
private static final int PERMISSION_SIGNEDBY = 3; |
|
1431 |
private static final int PRINCIPAL_TYPE = 4; |
|
1432 |
private static final int PRINCIPAL_NAME = 5; |
|
1433 |
||
1434 |
public static java.util.ArrayList<Perm> PERM_ARRAY; |
|
1435 |
public static java.util.ArrayList<Prin> PRIN_ARRAY; |
|
1436 |
PolicyTool tool; |
|
1437 |
ToolWindow tw; |
|
1438 |
||
1439 |
static { |
|
1440 |
||
1441 |
// set up permission objects |
|
1442 |
||
1443 |
PERM_ARRAY = new java.util.ArrayList<Perm>(); |
|
1444 |
PERM_ARRAY.add(new AllPerm()); |
|
1445 |
PERM_ARRAY.add(new AudioPerm()); |
|
1446 |
PERM_ARRAY.add(new AuthPerm()); |
|
1447 |
PERM_ARRAY.add(new AWTPerm()); |
|
1448 |
PERM_ARRAY.add(new DelegationPerm()); |
|
1449 |
PERM_ARRAY.add(new FilePerm()); |
|
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
20754
diff
changeset
|
1450 |
PERM_ARRAY.add(new URLPerm()); |
3482
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
715
diff
changeset
|
1451 |
PERM_ARRAY.add(new InqSecContextPerm()); |
2 | 1452 |
PERM_ARRAY.add(new LogPerm()); |
1453 |
PERM_ARRAY.add(new MgmtPerm()); |
|
1454 |
PERM_ARRAY.add(new MBeanPerm()); |
|
1455 |
PERM_ARRAY.add(new MBeanSvrPerm()); |
|
1456 |
PERM_ARRAY.add(new MBeanTrustPerm()); |
|
1457 |
PERM_ARRAY.add(new NetPerm()); |
|
1458 |
PERM_ARRAY.add(new PrivCredPerm()); |
|
1459 |
PERM_ARRAY.add(new PropPerm()); |
|
1460 |
PERM_ARRAY.add(new ReflectPerm()); |
|
1461 |
PERM_ARRAY.add(new RuntimePerm()); |
|
1462 |
PERM_ARRAY.add(new SecurityPerm()); |
|
1463 |
PERM_ARRAY.add(new SerialPerm()); |
|
1464 |
PERM_ARRAY.add(new ServicePerm()); |
|
1465 |
PERM_ARRAY.add(new SocketPerm()); |
|
1466 |
PERM_ARRAY.add(new SQLPerm()); |
|
1467 |
PERM_ARRAY.add(new SSLPerm()); |
|
1468 |
PERM_ARRAY.add(new SubjDelegPerm()); |
|
1469 |
||
1470 |
// set up principal objects |
|
1471 |
||
1472 |
PRIN_ARRAY = new java.util.ArrayList<Prin>(); |
|
1473 |
PRIN_ARRAY.add(new KrbPrin()); |
|
1474 |
PRIN_ARRAY.add(new X500Prin()); |
|
1475 |
} |
|
1476 |
||
1477 |
ToolDialog(String title, PolicyTool tool, ToolWindow tw, boolean modal) { |
|
1478 |
super(tw, modal); |
|
1479 |
setTitle(title); |
|
1480 |
this.tool = tool; |
|
1481 |
this.tw = tw; |
|
1482 |
addWindowListener(new ChildWindowListener(this)); |
|
1483 |
} |
|
1484 |
||
1485 |
/** |
|
1486 |
* get the Perm instance based on either the (shortened) class name |
|
1487 |
* or the fully qualified class name |
|
1488 |
*/ |
|
1489 |
static Perm getPerm(String clazz, boolean fullClassName) { |
|
1490 |
for (int i = 0; i < PERM_ARRAY.size(); i++) { |
|
1491 |
Perm next = PERM_ARRAY.get(i); |
|
1492 |
if (fullClassName) { |
|
1493 |
if (next.FULL_CLASS.equals(clazz)) { |
|
1494 |
return next; |
|
1495 |
} |
|
1496 |
} else { |
|
1497 |
if (next.CLASS.equals(clazz)) { |
|
1498 |
return next; |
|
1499 |
} |
|
1500 |
} |
|
1501 |
} |
|
1502 |
return null; |
|
1503 |
} |
|
1504 |
||
1505 |
/** |
|
1506 |
* get the Prin instance based on either the (shortened) class name |
|
1507 |
* or the fully qualified class name |
|
1508 |
*/ |
|
1509 |
static Prin getPrin(String clazz, boolean fullClassName) { |
|
1510 |
for (int i = 0; i < PRIN_ARRAY.size(); i++) { |
|
1511 |
Prin next = PRIN_ARRAY.get(i); |
|
1512 |
if (fullClassName) { |
|
1513 |
if (next.FULL_CLASS.equals(clazz)) { |
|
1514 |
return next; |
|
1515 |
} |
|
1516 |
} else { |
|
1517 |
if (next.CLASS.equals(clazz)) { |
|
1518 |
return next; |
|
1519 |
} |
|
1520 |
} |
|
1521 |
} |
|
1522 |
return null; |
|
1523 |
} |
|
1524 |
||
1525 |
/** |
|
1526 |
* pop up a dialog so the user can enter info to add a new PolicyEntry |
|
1527 |
* - if edit is TRUE, then the user is editing an existing entry |
|
1528 |
* and we should display the original info as well. |
|
1529 |
* |
|
1530 |
* - the other reason we need the 'edit' boolean is we need to know |
|
1531 |
* when we are adding a NEW policy entry. in this case, we can |
|
1532 |
* not simply update the existing entry, because it doesn't exist. |
|
1533 |
* we ONLY update the GUI listing/info, and then when the user |
|
1534 |
* finally clicks 'OK' or 'DONE', then we can collect that info |
|
1535 |
* and add it to the policy. |
|
1536 |
*/ |
|
1537 |
void displayPolicyEntryDialog(boolean edit) { |
|
1538 |
||
1539 |
int listIndex = 0; |
|
1540 |
PolicyEntry entries[] = null; |
|
1541 |
TaggedList prinList = new TaggedList(3, false); |
|
1542 |
prinList.getAccessibleContext().setAccessibleName( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1543 |
PolicyTool.rb.getString("Principal.List")); |
2 | 1544 |
prinList.addActionListener |
1545 |
(new EditPrinButtonListener(tool, tw, this, edit)); |
|
1546 |
TaggedList permList = new TaggedList(10, false); |
|
1547 |
permList.getAccessibleContext().setAccessibleName( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1548 |
PolicyTool.rb.getString("Permission.List")); |
2 | 1549 |
permList.addActionListener |
1550 |
(new EditPermButtonListener(tool, tw, this, edit)); |
|
1551 |
||
1552 |
// find where the PolicyTool gui is |
|
1553 |
Point location = tw.getLocationOnScreen(); |
|
1554 |
setBounds(location.x + 75, location.y + 200, 650, 500); |
|
1555 |
setLayout(new GridBagLayout()); |
|
1556 |
setResizable(true); |
|
1557 |
||
1558 |
if (edit) { |
|
1559 |
// get the selected item |
|
1560 |
entries = tool.getEntry(); |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1561 |
List policyList = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST); |
2 | 1562 |
listIndex = policyList.getSelectedIndex(); |
1563 |
||
1564 |
// get principal list |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1565 |
LinkedList<PolicyParser.PrincipalEntry> principals = |
2 | 1566 |
entries[listIndex].getGrantEntry().principals; |
1567 |
for (int i = 0; i < principals.size(); i++) { |
|
1568 |
String prinString = null; |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1569 |
PolicyParser.PrincipalEntry nextPrin = principals.get(i); |
2 | 1570 |
prinList.addTaggedItem(PrincipalEntryToUserFriendlyString(nextPrin), nextPrin); |
1571 |
} |
|
1572 |
||
1573 |
// get permission list |
|
1574 |
Vector<PolicyParser.PermissionEntry> permissions = |
|
1575 |
entries[listIndex].getGrantEntry().permissionEntries; |
|
1576 |
for (int i = 0; i < permissions.size(); i++) { |
|
1577 |
String permString = null; |
|
1578 |
PolicyParser.PermissionEntry nextPerm = |
|
1579 |
permissions.elementAt(i); |
|
1580 |
permList.addTaggedItem(ToolDialog.PermissionEntryToUserFriendlyString(nextPerm), nextPerm); |
|
1581 |
} |
|
1582 |
} |
|
1583 |
||
1584 |
// codebase label and textfield |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1585 |
Label label = new Label(PolicyTool.rb.getString("CodeBase.")); |
2 | 1586 |
tw.addNewComponent(this, label, PE_CODEBASE_LABEL, |
1587 |
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); |
|
1588 |
TextField tf; |
|
1589 |
tf = (edit ? |
|
1590 |
new TextField(entries[listIndex].getGrantEntry().codeBase, 60) : |
|
1591 |
new TextField(60)); |
|
1592 |
tf.getAccessibleContext().setAccessibleName( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1593 |
PolicyTool.rb.getString("Code.Base")); |
2 | 1594 |
tw.addNewComponent(this, tf, PE_CODEBASE_TEXTFIELD, |
1595 |
1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); |
|
1596 |
||
1597 |
// signedby label and textfield |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1598 |
label = new Label(PolicyTool.rb.getString("SignedBy.")); |
2 | 1599 |
tw.addNewComponent(this, label, PE_SIGNEDBY_LABEL, |
1600 |
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); |
|
1601 |
tf = (edit ? |
|
1602 |
new TextField(entries[listIndex].getGrantEntry().signedBy, 60) : |
|
1603 |
new TextField(60)); |
|
1604 |
tf.getAccessibleContext().setAccessibleName( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1605 |
PolicyTool.rb.getString("Signed.By.")); |
2 | 1606 |
tw.addNewComponent(this, tf, PE_SIGNEDBY_TEXTFIELD, |
1607 |
1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); |
|
1608 |
||
1609 |
// panel for principal buttons |
|
1610 |
Panel panel = new Panel(); |
|
1611 |
panel.setLayout(new GridBagLayout()); |
|
1612 |
||
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1613 |
Button button = new Button(PolicyTool.rb.getString("Add.Principal")); |
2 | 1614 |
button.addActionListener |
1615 |
(new AddPrinButtonListener(tool, tw, this, edit)); |
|
1616 |
tw.addNewComponent(panel, button, PE_ADD_PRIN_BUTTON, |
|
1617 |
0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); |
|
1618 |
||
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1619 |
button = new Button(PolicyTool.rb.getString("Edit.Principal")); |
2 | 1620 |
button.addActionListener(new EditPrinButtonListener |
1621 |
(tool, tw, this, edit)); |
|
1622 |
tw.addNewComponent(panel, button, PE_EDIT_PRIN_BUTTON, |
|
1623 |
1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); |
|
1624 |
||
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1625 |
button = new Button(PolicyTool.rb.getString("Remove.Principal")); |
2 | 1626 |
button.addActionListener(new RemovePrinButtonListener |
1627 |
(tool, tw, this, edit)); |
|
1628 |
tw.addNewComponent(panel, button, PE_REMOVE_PRIN_BUTTON, |
|
1629 |
2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); |
|
1630 |
||
1631 |
tw.addNewComponent(this, panel, PE_PANEL0, |
|
1632 |
1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL); |
|
1633 |
||
1634 |
// principal label and list |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1635 |
label = new Label(PolicyTool.rb.getString("Principals.")); |
2 | 1636 |
tw.addNewComponent(this, label, PE_PRIN_LABEL, |
1637 |
0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1638 |
ToolWindow.BOTTOM_PADDING); |
2 | 1639 |
tw.addNewComponent(this, prinList, PE_PRIN_LIST, |
1640 |
1, 3, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1641 |
ToolWindow.BOTTOM_PADDING); |
2 | 1642 |
|
1643 |
// panel for permission buttons |
|
1644 |
panel = new Panel(); |
|
1645 |
panel.setLayout(new GridBagLayout()); |
|
1646 |
||
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1647 |
button = new Button(PolicyTool.rb.getString(".Add.Permission")); |
2 | 1648 |
button.addActionListener(new AddPermButtonListener |
1649 |
(tool, tw, this, edit)); |
|
1650 |
tw.addNewComponent(panel, button, PE_ADD_PERM_BUTTON, |
|
1651 |
0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); |
|
1652 |
||
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1653 |
button = new Button(PolicyTool.rb.getString(".Edit.Permission")); |
2 | 1654 |
button.addActionListener(new EditPermButtonListener |
1655 |
(tool, tw, this, edit)); |
|
1656 |
tw.addNewComponent(panel, button, PE_EDIT_PERM_BUTTON, |
|
1657 |
1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); |
|
1658 |
||
1659 |
||
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1660 |
button = new Button(PolicyTool.rb.getString("Remove.Permission")); |
2 | 1661 |
button.addActionListener(new RemovePermButtonListener |
1662 |
(tool, tw, this, edit)); |
|
1663 |
tw.addNewComponent(panel, button, PE_REMOVE_PERM_BUTTON, |
|
1664 |
2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL); |
|
1665 |
||
1666 |
tw.addNewComponent(this, panel, PE_PANEL1, |
|
1667 |
0, 4, 2, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1668 |
ToolWindow.LITE_BOTTOM_PADDING); |
2 | 1669 |
|
1670 |
// permission list |
|
1671 |
tw.addNewComponent(this, permList, PE_PERM_LIST, |
|
1672 |
0, 5, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1673 |
ToolWindow.BOTTOM_PADDING); |
2 | 1674 |
|
1675 |
||
1676 |
// panel for Done and Cancel buttons |
|
1677 |
panel = new Panel(); |
|
1678 |
panel.setLayout(new GridBagLayout()); |
|
1679 |
||
1680 |
// Done Button |
|
1681 |
button = new Button(PolicyTool.rb.getString("Done")); |
|
1682 |
button.addActionListener |
|
1683 |
(new AddEntryDoneButtonListener(tool, tw, this, edit)); |
|
1684 |
tw.addNewComponent(panel, button, PE_DONE_BUTTON, |
|
1685 |
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1686 |
ToolWindow.LR_PADDING); |
2 | 1687 |
|
1688 |
// Cancel Button |
|
1689 |
button = new Button(PolicyTool.rb.getString("Cancel")); |
|
1690 |
button.addActionListener(new CancelButtonListener(this)); |
|
1691 |
tw.addNewComponent(panel, button, PE_CANCEL_BUTTON, |
|
1692 |
1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1693 |
ToolWindow.LR_PADDING); |
2 | 1694 |
|
1695 |
// add the panel |
|
1696 |
tw.addNewComponent(this, panel, PE_PANEL2, |
|
1697 |
0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); |
|
1698 |
||
1699 |
setVisible(true); |
|
1700 |
} |
|
1701 |
||
1702 |
/** |
|
1703 |
* Read all the Policy information data in the dialog box |
|
1704 |
* and construct a PolicyEntry object with it. |
|
1705 |
*/ |
|
1706 |
PolicyEntry getPolicyEntryFromDialog() |
|
1707 |
throws InvalidParameterException, MalformedURLException, |
|
1708 |
NoSuchMethodException, ClassNotFoundException, InstantiationException, |
|
1709 |
IllegalAccessException, InvocationTargetException, |
|
1710 |
CertificateException, IOException, Exception { |
|
1711 |
||
1712 |
// get the Codebase |
|
1713 |
TextField tf = (TextField)getComponent(PE_CODEBASE_TEXTFIELD); |
|
1714 |
String codebase = null; |
|
1715 |
if (tf.getText().trim().equals("") == false) |
|
1716 |
codebase = new String(tf.getText().trim()); |
|
1717 |
||
1718 |
// get the SignedBy |
|
1719 |
tf = (TextField)getComponent(PE_SIGNEDBY_TEXTFIELD); |
|
1720 |
String signedby = null; |
|
1721 |
if (tf.getText().trim().equals("") == false) |
|
1722 |
signedby = new String(tf.getText().trim()); |
|
1723 |
||
1724 |
// construct a new GrantEntry |
|
1725 |
PolicyParser.GrantEntry ge = |
|
1726 |
new PolicyParser.GrantEntry(signedby, codebase); |
|
1727 |
||
1728 |
// get the new Principals |
|
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
7532
diff
changeset
|
1729 |
LinkedList<PolicyParser.PrincipalEntry> prins = new LinkedList<>(); |
2 | 1730 |
TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST); |
1731 |
for (int i = 0; i < prinList.getItemCount(); i++) { |
|
1732 |
prins.add((PolicyParser.PrincipalEntry)prinList.getObject(i)); |
|
1733 |
} |
|
1734 |
ge.principals = prins; |
|
1735 |
||
1736 |
// get the new Permissions |
|
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
7532
diff
changeset
|
1737 |
Vector<PolicyParser.PermissionEntry> perms = new Vector<>(); |
2 | 1738 |
TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST); |
1739 |
for (int i = 0; i < permList.getItemCount(); i++) { |
|
1740 |
perms.addElement((PolicyParser.PermissionEntry)permList.getObject(i)); |
|
1741 |
} |
|
1742 |
ge.permissionEntries = perms; |
|
1743 |
||
1744 |
// construct a new PolicyEntry object |
|
1745 |
PolicyEntry entry = new PolicyEntry(tool, ge); |
|
1746 |
||
1747 |
return entry; |
|
1748 |
} |
|
1749 |
||
1750 |
/** |
|
1751 |
* display a dialog box for the user to enter KeyStore information |
|
1752 |
*/ |
|
1753 |
void keyStoreDialog(int mode) { |
|
1754 |
||
1755 |
// find where the PolicyTool gui is |
|
1756 |
Point location = tw.getLocationOnScreen(); |
|
1757 |
setBounds(location.x + 25, location.y + 100, 500, 300); |
|
1758 |
setLayout(new GridBagLayout()); |
|
1759 |
||
1760 |
if (mode == EDIT_KEYSTORE) { |
|
1761 |
||
1762 |
// KeyStore label and textfield |
|
1763 |
Label label = new Label |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1764 |
(PolicyTool.rb.getString("KeyStore.URL.")); |
2 | 1765 |
tw.addNewComponent(this, label, KSD_NAME_LABEL, |
1766 |
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1767 |
ToolWindow.BOTTOM_PADDING); |
2 | 1768 |
TextField tf = new TextField(tool.getKeyStoreName(), 30); |
1769 |
||
1770 |
// URL to U R L, so that accessibility reader will pronounce well |
|
1771 |
tf.getAccessibleContext().setAccessibleName( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1772 |
PolicyTool.rb.getString("KeyStore.U.R.L.")); |
2 | 1773 |
tw.addNewComponent(this, tf, KSD_NAME_TEXTFIELD, |
1774 |
1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1775 |
ToolWindow.BOTTOM_PADDING); |
2 | 1776 |
|
1777 |
// KeyStore type and textfield |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1778 |
label = new Label(PolicyTool.rb.getString("KeyStore.Type.")); |
2 | 1779 |
tw.addNewComponent(this, label, KSD_TYPE_LABEL, |
1780 |
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1781 |
ToolWindow.BOTTOM_PADDING); |
2 | 1782 |
tf = new TextField(tool.getKeyStoreType(), 30); |
1783 |
tf.getAccessibleContext().setAccessibleName( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1784 |
PolicyTool.rb.getString("KeyStore.Type.")); |
2 | 1785 |
tw.addNewComponent(this, tf, KSD_TYPE_TEXTFIELD, |
1786 |
1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1787 |
ToolWindow.BOTTOM_PADDING); |
2 | 1788 |
|
1789 |
// KeyStore provider and textfield |
|
1790 |
label = new Label(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1791 |
("KeyStore.Provider.")); |
2 | 1792 |
tw.addNewComponent(this, label, KSD_PROVIDER_LABEL, |
1793 |
0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1794 |
ToolWindow.BOTTOM_PADDING); |
2 | 1795 |
tf = new TextField(tool.getKeyStoreProvider(), 30); |
1796 |
tf.getAccessibleContext().setAccessibleName( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1797 |
PolicyTool.rb.getString("KeyStore.Provider.")); |
2 | 1798 |
tw.addNewComponent(this, tf, KSD_PROVIDER_TEXTFIELD, |
1799 |
1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1800 |
ToolWindow.BOTTOM_PADDING); |
2 | 1801 |
|
1802 |
// KeyStore password URL and textfield |
|
1803 |
label = new Label(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1804 |
("KeyStore.Password.URL.")); |
2 | 1805 |
tw.addNewComponent(this, label, KSD_PWD_URL_LABEL, |
1806 |
0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1807 |
ToolWindow.BOTTOM_PADDING); |
2 | 1808 |
tf = new TextField(tool.getKeyStorePwdURL(), 30); |
1809 |
tf.getAccessibleContext().setAccessibleName( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1810 |
PolicyTool.rb.getString("KeyStore.Password.U.R.L.")); |
2 | 1811 |
tw.addNewComponent(this, tf, KSD_PWD_URL_TEXTFIELD, |
1812 |
1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1813 |
ToolWindow.BOTTOM_PADDING); |
2 | 1814 |
|
1815 |
// OK button |
|
1816 |
Button okButton = new Button(PolicyTool.rb.getString("OK")); |
|
1817 |
okButton.addActionListener |
|
1818 |
(new ChangeKeyStoreOKButtonListener(tool, tw, this)); |
|
1819 |
tw.addNewComponent(this, okButton, KSD_OK_BUTTON, |
|
1820 |
0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); |
|
1821 |
||
1822 |
// cancel button |
|
1823 |
Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); |
|
1824 |
cancelButton.addActionListener(new CancelButtonListener(this)); |
|
1825 |
tw.addNewComponent(this, cancelButton, KSD_CANCEL_BUTTON, |
|
1826 |
1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL); |
|
1827 |
||
1828 |
} |
|
1829 |
setVisible(true); |
|
1830 |
} |
|
1831 |
||
1832 |
/** |
|
1833 |
* display a dialog box for the user to input Principal info |
|
1834 |
* |
|
1835 |
* if editPolicyEntry is false, then we are adding Principals to |
|
1836 |
* a new PolicyEntry, and we only update the GUI listing |
|
1837 |
* with the new Principal. |
|
1838 |
* |
|
1839 |
* if edit is true, then we are editing an existing Policy entry. |
|
1840 |
*/ |
|
1841 |
void displayPrincipalDialog(boolean editPolicyEntry, boolean edit) { |
|
1842 |
||
1843 |
PolicyParser.PrincipalEntry editMe = null; |
|
1844 |
||
1845 |
// get the Principal selected from the Principal List |
|
1846 |
TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST); |
|
1847 |
int prinIndex = prinList.getSelectedIndex(); |
|
1848 |
||
1849 |
if (edit) { |
|
1850 |
editMe = (PolicyParser.PrincipalEntry)prinList.getObject(prinIndex); |
|
1851 |
} |
|
1852 |
||
1853 |
ToolDialog newTD = new ToolDialog |
|
1854 |
(PolicyTool.rb.getString("Principals"), tool, tw, true); |
|
1855 |
newTD.addWindowListener(new ChildWindowListener(newTD)); |
|
1856 |
||
1857 |
// find where the PolicyTool gui is |
|
1858 |
Point location = getLocationOnScreen(); |
|
1859 |
newTD.setBounds(location.x + 50, location.y + 100, 650, 190); |
|
1860 |
newTD.setLayout(new GridBagLayout()); |
|
1861 |
newTD.setResizable(true); |
|
1862 |
||
1863 |
// description label |
|
1864 |
Label label = (edit ? |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1865 |
new Label(PolicyTool.rb.getString(".Edit.Principal.")) : |
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1866 |
new Label(PolicyTool.rb.getString(".Add.New.Principal."))); |
2 | 1867 |
tw.addNewComponent(newTD, label, PRD_DESC_LABEL, |
1868 |
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1869 |
ToolWindow.TOP_BOTTOM_PADDING); |
2 | 1870 |
|
1871 |
// principal choice |
|
1872 |
Choice choice = new Choice(); |
|
1873 |
choice.add(PRIN_TYPE); |
|
1874 |
choice.getAccessibleContext().setAccessibleName(PRIN_TYPE); |
|
1875 |
for (int i = 0; i < PRIN_ARRAY.size(); i++) { |
|
1876 |
Prin next = PRIN_ARRAY.get(i); |
|
1877 |
choice.add(next.CLASS); |
|
1878 |
} |
|
1879 |
||
1880 |
choice.addItemListener(new PrincipalTypeMenuListener(newTD)); |
|
1881 |
if (edit) { |
|
1882 |
if (PolicyParser.PrincipalEntry.WILDCARD_CLASS.equals |
|
1883 |
(editMe.getPrincipalClass())) { |
|
1884 |
choice.select(PRIN_TYPE); |
|
1885 |
} else { |
|
1886 |
Prin inputPrin = getPrin(editMe.getPrincipalClass(), true); |
|
1887 |
if (inputPrin != null) { |
|
1888 |
choice.select(inputPrin.CLASS); |
|
1889 |
} |
|
1890 |
} |
|
1891 |
} |
|
1892 |
||
1893 |
tw.addNewComponent(newTD, choice, PRD_PRIN_CHOICE, |
|
1894 |
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1895 |
ToolWindow.LR_PADDING); |
2 | 1896 |
|
1897 |
// principal textfield |
|
1898 |
TextField tf; |
|
1899 |
tf = (edit ? |
|
1900 |
new TextField(editMe.getDisplayClass(), 30) : |
|
1901 |
new TextField(30)); |
|
1902 |
tf.getAccessibleContext().setAccessibleName(PRIN_TYPE); |
|
1903 |
tw.addNewComponent(newTD, tf, PRD_PRIN_TEXTFIELD, |
|
1904 |
1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1905 |
ToolWindow.LR_PADDING); |
2 | 1906 |
|
1907 |
// name label and textfield |
|
1908 |
label = new Label(PRIN_NAME); |
|
1909 |
tf = (edit ? |
|
1910 |
new TextField(editMe.getDisplayName(), 40) : |
|
1911 |
new TextField(40)); |
|
1912 |
tf.getAccessibleContext().setAccessibleName(PRIN_NAME); |
|
1913 |
||
1914 |
tw.addNewComponent(newTD, label, PRD_NAME_LABEL, |
|
1915 |
0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1916 |
ToolWindow.LR_PADDING); |
2 | 1917 |
tw.addNewComponent(newTD, tf, PRD_NAME_TEXTFIELD, |
1918 |
1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1919 |
ToolWindow.LR_PADDING); |
2 | 1920 |
|
1921 |
// OK button |
|
1922 |
Button okButton = new Button(PolicyTool.rb.getString("OK")); |
|
1923 |
okButton.addActionListener( |
|
1924 |
new NewPolicyPrinOKButtonListener |
|
1925 |
(tool, tw, this, newTD, edit)); |
|
1926 |
tw.addNewComponent(newTD, okButton, PRD_OK_BUTTON, |
|
1927 |
0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1928 |
ToolWindow.TOP_BOTTOM_PADDING); |
2 | 1929 |
// cancel button |
1930 |
Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); |
|
1931 |
cancelButton.addActionListener(new CancelButtonListener(newTD)); |
|
1932 |
tw.addNewComponent(newTD, cancelButton, PRD_CANCEL_BUTTON, |
|
1933 |
1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1934 |
ToolWindow.TOP_BOTTOM_PADDING); |
2 | 1935 |
|
1936 |
newTD.setVisible(true); |
|
1937 |
} |
|
1938 |
||
1939 |
/** |
|
1940 |
* display a dialog box for the user to input Permission info |
|
1941 |
* |
|
1942 |
* if editPolicyEntry is false, then we are adding Permissions to |
|
1943 |
* a new PolicyEntry, and we only update the GUI listing |
|
1944 |
* with the new Permission. |
|
1945 |
* |
|
1946 |
* if edit is true, then we are editing an existing Permission entry. |
|
1947 |
*/ |
|
1948 |
void displayPermissionDialog(boolean editPolicyEntry, boolean edit) { |
|
1949 |
||
1950 |
PolicyParser.PermissionEntry editMe = null; |
|
1951 |
||
1952 |
// get the Permission selected from the Permission List |
|
1953 |
TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST); |
|
1954 |
int permIndex = permList.getSelectedIndex(); |
|
1955 |
||
1956 |
if (edit) { |
|
1957 |
editMe = (PolicyParser.PermissionEntry)permList.getObject(permIndex); |
|
1958 |
} |
|
1959 |
||
1960 |
ToolDialog newTD = new ToolDialog |
|
1961 |
(PolicyTool.rb.getString("Permissions"), tool, tw, true); |
|
1962 |
newTD.addWindowListener(new ChildWindowListener(newTD)); |
|
1963 |
||
1964 |
// find where the PolicyTool gui is |
|
1965 |
Point location = getLocationOnScreen(); |
|
1966 |
newTD.setBounds(location.x + 50, location.y + 100, 700, 250); |
|
1967 |
newTD.setLayout(new GridBagLayout()); |
|
1968 |
newTD.setResizable(true); |
|
1969 |
||
1970 |
// description label |
|
1971 |
Label label = (edit ? |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1972 |
new Label(PolicyTool.rb.getString(".Edit.Permission.")) : |
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
1973 |
new Label(PolicyTool.rb.getString(".Add.New.Permission."))); |
2 | 1974 |
tw.addNewComponent(newTD, label, PD_DESC_LABEL, |
1975 |
0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1976 |
ToolWindow.TOP_BOTTOM_PADDING); |
2 | 1977 |
|
1978 |
// permission choice (added in alphabetical order) |
|
1979 |
Choice choice = new Choice(); |
|
1980 |
choice.add(PERM); |
|
1981 |
choice.getAccessibleContext().setAccessibleName(PERM); |
|
1982 |
for (int i = 0; i < PERM_ARRAY.size(); i++) { |
|
1983 |
Perm next = PERM_ARRAY.get(i); |
|
1984 |
choice.add(next.CLASS); |
|
1985 |
} |
|
1986 |
choice.addItemListener(new PermissionMenuListener(newTD)); |
|
1987 |
tw.addNewComponent(newTD, choice, PD_PERM_CHOICE, |
|
1988 |
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
1989 |
ToolWindow.LR_PADDING); |
2 | 1990 |
|
1991 |
// permission textfield |
|
1992 |
TextField tf; |
|
1993 |
tf = (edit ? new TextField(editMe.permission, 30) : new TextField(30)); |
|
1994 |
tf.getAccessibleContext().setAccessibleName(PERM); |
|
1995 |
if (edit) { |
|
1996 |
Perm inputPerm = getPerm(editMe.permission, true); |
|
1997 |
if (inputPerm != null) { |
|
1998 |
choice.select(inputPerm.CLASS); |
|
1999 |
} |
|
2000 |
} |
|
2001 |
tw.addNewComponent(newTD, tf, PD_PERM_TEXTFIELD, |
|
2002 |
1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2003 |
ToolWindow.LR_PADDING); |
2 | 2004 |
|
2005 |
// name label and textfield |
|
2006 |
choice = new Choice(); |
|
2007 |
choice.add(PERM_NAME); |
|
2008 |
choice.getAccessibleContext().setAccessibleName(PERM_NAME); |
|
2009 |
choice.addItemListener(new PermissionNameMenuListener(newTD)); |
|
2010 |
tf = (edit ? new TextField(editMe.name, 40) : new TextField(40)); |
|
2011 |
tf.getAccessibleContext().setAccessibleName(PERM_NAME); |
|
2012 |
if (edit) { |
|
2013 |
setPermissionNames(getPerm(editMe.permission, true), choice, tf); |
|
2014 |
} |
|
2015 |
tw.addNewComponent(newTD, choice, PD_NAME_CHOICE, |
|
2016 |
0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2017 |
ToolWindow.LR_PADDING); |
2 | 2018 |
tw.addNewComponent(newTD, tf, PD_NAME_TEXTFIELD, |
2019 |
1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2020 |
ToolWindow.LR_PADDING); |
2 | 2021 |
|
2022 |
// actions label and textfield |
|
2023 |
choice = new Choice(); |
|
2024 |
choice.add(PERM_ACTIONS); |
|
2025 |
choice.getAccessibleContext().setAccessibleName(PERM_ACTIONS); |
|
2026 |
choice.addItemListener(new PermissionActionsMenuListener(newTD)); |
|
2027 |
tf = (edit ? new TextField(editMe.action, 40) : new TextField(40)); |
|
2028 |
tf.getAccessibleContext().setAccessibleName(PERM_ACTIONS); |
|
2029 |
if (edit) { |
|
2030 |
setPermissionActions(getPerm(editMe.permission, true), choice, tf); |
|
2031 |
} |
|
2032 |
tw.addNewComponent(newTD, choice, PD_ACTIONS_CHOICE, |
|
2033 |
0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2034 |
ToolWindow.LR_PADDING); |
2 | 2035 |
tw.addNewComponent(newTD, tf, PD_ACTIONS_TEXTFIELD, |
2036 |
1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2037 |
ToolWindow.LR_PADDING); |
2 | 2038 |
|
2039 |
// signedby label and textfield |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2040 |
label = new Label(PolicyTool.rb.getString("Signed.By.")); |
2 | 2041 |
tw.addNewComponent(newTD, label, PD_SIGNEDBY_LABEL, |
2042 |
0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2043 |
ToolWindow.LR_PADDING); |
2 | 2044 |
tf = (edit ? new TextField(editMe.signedBy, 40) : new TextField(40)); |
2045 |
tf.getAccessibleContext().setAccessibleName( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2046 |
PolicyTool.rb.getString("Signed.By.")); |
2 | 2047 |
tw.addNewComponent(newTD, tf, PD_SIGNEDBY_TEXTFIELD, |
2048 |
1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2049 |
ToolWindow.LR_PADDING); |
2 | 2050 |
|
2051 |
// OK button |
|
2052 |
Button okButton = new Button(PolicyTool.rb.getString("OK")); |
|
2053 |
okButton.addActionListener( |
|
2054 |
new NewPolicyPermOKButtonListener |
|
2055 |
(tool, tw, this, newTD, edit)); |
|
2056 |
tw.addNewComponent(newTD, okButton, PD_OK_BUTTON, |
|
2057 |
0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2058 |
ToolWindow.TOP_BOTTOM_PADDING); |
2 | 2059 |
|
2060 |
// cancel button |
|
2061 |
Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); |
|
2062 |
cancelButton.addActionListener(new CancelButtonListener(newTD)); |
|
2063 |
tw.addNewComponent(newTD, cancelButton, PD_CANCEL_BUTTON, |
|
2064 |
1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2065 |
ToolWindow.TOP_BOTTOM_PADDING); |
2 | 2066 |
|
2067 |
newTD.setVisible(true); |
|
2068 |
} |
|
2069 |
||
2070 |
/** |
|
2071 |
* construct a Principal object from the Principal Info Dialog Box |
|
2072 |
*/ |
|
2073 |
PolicyParser.PrincipalEntry getPrinFromDialog() throws Exception { |
|
2074 |
||
2075 |
TextField tf = (TextField)getComponent(PRD_PRIN_TEXTFIELD); |
|
2076 |
String pclass = new String(tf.getText().trim()); |
|
2077 |
tf = (TextField)getComponent(PRD_NAME_TEXTFIELD); |
|
2078 |
String pname = new String(tf.getText().trim()); |
|
2079 |
if (pclass.equals("*")) { |
|
2080 |
pclass = PolicyParser.PrincipalEntry.WILDCARD_CLASS; |
|
2081 |
} |
|
2082 |
if (pname.equals("*")) { |
|
2083 |
pname = PolicyParser.PrincipalEntry.WILDCARD_NAME; |
|
2084 |
} |
|
2085 |
||
2086 |
PolicyParser.PrincipalEntry pppe = null; |
|
2087 |
||
2088 |
if ((pclass.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS)) && |
|
2089 |
(!pname.equals(PolicyParser.PrincipalEntry.WILDCARD_NAME))) { |
|
2090 |
throw new Exception |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2091 |
(PolicyTool.rb.getString("Cannot.Specify.Principal.with.a.Wildcard.Class.without.a.Wildcard.Name")); |
2 | 2092 |
} else if (pname.equals("")) { |
2093 |
throw new Exception |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2094 |
(PolicyTool.rb.getString("Cannot.Specify.Principal.without.a.Name")); |
2 | 2095 |
} else if (pclass.equals("")) { |
2096 |
// make this consistent with what PolicyParser does |
|
2097 |
// when it sees an empty principal class |
|
15013
4a17ca431caf
7019834: Eliminate dependency from PolicyFile to com.sun.security.auth.PrincipalComparator
mullan
parents:
14182
diff
changeset
|
2098 |
pclass = PolicyParser.PrincipalEntry.REPLACE_NAME; |
2 | 2099 |
tool.warnings.addElement( |
2100 |
"Warning: Principal name '" + pname + |
|
2101 |
"' specified without a Principal class.\n" + |
|
2102 |
"\t'" + pname + "' will be interpreted " + |
|
2103 |
"as a key store alias.\n" + |
|
2104 |
"\tThe final principal class will be " + |
|
2105 |
ToolDialog.X500_PRIN_CLASS + ".\n" + |
|
2106 |
"\tThe final principal name will be " + |
|
2107 |
"determined by the following:\n" + |
|
2108 |
"\n" + |
|
2109 |
"\tIf the key store entry identified by '" |
|
2110 |
+ pname + "'\n" + |
|
2111 |
"\tis a key entry, then the principal name will be\n" + |
|
2112 |
"\tthe subject distinguished name from the first\n" + |
|
2113 |
"\tcertificate in the entry's certificate chain.\n" + |
|
2114 |
"\n" + |
|
2115 |
"\tIf the key store entry identified by '" + |
|
2116 |
pname + "'\n" + |
|
2117 |
"\tis a trusted certificate entry, then the\n" + |
|
2118 |
"\tprincipal name will be the subject distinguished\n" + |
|
2119 |
"\tname from the trusted public key certificate."); |
|
2120 |
tw.displayStatusDialog(this, |
|
2121 |
"'" + pname + "' will be interpreted as a key " + |
|
2122 |
"store alias. View Warning Log for details."); |
|
2123 |
} |
|
2124 |
return new PolicyParser.PrincipalEntry(pclass, pname); |
|
2125 |
} |
|
2126 |
||
2127 |
||
2128 |
/** |
|
2129 |
* construct a Permission object from the Permission Info Dialog Box |
|
2130 |
*/ |
|
2131 |
PolicyParser.PermissionEntry getPermFromDialog() { |
|
2132 |
||
2133 |
TextField tf = (TextField)getComponent(PD_PERM_TEXTFIELD); |
|
2134 |
String permission = new String(tf.getText().trim()); |
|
2135 |
tf = (TextField)getComponent(PD_NAME_TEXTFIELD); |
|
2136 |
String name = null; |
|
2137 |
if (tf.getText().trim().equals("") == false) |
|
2138 |
name = new String(tf.getText().trim()); |
|
2139 |
if (permission.equals("") || |
|
2140 |
(!permission.equals(ALL_PERM_CLASS) && name == null)) { |
|
2141 |
throw new InvalidParameterException(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2142 |
("Permission.and.Target.Name.must.have.a.value")); |
2 | 2143 |
} |
2144 |
||
2145 |
// When the permission is FilePermission, we need to check the name |
|
2146 |
// to make sure it's not escaped. We believe -- |
|
2147 |
// |
|
2148 |
// String name.lastIndexOf("\\\\") |
|
2149 |
// ---------------- ------------------------ |
|
2150 |
// c:\foo\bar -1, legal |
|
2151 |
// c:\\foo\\bar 2, illegal |
|
2152 |
// \\server\share 0, legal |
|
2153 |
// \\\\server\share 2, illegal |
|
2154 |
||
2155 |
if (permission.equals(FILE_PERM_CLASS) && name.lastIndexOf("\\\\") > 0) { |
|
2156 |
char result = tw.displayYesNoDialog(this, |
|
2157 |
PolicyTool.rb.getString("Warning"), |
|
2158 |
PolicyTool.rb.getString( |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2159 |
"Warning.File.name.may.include.escaped.backslash.characters.It.is.not.necessary.to.escape.backslash.characters.the.tool.escapes"), |
2 | 2160 |
PolicyTool.rb.getString("Retain"), |
2161 |
PolicyTool.rb.getString("Edit") |
|
2162 |
); |
|
2163 |
if (result != 'Y') { |
|
2164 |
// an invisible exception |
|
2165 |
throw new NoDisplayException(); |
|
2166 |
} |
|
2167 |
} |
|
2168 |
// get the Actions |
|
2169 |
tf = (TextField)getComponent(PD_ACTIONS_TEXTFIELD); |
|
2170 |
String actions = null; |
|
2171 |
if (tf.getText().trim().equals("") == false) |
|
2172 |
actions = new String(tf.getText().trim()); |
|
2173 |
||
2174 |
// get the Signed By |
|
2175 |
tf = (TextField)getComponent(PD_SIGNEDBY_TEXTFIELD); |
|
2176 |
String signedBy = null; |
|
2177 |
if (tf.getText().trim().equals("") == false) |
|
2178 |
signedBy = new String(tf.getText().trim()); |
|
2179 |
||
2180 |
PolicyParser.PermissionEntry pppe = new PolicyParser.PermissionEntry |
|
2181 |
(permission, name, actions); |
|
2182 |
pppe.signedBy = signedBy; |
|
2183 |
||
2184 |
// see if the signers have public keys |
|
2185 |
if (signedBy != null) { |
|
2186 |
String signers[] = tool.parseSigners(pppe.signedBy); |
|
2187 |
for (int i = 0; i < signers.length; i++) { |
|
2188 |
try { |
|
2189 |
PublicKey pubKey = tool.getPublicKeyAlias(signers[i]); |
|
2190 |
if (pubKey == null) { |
|
2191 |
MessageFormat form = new MessageFormat |
|
2192 |
(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2193 |
("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured.")); |
2 | 2194 |
Object[] source = {signers[i]}; |
2195 |
tool.warnings.addElement(form.format(source)); |
|
2196 |
tw.displayStatusDialog(this, form.format(source)); |
|
2197 |
} |
|
2198 |
} catch (Exception e) { |
|
2199 |
tw.displayErrorDialog(this, e); |
|
2200 |
} |
|
2201 |
} |
|
2202 |
} |
|
2203 |
return pppe; |
|
2204 |
} |
|
2205 |
||
2206 |
/** |
|
2207 |
* confirm that the user REALLY wants to remove the Policy Entry |
|
2208 |
*/ |
|
2209 |
void displayConfirmRemovePolicyEntry() { |
|
2210 |
||
2211 |
// find the entry to be removed |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2212 |
List list = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST); |
2 | 2213 |
int index = list.getSelectedIndex(); |
2214 |
PolicyEntry entries[] = tool.getEntry(); |
|
2215 |
||
2216 |
// find where the PolicyTool gui is |
|
2217 |
Point location = tw.getLocationOnScreen(); |
|
2218 |
setBounds(location.x + 25, location.y + 100, 600, 400); |
|
2219 |
setLayout(new GridBagLayout()); |
|
2220 |
||
2221 |
// ask the user do they really want to do this? |
|
2222 |
Label label = new Label |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2223 |
(PolicyTool.rb.getString("Remove.this.Policy.Entry.")); |
2 | 2224 |
tw.addNewComponent(this, label, CRPE_LABEL1, |
2225 |
0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2226 |
ToolWindow.BOTTOM_PADDING); |
2 | 2227 |
|
2228 |
// display the policy entry |
|
2229 |
label = new Label(entries[index].codebaseToString()); |
|
2230 |
tw.addNewComponent(this, label, CRPE_LABEL2, |
|
2231 |
0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH); |
|
2232 |
label = new Label(entries[index].principalsToString().trim()); |
|
2233 |
tw.addNewComponent(this, label, CRPE_LABEL2+1, |
|
2234 |
0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH); |
|
2235 |
Vector<PolicyParser.PermissionEntry> perms = |
|
2236 |
entries[index].getGrantEntry().permissionEntries; |
|
2237 |
for (int i = 0; i < perms.size(); i++) { |
|
2238 |
PolicyParser.PermissionEntry nextPerm = perms.elementAt(i); |
|
2239 |
String permString = ToolDialog.PermissionEntryToUserFriendlyString(nextPerm); |
|
2240 |
label = new Label(" " + permString); |
|
2241 |
if (i == (perms.size()-1)) { |
|
2242 |
tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i, |
|
2243 |
1, 3 + i, 1, 1, 0.0, 0.0, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2244 |
GridBagConstraints.BOTH, |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2245 |
ToolWindow.BOTTOM_PADDING); |
2 | 2246 |
} else { |
2247 |
tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i, |
|
2248 |
1, 3 + i, 1, 1, 0.0, 0.0, |
|
2249 |
GridBagConstraints.BOTH); |
|
2250 |
} |
|
2251 |
} |
|
2252 |
||
2253 |
||
2254 |
// add OK/CANCEL buttons in a new panel |
|
2255 |
Panel panel = new Panel(); |
|
2256 |
panel.setLayout(new GridBagLayout()); |
|
2257 |
||
2258 |
// OK button |
|
2259 |
Button okButton = new Button(PolicyTool.rb.getString("OK")); |
|
2260 |
okButton.addActionListener |
|
2261 |
(new ConfirmRemovePolicyEntryOKButtonListener(tool, tw, this)); |
|
2262 |
tw.addNewComponent(panel, okButton, CRPE_PANEL_OK, |
|
2263 |
0, 0, 1, 1, 0.0, 0.0, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2264 |
GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING); |
2 | 2265 |
|
2266 |
// cancel button |
|
2267 |
Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); |
|
2268 |
cancelButton.addActionListener(new CancelButtonListener(this)); |
|
2269 |
tw.addNewComponent(panel, cancelButton, CRPE_PANEL_CANCEL, |
|
2270 |
1, 0, 1, 1, 0.0, 0.0, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2271 |
GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING); |
2 | 2272 |
|
2273 |
tw.addNewComponent(this, panel, CRPE_LABEL2 + 2 + perms.size(), |
|
2274 |
0, 3 + perms.size(), 2, 1, 0.0, 0.0, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2275 |
GridBagConstraints.VERTICAL, ToolWindow.TOP_BOTTOM_PADDING); |
2 | 2276 |
|
2277 |
pack(); |
|
2278 |
setVisible(true); |
|
2279 |
} |
|
2280 |
||
2281 |
/** |
|
2282 |
* perform SAVE AS |
|
2283 |
*/ |
|
2284 |
void displaySaveAsDialog(int nextEvent) { |
|
2285 |
||
2286 |
// pop up a dialog box for the user to enter a filename. |
|
2287 |
FileDialog fd = new FileDialog |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2288 |
(tw, PolicyTool.rb.getString("Save.As"), FileDialog.SAVE); |
2 | 2289 |
fd.addWindowListener(new WindowAdapter() { |
2290 |
public void windowClosing(WindowEvent e) { |
|
2291 |
e.getWindow().setVisible(false); |
|
2292 |
} |
|
2293 |
}); |
|
2294 |
fd.setVisible(true); |
|
2295 |
||
2296 |
// see if the user hit cancel |
|
2297 |
if (fd.getFile() == null || |
|
2298 |
fd.getFile().equals("")) |
|
2299 |
return; |
|
2300 |
||
2301 |
// get the entered filename |
|
7532 | 2302 |
File saveAsFile = new File(fd.getDirectory(), fd.getFile()); |
2303 |
String filename = saveAsFile.getPath(); |
|
2 | 2304 |
fd.dispose(); |
2305 |
||
7532 | 2306 |
try { |
2307 |
// save the policy entries to a file |
|
2308 |
tool.savePolicy(filename); |
|
2309 |
||
2310 |
// display status |
|
2311 |
MessageFormat form = new MessageFormat(PolicyTool.rb.getString |
|
2312 |
("Policy.successfully.written.to.filename")); |
|
2313 |
Object[] source = {filename}; |
|
2314 |
tw.displayStatusDialog(null, form.format(source)); |
|
2315 |
||
2316 |
// display the new policy filename |
|
2317 |
TextField newFilename = (TextField)tw.getComponent |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2318 |
(ToolWindow.MW_FILENAME_TEXTFIELD); |
7532 | 2319 |
newFilename.setText(filename); |
2320 |
tw.setVisible(true); |
|
2321 |
||
2322 |
// now continue with the originally requested command |
|
2323 |
// (QUIT, NEW, or OPEN) |
|
2324 |
userSaveContinue(tool, tw, this, nextEvent); |
|
2325 |
||
2326 |
} catch (FileNotFoundException fnfe) { |
|
2327 |
if (filename == null || filename.equals("")) { |
|
2328 |
tw.displayErrorDialog(null, new FileNotFoundException |
|
2329 |
(PolicyTool.rb.getString("null.filename"))); |
|
2330 |
} else { |
|
2331 |
tw.displayErrorDialog(null, fnfe); |
|
2 | 2332 |
} |
7532 | 2333 |
} catch (Exception ee) { |
2334 |
tw.displayErrorDialog(null, ee); |
|
2 | 2335 |
} |
2336 |
} |
|
2337 |
||
2338 |
/** |
|
2339 |
* ask user if they want to save changes |
|
2340 |
*/ |
|
2341 |
void displayUserSave(int select) { |
|
2342 |
||
2343 |
if (tool.modified == true) { |
|
2344 |
||
2345 |
// find where the PolicyTool gui is |
|
2346 |
Point location = tw.getLocationOnScreen(); |
|
2347 |
setBounds(location.x + 75, location.y + 100, 400, 150); |
|
2348 |
setLayout(new GridBagLayout()); |
|
2349 |
||
2350 |
Label label = new Label |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2351 |
(PolicyTool.rb.getString("Save.changes.")); |
2 | 2352 |
tw.addNewComponent(this, label, USC_LABEL, |
2353 |
0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2354 |
ToolWindow.L_TOP_BOTTOM_PADDING); |
2 | 2355 |
|
2356 |
Panel panel = new Panel(); |
|
2357 |
panel.setLayout(new GridBagLayout()); |
|
2358 |
||
2359 |
Button yesButton = new Button(PolicyTool.rb.getString("Yes")); |
|
2360 |
yesButton.addActionListener |
|
2361 |
(new UserSaveYesButtonListener(this, tool, tw, select)); |
|
2362 |
tw.addNewComponent(panel, yesButton, USC_YES_BUTTON, |
|
2363 |
0, 0, 1, 1, 0.0, 0.0, |
|
2364 |
GridBagConstraints.VERTICAL, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2365 |
ToolWindow.LR_BOTTOM_PADDING); |
2 | 2366 |
Button noButton = new Button(PolicyTool.rb.getString("No")); |
2367 |
noButton.addActionListener |
|
2368 |
(new UserSaveNoButtonListener(this, tool, tw, select)); |
|
2369 |
tw.addNewComponent(panel, noButton, USC_NO_BUTTON, |
|
2370 |
1, 0, 1, 1, 0.0, 0.0, |
|
2371 |
GridBagConstraints.VERTICAL, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2372 |
ToolWindow.LR_BOTTOM_PADDING); |
2 | 2373 |
Button cancelButton = new Button(PolicyTool.rb.getString("Cancel")); |
2374 |
cancelButton.addActionListener |
|
2375 |
(new UserSaveCancelButtonListener(this)); |
|
2376 |
tw.addNewComponent(panel, cancelButton, USC_CANCEL_BUTTON, |
|
2377 |
2, 0, 1, 1, 0.0, 0.0, |
|
2378 |
GridBagConstraints.VERTICAL, |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2379 |
ToolWindow.LR_BOTTOM_PADDING); |
2 | 2380 |
|
2381 |
tw.addNewComponent(this, panel, USC_PANEL, |
|
2382 |
0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH); |
|
2383 |
||
2384 |
pack(); |
|
2385 |
setVisible(true); |
|
2386 |
} else { |
|
2387 |
// just do the original request (QUIT, NEW, or OPEN) |
|
2388 |
userSaveContinue(tool, tw, this, select); |
|
2389 |
} |
|
2390 |
} |
|
2391 |
||
2392 |
/** |
|
2393 |
* when the user sees the 'YES', 'NO', 'CANCEL' buttons on the |
|
2394 |
* displayUserSave dialog, and the click on one of them, |
|
2395 |
* we need to continue the originally requested action |
|
2396 |
* (either QUITting, opening NEW policy file, or OPENing an existing |
|
2397 |
* policy file. do that now. |
|
2398 |
*/ |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2399 |
@SuppressWarnings("fallthrough") |
2 | 2400 |
void userSaveContinue(PolicyTool tool, ToolWindow tw, |
2401 |
ToolDialog us, int select) { |
|
2402 |
||
2403 |
// now either QUIT, open a NEW policy file, or OPEN an existing policy |
|
2404 |
switch(select) { |
|
2405 |
case ToolDialog.QUIT: |
|
2406 |
||
2407 |
tw.setVisible(false); |
|
2408 |
tw.dispose(); |
|
2409 |
System.exit(0); |
|
2410 |
||
2411 |
case ToolDialog.NEW: |
|
2412 |
||
2413 |
try { |
|
2414 |
tool.openPolicy(null); |
|
2415 |
} catch (Exception ee) { |
|
2416 |
tool.modified = false; |
|
2417 |
tw.displayErrorDialog(null, ee); |
|
2418 |
} |
|
2419 |
||
2420 |
// display the policy entries via the policy list textarea |
|
2421 |
List list = new List(40, false); |
|
2422 |
list.addActionListener(new PolicyListListener(tool, tw)); |
|
2423 |
tw.replacePolicyList(list); |
|
2424 |
||
2425 |
// display null policy filename and keystore |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2426 |
TextField newFilename = (TextField)tw.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2427 |
ToolWindow.MW_FILENAME_TEXTFIELD); |
2 | 2428 |
newFilename.setText(""); |
2429 |
tw.setVisible(true); |
|
2430 |
break; |
|
2431 |
||
2432 |
case ToolDialog.OPEN: |
|
2433 |
||
2434 |
// pop up a dialog box for the user to enter a filename. |
|
2435 |
FileDialog fd = new FileDialog |
|
2436 |
(tw, PolicyTool.rb.getString("Open"), FileDialog.LOAD); |
|
2437 |
fd.addWindowListener(new WindowAdapter() { |
|
2438 |
public void windowClosing(WindowEvent e) { |
|
2439 |
e.getWindow().setVisible(false); |
|
2440 |
} |
|
2441 |
}); |
|
2442 |
fd.setVisible(true); |
|
2443 |
||
2444 |
// see if the user hit 'cancel' |
|
2445 |
if (fd.getFile() == null || |
|
2446 |
fd.getFile().equals("")) |
|
2447 |
return; |
|
2448 |
||
2449 |
// get the entered filename |
|
7532 | 2450 |
String policyFile = new File(fd.getDirectory(), fd.getFile()).getPath(); |
2 | 2451 |
|
2452 |
try { |
|
2453 |
// open the policy file |
|
2454 |
tool.openPolicy(policyFile); |
|
2455 |
||
2456 |
// display the policy entries via the policy list textarea |
|
2457 |
list = new List(40, false); |
|
2458 |
list.addActionListener(new PolicyListListener(tool, tw)); |
|
2459 |
PolicyEntry entries[] = tool.getEntry(); |
|
2460 |
if (entries != null) { |
|
2461 |
for (int i = 0; i < entries.length; i++) |
|
2462 |
list.add(entries[i].headerToString()); |
|
2463 |
} |
|
2464 |
tw.replacePolicyList(list); |
|
2465 |
tool.modified = false; |
|
2466 |
||
2467 |
// display the new policy filename |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2468 |
newFilename = (TextField)tw.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2469 |
ToolWindow.MW_FILENAME_TEXTFIELD); |
2 | 2470 |
newFilename.setText(policyFile); |
2471 |
tw.setVisible(true); |
|
2472 |
||
2473 |
// inform user of warnings |
|
2474 |
if (tool.newWarning == true) { |
|
2475 |
tw.displayStatusDialog(null, PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2476 |
("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information.")); |
2 | 2477 |
} |
2478 |
||
2479 |
} catch (Exception e) { |
|
2480 |
// add blank policy listing |
|
2481 |
list = new List(40, false); |
|
2482 |
list.addActionListener(new PolicyListListener(tool, tw)); |
|
2483 |
tw.replacePolicyList(list); |
|
2484 |
tool.setPolicyFileName(null); |
|
2485 |
tool.modified = false; |
|
2486 |
||
2487 |
// display a null policy filename |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2488 |
newFilename = (TextField)tw.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2489 |
ToolWindow.MW_FILENAME_TEXTFIELD); |
2 | 2490 |
newFilename.setText(""); |
2491 |
tw.setVisible(true); |
|
2492 |
||
2493 |
// display the error |
|
2494 |
MessageFormat form = new MessageFormat(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2495 |
("Could.not.open.policy.file.policyFile.e.toString.")); |
2 | 2496 |
Object[] source = {policyFile, e.toString()}; |
2497 |
tw.displayErrorDialog(null, form.format(source)); |
|
2498 |
} |
|
2499 |
break; |
|
2500 |
} |
|
2501 |
} |
|
2502 |
||
2503 |
/** |
|
2504 |
* Return a Menu list of names for a given permission |
|
2505 |
* |
|
2506 |
* If inputPerm's TARGETS are null, then this means TARGETS are |
|
2507 |
* not allowed to be entered (and the TextField is set to be |
|
2508 |
* non-editable). |
|
2509 |
* |
|
2510 |
* If TARGETS are valid but there are no standard ones |
|
2511 |
* (user must enter them by hand) then the TARGETS array may be empty |
|
2512 |
* (and of course non-null). |
|
2513 |
*/ |
|
2514 |
void setPermissionNames(Perm inputPerm, Choice names, TextField field) { |
|
2515 |
names.removeAll(); |
|
2516 |
names.add(PERM_NAME); |
|
2517 |
||
2518 |
if (inputPerm == null) { |
|
2519 |
// custom permission |
|
2520 |
field.setEditable(true); |
|
2521 |
} else if (inputPerm.TARGETS == null) { |
|
2522 |
// standard permission with no targets |
|
2523 |
field.setEditable(false); |
|
2524 |
} else { |
|
2525 |
// standard permission with standard targets |
|
2526 |
field.setEditable(true); |
|
2527 |
for (int i = 0; i < inputPerm.TARGETS.length; i++) { |
|
2528 |
names.add(inputPerm.TARGETS[i]); |
|
2529 |
} |
|
2530 |
} |
|
2531 |
} |
|
2532 |
||
2533 |
/** |
|
2534 |
* Return a Menu list of actions for a given permission |
|
2535 |
* |
|
2536 |
* If inputPerm's ACTIONS are null, then this means ACTIONS are |
|
2537 |
* not allowed to be entered (and the TextField is set to be |
|
2538 |
* non-editable). This is typically true for BasicPermissions. |
|
2539 |
* |
|
2540 |
* If ACTIONS are valid but there are no standard ones |
|
2541 |
* (user must enter them by hand) then the ACTIONS array may be empty |
|
2542 |
* (and of course non-null). |
|
2543 |
*/ |
|
2544 |
void setPermissionActions(Perm inputPerm, Choice actions, TextField field) { |
|
2545 |
actions.removeAll(); |
|
2546 |
actions.add(PERM_ACTIONS); |
|
2547 |
||
2548 |
if (inputPerm == null) { |
|
2549 |
// custom permission |
|
2550 |
field.setEditable(true); |
|
2551 |
} else if (inputPerm.ACTIONS == null) { |
|
2552 |
// standard permission with no actions |
|
2553 |
field.setEditable(false); |
|
2554 |
} else { |
|
2555 |
// standard permission with standard actions |
|
2556 |
field.setEditable(true); |
|
2557 |
for (int i = 0; i < inputPerm.ACTIONS.length; i++) { |
|
2558 |
actions.add(inputPerm.ACTIONS[i]); |
|
2559 |
} |
|
2560 |
} |
|
2561 |
} |
|
2562 |
||
2563 |
static String PermissionEntryToUserFriendlyString(PolicyParser.PermissionEntry pppe) { |
|
2564 |
String result = pppe.permission; |
|
2565 |
if (pppe.name != null) { |
|
2566 |
result += " " + pppe.name; |
|
2567 |
} |
|
2568 |
if (pppe.action != null) { |
|
2569 |
result += ", \"" + pppe.action + "\""; |
|
2570 |
} |
|
2571 |
if (pppe.signedBy != null) { |
|
2572 |
result += ", signedBy " + pppe.signedBy; |
|
2573 |
} |
|
2574 |
return result; |
|
2575 |
} |
|
2576 |
||
2577 |
static String PrincipalEntryToUserFriendlyString(PolicyParser.PrincipalEntry pppe) { |
|
2578 |
StringWriter sw = new StringWriter(); |
|
2579 |
PrintWriter pw = new PrintWriter(sw); |
|
2580 |
pppe.write(pw); |
|
2581 |
return sw.toString(); |
|
2582 |
} |
|
2583 |
} |
|
2584 |
||
2585 |
/** |
|
2586 |
* Event handler for the PolicyTool window |
|
2587 |
*/ |
|
2588 |
class ToolWindowListener implements WindowListener { |
|
2589 |
||
2590 |
private ToolWindow tw; |
|
2591 |
||
2592 |
ToolWindowListener(ToolWindow tw) { |
|
2593 |
this.tw = tw; |
|
2594 |
} |
|
2595 |
||
2596 |
public void windowOpened(WindowEvent we) { |
|
2597 |
} |
|
2598 |
||
2599 |
public void windowClosing(WindowEvent we) { |
|
2600 |
||
2601 |
// XXX |
|
2602 |
// should we ask user if they want to save changes? |
|
2603 |
// (we do if they choose the Menu->Exit) |
|
2604 |
// seems that if they kill the application by hand, |
|
2605 |
// we don't have to ask. |
|
2606 |
||
2607 |
tw.setVisible(false); |
|
2608 |
tw.dispose(); |
|
2609 |
System.exit(0); |
|
2610 |
} |
|
2611 |
||
2612 |
public void windowClosed(WindowEvent we) { |
|
2613 |
System.exit(0); |
|
2614 |
} |
|
2615 |
||
2616 |
public void windowIconified(WindowEvent we) { |
|
2617 |
} |
|
2618 |
||
2619 |
public void windowDeiconified(WindowEvent we) { |
|
2620 |
} |
|
2621 |
||
2622 |
public void windowActivated(WindowEvent we) { |
|
2623 |
} |
|
2624 |
||
2625 |
public void windowDeactivated(WindowEvent we) { |
|
2626 |
} |
|
2627 |
} |
|
2628 |
||
2629 |
/** |
|
2630 |
* Event handler for the Policy List |
|
2631 |
*/ |
|
2632 |
class PolicyListListener implements ActionListener { |
|
2633 |
||
2634 |
private PolicyTool tool; |
|
2635 |
private ToolWindow tw; |
|
2636 |
||
2637 |
PolicyListListener(PolicyTool tool, ToolWindow tw) { |
|
2638 |
this.tool = tool; |
|
2639 |
this.tw = tw; |
|
2640 |
||
2641 |
} |
|
2642 |
||
2643 |
public void actionPerformed(ActionEvent e) { |
|
2644 |
||
2645 |
// display the permission list for a policy entry |
|
2646 |
ToolDialog td = new ToolDialog |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2647 |
(PolicyTool.rb.getString("Policy.Entry"), tool, tw, true); |
2 | 2648 |
td.displayPolicyEntryDialog(true); |
2649 |
} |
|
2650 |
} |
|
2651 |
||
2652 |
/** |
|
2653 |
* Event handler for the File Menu |
|
2654 |
*/ |
|
2655 |
class FileMenuListener implements ActionListener { |
|
2656 |
||
2657 |
private PolicyTool tool; |
|
2658 |
private ToolWindow tw; |
|
2659 |
||
2660 |
FileMenuListener(PolicyTool tool, ToolWindow tw) { |
|
2661 |
this.tool = tool; |
|
2662 |
this.tw = tw; |
|
2663 |
} |
|
2664 |
||
2665 |
public void actionPerformed(ActionEvent e) { |
|
2666 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2667 |
if (PolicyTool.collator.compare(e.getActionCommand(), |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2668 |
ToolWindow.QUIT) == 0) { |
2 | 2669 |
|
2670 |
// ask user if they want to save changes |
|
2671 |
ToolDialog td = new ToolDialog |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2672 |
(PolicyTool.rb.getString("Save.Changes"), tool, tw, true); |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2673 |
td.displayUserSave(ToolDialog.QUIT); |
2 | 2674 |
|
2675 |
// the above method will perform the QUIT as long as the |
|
2676 |
// user does not CANCEL the request |
|
2677 |
||
2678 |
} else if (PolicyTool.collator.compare(e.getActionCommand(), |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2679 |
ToolWindow.NEW_POLICY_FILE) == 0) { |
2 | 2680 |
|
2681 |
// ask user if they want to save changes |
|
2682 |
ToolDialog td = new ToolDialog |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2683 |
(PolicyTool.rb.getString("Save.Changes"), tool, tw, true); |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2684 |
td.displayUserSave(ToolDialog.NEW); |
2 | 2685 |
|
2686 |
// the above method will perform the NEW as long as the |
|
2687 |
// user does not CANCEL the request |
|
2688 |
||
2689 |
} else if (PolicyTool.collator.compare(e.getActionCommand(), |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2690 |
ToolWindow.OPEN_POLICY_FILE) == 0) { |
2 | 2691 |
|
2692 |
// ask user if they want to save changes |
|
2693 |
ToolDialog td = new ToolDialog |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2694 |
(PolicyTool.rb.getString("Save.Changes"), tool, tw, true); |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2695 |
td.displayUserSave(ToolDialog.OPEN); |
2 | 2696 |
|
2697 |
// the above method will perform the OPEN as long as the |
|
2698 |
// user does not CANCEL the request |
|
2699 |
||
2700 |
} else if (PolicyTool.collator.compare(e.getActionCommand(), |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2701 |
ToolWindow.SAVE_POLICY_FILE) == 0) { |
2 | 2702 |
|
2703 |
// get the previously entered filename |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2704 |
String filename = ((TextField)tw.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2705 |
ToolWindow.MW_FILENAME_TEXTFIELD)).getText(); |
2 | 2706 |
|
2707 |
// if there is no filename, do a SAVE_AS |
|
2708 |
if (filename == null || filename.length() == 0) { |
|
2709 |
// user wants to SAVE AS |
|
2710 |
ToolDialog td = new ToolDialog |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2711 |
(PolicyTool.rb.getString("Save.As"), tool, tw, true); |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2712 |
td.displaySaveAsDialog(ToolDialog.NOACTION); |
2 | 2713 |
} else { |
2714 |
try { |
|
2715 |
// save the policy entries to a file |
|
2716 |
tool.savePolicy(filename); |
|
2717 |
||
2718 |
// display status |
|
2719 |
MessageFormat form = new MessageFormat |
|
2720 |
(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2721 |
("Policy.successfully.written.to.filename")); |
2 | 2722 |
Object[] source = {filename}; |
2723 |
tw.displayStatusDialog(null, form.format(source)); |
|
2724 |
} catch (FileNotFoundException fnfe) { |
|
2725 |
if (filename == null || filename.equals("")) { |
|
2726 |
tw.displayErrorDialog(null, new FileNotFoundException |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2727 |
(PolicyTool.rb.getString("null.filename"))); |
2 | 2728 |
} else { |
2729 |
tw.displayErrorDialog(null, fnfe); |
|
2730 |
} |
|
2731 |
} catch (Exception ee) { |
|
2732 |
tw.displayErrorDialog(null, ee); |
|
2733 |
} |
|
2734 |
} |
|
2735 |
} else if (PolicyTool.collator.compare(e.getActionCommand(), |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2736 |
ToolWindow.SAVE_AS_POLICY_FILE) == 0) { |
2 | 2737 |
|
2738 |
// user wants to SAVE AS |
|
2739 |
ToolDialog td = new ToolDialog |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2740 |
(PolicyTool.rb.getString("Save.As"), tool, tw, true); |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2741 |
td.displaySaveAsDialog(ToolDialog.NOACTION); |
2 | 2742 |
|
2743 |
} else if (PolicyTool.collator.compare(e.getActionCommand(), |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2744 |
ToolWindow.VIEW_WARNINGS) == 0) { |
2 | 2745 |
tw.displayWarningLog(null); |
2746 |
} |
|
2747 |
} |
|
2748 |
} |
|
2749 |
||
2750 |
/** |
|
2751 |
* Event handler for the main window buttons and Edit Menu |
|
2752 |
*/ |
|
2753 |
class MainWindowListener implements ActionListener { |
|
2754 |
||
2755 |
private PolicyTool tool; |
|
2756 |
private ToolWindow tw; |
|
2757 |
||
2758 |
MainWindowListener(PolicyTool tool, ToolWindow tw) { |
|
2759 |
this.tool = tool; |
|
2760 |
this.tw = tw; |
|
2761 |
} |
|
2762 |
||
2763 |
public void actionPerformed(ActionEvent e) { |
|
2764 |
||
2765 |
if (PolicyTool.collator.compare(e.getActionCommand(), |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2766 |
ToolWindow.ADD_POLICY_ENTRY) == 0) { |
2 | 2767 |
|
2768 |
// display a dialog box for the user to enter policy info |
|
2769 |
ToolDialog td = new ToolDialog |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2770 |
(PolicyTool.rb.getString("Policy.Entry"), tool, tw, true); |
2 | 2771 |
td.displayPolicyEntryDialog(false); |
2772 |
||
2773 |
} else if (PolicyTool.collator.compare(e.getActionCommand(), |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2774 |
ToolWindow.REMOVE_POLICY_ENTRY) == 0) { |
2 | 2775 |
|
2776 |
// get the selected entry |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2777 |
List list = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST); |
2 | 2778 |
int index = list.getSelectedIndex(); |
2779 |
if (index < 0) { |
|
2780 |
tw.displayErrorDialog(null, new Exception |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2781 |
(PolicyTool.rb.getString("No.Policy.Entry.selected"))); |
2 | 2782 |
return; |
2783 |
} |
|
2784 |
||
2785 |
// ask the user if they really want to remove the policy entry |
|
2786 |
ToolDialog td = new ToolDialog(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2787 |
("Remove.Policy.Entry"), tool, tw, true); |
2 | 2788 |
td.displayConfirmRemovePolicyEntry(); |
2789 |
||
2790 |
} else if (PolicyTool.collator.compare(e.getActionCommand(), |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2791 |
ToolWindow.EDIT_POLICY_ENTRY) == 0) { |
2 | 2792 |
|
2793 |
// get the selected entry |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2794 |
List list = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST); |
2 | 2795 |
int index = list.getSelectedIndex(); |
2796 |
if (index < 0) { |
|
2797 |
tw.displayErrorDialog(null, new Exception |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2798 |
(PolicyTool.rb.getString("No.Policy.Entry.selected"))); |
2 | 2799 |
return; |
2800 |
} |
|
2801 |
||
2802 |
// display the permission list for a policy entry |
|
2803 |
ToolDialog td = new ToolDialog |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2804 |
(PolicyTool.rb.getString("Policy.Entry"), tool, tw, true); |
2 | 2805 |
td.displayPolicyEntryDialog(true); |
2806 |
||
2807 |
} else if (PolicyTool.collator.compare(e.getActionCommand(), |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2808 |
ToolWindow.EDIT_KEYSTORE) == 0) { |
2 | 2809 |
|
2810 |
// display a dialog box for the user to enter keystore info |
|
2811 |
ToolDialog td = new ToolDialog |
|
2812 |
(PolicyTool.rb.getString("KeyStore"), tool, tw, true); |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2813 |
td.keyStoreDialog(ToolDialog.EDIT_KEYSTORE); |
2 | 2814 |
} |
2815 |
} |
|
2816 |
} |
|
2817 |
||
2818 |
/** |
|
2819 |
* Event handler for AddEntryDoneButton button |
|
2820 |
* |
|
2821 |
* -- if edit is TRUE, then we are EDITing an existing PolicyEntry |
|
2822 |
* and we need to update both the policy and the GUI listing. |
|
2823 |
* if edit is FALSE, then we are ADDing a new PolicyEntry, |
|
2824 |
* so we only need to update the GUI listing. |
|
2825 |
*/ |
|
2826 |
class AddEntryDoneButtonListener implements ActionListener { |
|
2827 |
||
2828 |
private PolicyTool tool; |
|
2829 |
private ToolWindow tw; |
|
2830 |
private ToolDialog td; |
|
2831 |
private boolean edit; |
|
2832 |
||
2833 |
AddEntryDoneButtonListener(PolicyTool tool, ToolWindow tw, |
|
2834 |
ToolDialog td, boolean edit) { |
|
2835 |
this.tool = tool; |
|
2836 |
this.tw = tw; |
|
2837 |
this.td = td; |
|
2838 |
this.edit = edit; |
|
2839 |
} |
|
2840 |
||
2841 |
public void actionPerformed(ActionEvent e) { |
|
2842 |
||
2843 |
try { |
|
2844 |
// get a PolicyEntry object from the dialog policy info |
|
2845 |
PolicyEntry newEntry = td.getPolicyEntryFromDialog(); |
|
2846 |
PolicyParser.GrantEntry newGe = newEntry.getGrantEntry(); |
|
2847 |
||
2848 |
// see if all the signers have public keys |
|
2849 |
if (newGe.signedBy != null) { |
|
2850 |
String signers[] = tool.parseSigners(newGe.signedBy); |
|
2851 |
for (int i = 0; i < signers.length; i++) { |
|
2852 |
PublicKey pubKey = tool.getPublicKeyAlias(signers[i]); |
|
2853 |
if (pubKey == null) { |
|
2854 |
MessageFormat form = new MessageFormat |
|
2855 |
(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2856 |
("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured.")); |
2 | 2857 |
Object[] source = {signers[i]}; |
2858 |
tool.warnings.addElement(form.format(source)); |
|
2859 |
tw.displayStatusDialog(td, form.format(source)); |
|
2860 |
} |
|
2861 |
} |
|
2862 |
} |
|
2863 |
||
2864 |
// add the entry |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2865 |
List policyList = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST); |
2 | 2866 |
if (edit) { |
2867 |
int listIndex = policyList.getSelectedIndex(); |
|
2868 |
tool.addEntry(newEntry, listIndex); |
|
2869 |
String newCodeBaseStr = newEntry.headerToString(); |
|
2870 |
if (PolicyTool.collator.compare |
|
2871 |
(newCodeBaseStr, policyList.getItem(listIndex)) != 0) |
|
2872 |
tool.modified = true; |
|
2873 |
policyList.replaceItem(newCodeBaseStr, listIndex); |
|
2874 |
} else { |
|
2875 |
tool.addEntry(newEntry, -1); |
|
2876 |
policyList.add(newEntry.headerToString()); |
|
2877 |
tool.modified = true; |
|
2878 |
} |
|
2879 |
td.setVisible(false); |
|
2880 |
td.dispose(); |
|
2881 |
||
2882 |
} catch (Exception eee) { |
|
2883 |
tw.displayErrorDialog(td, eee); |
|
2884 |
} |
|
2885 |
} |
|
2886 |
} |
|
2887 |
||
2888 |
/** |
|
2889 |
* Event handler for ChangeKeyStoreOKButton button |
|
2890 |
*/ |
|
2891 |
class ChangeKeyStoreOKButtonListener implements ActionListener { |
|
2892 |
||
2893 |
private PolicyTool tool; |
|
2894 |
private ToolWindow tw; |
|
2895 |
private ToolDialog td; |
|
2896 |
||
2897 |
ChangeKeyStoreOKButtonListener(PolicyTool tool, ToolWindow tw, |
|
2898 |
ToolDialog td) { |
|
2899 |
this.tool = tool; |
|
2900 |
this.tw = tw; |
|
2901 |
this.td = td; |
|
2902 |
} |
|
2903 |
||
2904 |
public void actionPerformed(ActionEvent e) { |
|
2905 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2906 |
String URLString = ((TextField)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2907 |
ToolDialog.KSD_NAME_TEXTFIELD)).getText().trim(); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2908 |
String type = ((TextField)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2909 |
ToolDialog.KSD_TYPE_TEXTFIELD)).getText().trim(); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2910 |
String provider = ((TextField)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2911 |
ToolDialog.KSD_PROVIDER_TEXTFIELD)).getText().trim(); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2912 |
String pwdURL = ((TextField)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
2913 |
ToolDialog.KSD_PWD_URL_TEXTFIELD)).getText().trim(); |
2 | 2914 |
|
2915 |
try { |
|
2916 |
tool.openKeyStore |
|
2917 |
((URLString.length() == 0 ? null : URLString), |
|
2918 |
(type.length() == 0 ? null : type), |
|
2919 |
(provider.length() == 0 ? null : provider), |
|
2920 |
(pwdURL.length() == 0 ? null : pwdURL)); |
|
2921 |
tool.modified = true; |
|
2922 |
} catch (Exception ex) { |
|
2923 |
MessageFormat form = new MessageFormat(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
2924 |
("Unable.to.open.KeyStore.ex.toString.")); |
2 | 2925 |
Object[] source = {ex.toString()}; |
2926 |
tw.displayErrorDialog(td, form.format(source)); |
|
2927 |
return; |
|
2928 |
} |
|
2929 |
||
2930 |
td.dispose(); |
|
2931 |
} |
|
2932 |
} |
|
2933 |
||
2934 |
/** |
|
2935 |
* Event handler for AddPrinButton button |
|
2936 |
*/ |
|
2937 |
class AddPrinButtonListener implements ActionListener { |
|
2938 |
||
2939 |
private PolicyTool tool; |
|
2940 |
private ToolWindow tw; |
|
2941 |
private ToolDialog td; |
|
2942 |
private boolean editPolicyEntry; |
|
2943 |
||
2944 |
AddPrinButtonListener(PolicyTool tool, ToolWindow tw, |
|
2945 |
ToolDialog td, boolean editPolicyEntry) { |
|
2946 |
this.tool = tool; |
|
2947 |
this.tw = tw; |
|
2948 |
this.td = td; |
|
2949 |
this.editPolicyEntry = editPolicyEntry; |
|
2950 |
} |
|
2951 |
||
2952 |
public void actionPerformed(ActionEvent e) { |
|
2953 |
||
2954 |
// display a dialog box for the user to enter principal info |
|
2955 |
td.displayPrincipalDialog(editPolicyEntry, false); |
|
2956 |
} |
|
2957 |
} |
|
2958 |
||
2959 |
/** |
|
2960 |
* Event handler for AddPermButton button |
|
2961 |
*/ |
|
2962 |
class AddPermButtonListener implements ActionListener { |
|
2963 |
||
2964 |
private PolicyTool tool; |
|
2965 |
private ToolWindow tw; |
|
2966 |
private ToolDialog td; |
|
2967 |
private boolean editPolicyEntry; |
|
2968 |
||
2969 |
AddPermButtonListener(PolicyTool tool, ToolWindow tw, |
|
2970 |
ToolDialog td, boolean editPolicyEntry) { |
|
2971 |
this.tool = tool; |
|
2972 |
this.tw = tw; |
|
2973 |
this.td = td; |
|
2974 |
this.editPolicyEntry = editPolicyEntry; |
|
2975 |
} |
|
2976 |
||
2977 |
public void actionPerformed(ActionEvent e) { |
|
2978 |
||
2979 |
// display a dialog box for the user to enter permission info |
|
2980 |
td.displayPermissionDialog(editPolicyEntry, false); |
|
2981 |
} |
|
2982 |
} |
|
2983 |
||
2984 |
/** |
|
2985 |
* Event handler for AddPrinOKButton button |
|
2986 |
*/ |
|
2987 |
class NewPolicyPrinOKButtonListener implements ActionListener { |
|
2988 |
||
2989 |
private PolicyTool tool; |
|
2990 |
private ToolWindow tw; |
|
2991 |
private ToolDialog listDialog; |
|
2992 |
private ToolDialog infoDialog; |
|
2993 |
private boolean edit; |
|
2994 |
||
2995 |
NewPolicyPrinOKButtonListener(PolicyTool tool, |
|
2996 |
ToolWindow tw, |
|
2997 |
ToolDialog listDialog, |
|
2998 |
ToolDialog infoDialog, |
|
2999 |
boolean edit) { |
|
3000 |
this.tool = tool; |
|
3001 |
this.tw = tw; |
|
3002 |
this.listDialog = listDialog; |
|
3003 |
this.infoDialog = infoDialog; |
|
3004 |
this.edit = edit; |
|
3005 |
} |
|
3006 |
||
3007 |
public void actionPerformed(ActionEvent e) { |
|
3008 |
||
3009 |
try { |
|
3010 |
// read in the new principal info from Dialog Box |
|
3011 |
PolicyParser.PrincipalEntry pppe = |
|
3012 |
infoDialog.getPrinFromDialog(); |
|
3013 |
if (pppe != null) { |
|
3014 |
try { |
|
3015 |
tool.verifyPrincipal(pppe.getPrincipalClass(), |
|
3016 |
pppe.getPrincipalName()); |
|
3017 |
} catch (ClassNotFoundException cnfe) { |
|
3018 |
MessageFormat form = new MessageFormat |
|
3019 |
(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
3020 |
("Warning.Class.not.found.class")); |
2 | 3021 |
Object[] source = {pppe.getPrincipalClass()}; |
3022 |
tool.warnings.addElement(form.format(source)); |
|
3023 |
tw.displayStatusDialog(infoDialog, form.format(source)); |
|
3024 |
} |
|
3025 |
||
3026 |
// add the principal to the GUI principal list |
|
3027 |
TaggedList prinList = |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3028 |
(TaggedList)listDialog.getComponent(ToolDialog.PE_PRIN_LIST); |
2 | 3029 |
|
3030 |
String prinString = ToolDialog.PrincipalEntryToUserFriendlyString(pppe); |
|
3031 |
if (edit) { |
|
3032 |
// if editing, replace the original principal |
|
3033 |
int index = prinList.getSelectedIndex(); |
|
3034 |
prinList.replaceTaggedItem(prinString, pppe, index); |
|
3035 |
} else { |
|
3036 |
// if adding, just add it to the end |
|
3037 |
prinList.addTaggedItem(prinString, pppe); |
|
3038 |
} |
|
3039 |
} |
|
3040 |
infoDialog.dispose(); |
|
3041 |
} catch (Exception ee) { |
|
3042 |
tw.displayErrorDialog(infoDialog, ee); |
|
3043 |
} |
|
3044 |
} |
|
3045 |
} |
|
3046 |
||
3047 |
/** |
|
3048 |
* Event handler for AddPermOKButton button |
|
3049 |
*/ |
|
3050 |
class NewPolicyPermOKButtonListener implements ActionListener { |
|
3051 |
||
3052 |
private PolicyTool tool; |
|
3053 |
private ToolWindow tw; |
|
3054 |
private ToolDialog listDialog; |
|
3055 |
private ToolDialog infoDialog; |
|
3056 |
private boolean edit; |
|
3057 |
||
3058 |
NewPolicyPermOKButtonListener(PolicyTool tool, |
|
3059 |
ToolWindow tw, |
|
3060 |
ToolDialog listDialog, |
|
3061 |
ToolDialog infoDialog, |
|
3062 |
boolean edit) { |
|
3063 |
this.tool = tool; |
|
3064 |
this.tw = tw; |
|
3065 |
this.listDialog = listDialog; |
|
3066 |
this.infoDialog = infoDialog; |
|
3067 |
this.edit = edit; |
|
3068 |
} |
|
3069 |
||
3070 |
public void actionPerformed(ActionEvent e) { |
|
3071 |
||
3072 |
try { |
|
3073 |
// read in the new permission info from Dialog Box |
|
3074 |
PolicyParser.PermissionEntry pppe = |
|
3075 |
infoDialog.getPermFromDialog(); |
|
3076 |
||
3077 |
try { |
|
3078 |
tool.verifyPermission(pppe.permission, pppe.name, pppe.action); |
|
3079 |
} catch (ClassNotFoundException cnfe) { |
|
3080 |
MessageFormat form = new MessageFormat(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
3081 |
("Warning.Class.not.found.class")); |
2 | 3082 |
Object[] source = {pppe.permission}; |
3083 |
tool.warnings.addElement(form.format(source)); |
|
3084 |
tw.displayStatusDialog(infoDialog, form.format(source)); |
|
3085 |
} |
|
3086 |
||
3087 |
// add the permission to the GUI permission list |
|
3088 |
TaggedList permList = |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3089 |
(TaggedList)listDialog.getComponent(ToolDialog.PE_PERM_LIST); |
2 | 3090 |
|
3091 |
String permString = ToolDialog.PermissionEntryToUserFriendlyString(pppe); |
|
3092 |
if (edit) { |
|
3093 |
// if editing, replace the original permission |
|
3094 |
int which = permList.getSelectedIndex(); |
|
3095 |
permList.replaceTaggedItem(permString, pppe, which); |
|
3096 |
} else { |
|
3097 |
// if adding, just add it to the end |
|
3098 |
permList.addTaggedItem(permString, pppe); |
|
3099 |
} |
|
3100 |
infoDialog.dispose(); |
|
3101 |
||
3102 |
} catch (InvocationTargetException ite) { |
|
3103 |
tw.displayErrorDialog(infoDialog, ite.getTargetException()); |
|
3104 |
} catch (Exception ee) { |
|
3105 |
tw.displayErrorDialog(infoDialog, ee); |
|
3106 |
} |
|
3107 |
} |
|
3108 |
} |
|
3109 |
||
3110 |
/** |
|
3111 |
* Event handler for RemovePrinButton button |
|
3112 |
*/ |
|
3113 |
class RemovePrinButtonListener implements ActionListener { |
|
3114 |
||
3115 |
private PolicyTool tool; |
|
3116 |
private ToolWindow tw; |
|
3117 |
private ToolDialog td; |
|
3118 |
private boolean edit; |
|
3119 |
||
3120 |
RemovePrinButtonListener(PolicyTool tool, ToolWindow tw, |
|
3121 |
ToolDialog td, boolean edit) { |
|
3122 |
this.tool = tool; |
|
3123 |
this.tw = tw; |
|
3124 |
this.td = td; |
|
3125 |
this.edit = edit; |
|
3126 |
} |
|
3127 |
||
3128 |
public void actionPerformed(ActionEvent e) { |
|
3129 |
||
3130 |
// get the Principal selected from the Principal List |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3131 |
TaggedList prinList = (TaggedList)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3132 |
ToolDialog.PE_PRIN_LIST); |
2 | 3133 |
int prinIndex = prinList.getSelectedIndex(); |
3134 |
||
3135 |
if (prinIndex < 0) { |
|
3136 |
tw.displayErrorDialog(td, new Exception |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
3137 |
(PolicyTool.rb.getString("No.principal.selected"))); |
2 | 3138 |
return; |
3139 |
} |
|
3140 |
// remove the principal from the display |
|
3141 |
prinList.removeTaggedItem(prinIndex); |
|
3142 |
} |
|
3143 |
} |
|
3144 |
||
3145 |
/** |
|
3146 |
* Event handler for RemovePermButton button |
|
3147 |
*/ |
|
3148 |
class RemovePermButtonListener implements ActionListener { |
|
3149 |
||
3150 |
private PolicyTool tool; |
|
3151 |
private ToolWindow tw; |
|
3152 |
private ToolDialog td; |
|
3153 |
private boolean edit; |
|
3154 |
||
3155 |
RemovePermButtonListener(PolicyTool tool, ToolWindow tw, |
|
3156 |
ToolDialog td, boolean edit) { |
|
3157 |
this.tool = tool; |
|
3158 |
this.tw = tw; |
|
3159 |
this.td = td; |
|
3160 |
this.edit = edit; |
|
3161 |
} |
|
3162 |
||
3163 |
public void actionPerformed(ActionEvent e) { |
|
3164 |
||
3165 |
// get the Permission selected from the Permission List |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3166 |
TaggedList permList = (TaggedList)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3167 |
ToolDialog.PE_PERM_LIST); |
2 | 3168 |
int permIndex = permList.getSelectedIndex(); |
3169 |
||
3170 |
if (permIndex < 0) { |
|
3171 |
tw.displayErrorDialog(td, new Exception |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
3172 |
(PolicyTool.rb.getString("No.permission.selected"))); |
2 | 3173 |
return; |
3174 |
} |
|
3175 |
// remove the permission from the display |
|
3176 |
permList.removeTaggedItem(permIndex); |
|
3177 |
||
3178 |
} |
|
3179 |
} |
|
3180 |
||
3181 |
/** |
|
3182 |
* Event handler for Edit Principal button |
|
3183 |
* |
|
3184 |
* We need the editPolicyEntry boolean to tell us if the user is |
|
3185 |
* adding a new PolicyEntry at this time, or editing an existing entry. |
|
3186 |
* If the user is adding a new PolicyEntry, we ONLY update the |
|
3187 |
* GUI listing. If the user is editing an existing PolicyEntry, we |
|
3188 |
* update both the GUI listing and the actual PolicyEntry. |
|
3189 |
*/ |
|
3190 |
class EditPrinButtonListener implements ActionListener { |
|
3191 |
||
3192 |
private PolicyTool tool; |
|
3193 |
private ToolWindow tw; |
|
3194 |
private ToolDialog td; |
|
3195 |
private boolean editPolicyEntry; |
|
3196 |
||
3197 |
EditPrinButtonListener(PolicyTool tool, ToolWindow tw, |
|
3198 |
ToolDialog td, boolean editPolicyEntry) { |
|
3199 |
this.tool = tool; |
|
3200 |
this.tw = tw; |
|
3201 |
this.td = td; |
|
3202 |
this.editPolicyEntry = editPolicyEntry; |
|
3203 |
} |
|
3204 |
||
3205 |
public void actionPerformed(ActionEvent e) { |
|
3206 |
||
3207 |
// get the Principal selected from the Principal List |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3208 |
TaggedList list = (TaggedList)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3209 |
ToolDialog.PE_PRIN_LIST); |
2 | 3210 |
int prinIndex = list.getSelectedIndex(); |
3211 |
||
3212 |
if (prinIndex < 0) { |
|
3213 |
tw.displayErrorDialog(td, new Exception |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
3214 |
(PolicyTool.rb.getString("No.principal.selected"))); |
2 | 3215 |
return; |
3216 |
} |
|
3217 |
td.displayPrincipalDialog(editPolicyEntry, true); |
|
3218 |
} |
|
3219 |
} |
|
3220 |
||
3221 |
/** |
|
3222 |
* Event handler for Edit Permission button |
|
3223 |
* |
|
3224 |
* We need the editPolicyEntry boolean to tell us if the user is |
|
3225 |
* adding a new PolicyEntry at this time, or editing an existing entry. |
|
3226 |
* If the user is adding a new PolicyEntry, we ONLY update the |
|
3227 |
* GUI listing. If the user is editing an existing PolicyEntry, we |
|
3228 |
* update both the GUI listing and the actual PolicyEntry. |
|
3229 |
*/ |
|
3230 |
class EditPermButtonListener implements ActionListener { |
|
3231 |
||
3232 |
private PolicyTool tool; |
|
3233 |
private ToolWindow tw; |
|
3234 |
private ToolDialog td; |
|
3235 |
private boolean editPolicyEntry; |
|
3236 |
||
3237 |
EditPermButtonListener(PolicyTool tool, ToolWindow tw, |
|
3238 |
ToolDialog td, boolean editPolicyEntry) { |
|
3239 |
this.tool = tool; |
|
3240 |
this.tw = tw; |
|
3241 |
this.td = td; |
|
3242 |
this.editPolicyEntry = editPolicyEntry; |
|
3243 |
} |
|
3244 |
||
3245 |
public void actionPerformed(ActionEvent e) { |
|
3246 |
||
3247 |
// get the Permission selected from the Permission List |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3248 |
List list = (List)td.getComponent(ToolDialog.PE_PERM_LIST); |
2 | 3249 |
int permIndex = list.getSelectedIndex(); |
3250 |
||
3251 |
if (permIndex < 0) { |
|
3252 |
tw.displayErrorDialog(td, new Exception |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
3253 |
(PolicyTool.rb.getString("No.permission.selected"))); |
2 | 3254 |
return; |
3255 |
} |
|
3256 |
td.displayPermissionDialog(editPolicyEntry, true); |
|
3257 |
} |
|
3258 |
} |
|
3259 |
||
3260 |
/** |
|
3261 |
* Event handler for Principal Popup Menu |
|
3262 |
*/ |
|
3263 |
class PrincipalTypeMenuListener implements ItemListener { |
|
3264 |
||
3265 |
private ToolDialog td; |
|
3266 |
||
3267 |
PrincipalTypeMenuListener(ToolDialog td) { |
|
3268 |
this.td = td; |
|
3269 |
} |
|
3270 |
||
3271 |
public void itemStateChanged(ItemEvent e) { |
|
3272 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3273 |
Choice prin = (Choice)td.getComponent(ToolDialog.PRD_PRIN_CHOICE); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3274 |
TextField prinField = (TextField)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3275 |
ToolDialog.PRD_PRIN_TEXTFIELD); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3276 |
TextField nameField = (TextField)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3277 |
ToolDialog.PRD_NAME_TEXTFIELD); |
2 | 3278 |
|
3279 |
prin.getAccessibleContext().setAccessibleName( |
|
3280 |
PolicyTool.splitToWords((String)e.getItem())); |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3281 |
if (((String)e.getItem()).equals(ToolDialog.PRIN_TYPE)) { |
2 | 3282 |
// ignore if they choose "Principal Type:" item |
3283 |
if (prinField.getText() != null && |
|
3284 |
prinField.getText().length() > 0) { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3285 |
Prin inputPrin = ToolDialog.getPrin(prinField.getText(), true); |
2 | 3286 |
prin.select(inputPrin.CLASS); |
3287 |
} |
|
3288 |
return; |
|
3289 |
} |
|
3290 |
||
3291 |
// if you change the principal, clear the name |
|
3292 |
if (prinField.getText().indexOf((String)e.getItem()) == -1) { |
|
3293 |
nameField.setText(""); |
|
3294 |
} |
|
3295 |
||
3296 |
// set the text in the textfield and also modify the |
|
3297 |
// pull-down choice menus to reflect the correct possible |
|
3298 |
// set of names and actions |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3299 |
Prin inputPrin = ToolDialog.getPrin((String)e.getItem(), false); |
2 | 3300 |
if (inputPrin != null) { |
3301 |
prinField.setText(inputPrin.FULL_CLASS); |
|
3302 |
} |
|
3303 |
} |
|
3304 |
} |
|
3305 |
||
3306 |
/** |
|
3307 |
* Event handler for Permission Popup Menu |
|
3308 |
*/ |
|
3309 |
class PermissionMenuListener implements ItemListener { |
|
3310 |
||
3311 |
private ToolDialog td; |
|
3312 |
||
3313 |
PermissionMenuListener(ToolDialog td) { |
|
3314 |
this.td = td; |
|
3315 |
} |
|
3316 |
||
3317 |
public void itemStateChanged(ItemEvent e) { |
|
3318 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3319 |
Choice perms = (Choice)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3320 |
ToolDialog.PD_PERM_CHOICE); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3321 |
Choice names = (Choice)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3322 |
ToolDialog.PD_NAME_CHOICE); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3323 |
Choice actions = (Choice)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3324 |
ToolDialog.PD_ACTIONS_CHOICE); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3325 |
TextField nameField = (TextField)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3326 |
ToolDialog.PD_NAME_TEXTFIELD); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3327 |
TextField actionsField = (TextField)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3328 |
ToolDialog.PD_ACTIONS_TEXTFIELD); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3329 |
TextField permField = (TextField)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3330 |
ToolDialog.PD_PERM_TEXTFIELD); |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3331 |
TextField signedbyField = (TextField)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3332 |
ToolDialog.PD_SIGNEDBY_TEXTFIELD); |
2 | 3333 |
|
3334 |
perms.getAccessibleContext().setAccessibleName( |
|
3335 |
PolicyTool.splitToWords((String)e.getItem())); |
|
3336 |
||
3337 |
// ignore if they choose the 'Permission:' item |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3338 |
if (PolicyTool.collator.compare((String)e.getItem(), |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3339 |
ToolDialog.PERM) == 0) { |
2 | 3340 |
if (permField.getText() != null && |
3341 |
permField.getText().length() > 0) { |
|
3342 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3343 |
Perm inputPerm = ToolDialog.getPerm(permField.getText(), true); |
2 | 3344 |
if (inputPerm != null) { |
3345 |
perms.select(inputPerm.CLASS); |
|
3346 |
} |
|
3347 |
} |
|
3348 |
return; |
|
3349 |
} |
|
3350 |
||
3351 |
// if you change the permission, clear the name, actions, and signedBy |
|
3352 |
if (permField.getText().indexOf((String)e.getItem()) == -1) { |
|
3353 |
nameField.setText(""); |
|
3354 |
actionsField.setText(""); |
|
3355 |
signedbyField.setText(""); |
|
3356 |
} |
|
3357 |
||
3358 |
// set the text in the textfield and also modify the |
|
3359 |
// pull-down choice menus to reflect the correct possible |
|
3360 |
// set of names and actions |
|
3361 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3362 |
Perm inputPerm = ToolDialog.getPerm((String)e.getItem(), false); |
2 | 3363 |
if (inputPerm == null) { |
3364 |
permField.setText(""); |
|
3365 |
} else { |
|
3366 |
permField.setText(inputPerm.FULL_CLASS); |
|
3367 |
} |
|
3368 |
td.setPermissionNames(inputPerm, names, nameField); |
|
3369 |
td.setPermissionActions(inputPerm, actions, actionsField); |
|
3370 |
} |
|
3371 |
} |
|
3372 |
||
3373 |
/** |
|
3374 |
* Event handler for Permission Name Popup Menu |
|
3375 |
*/ |
|
3376 |
class PermissionNameMenuListener implements ItemListener { |
|
3377 |
||
3378 |
private ToolDialog td; |
|
3379 |
||
3380 |
PermissionNameMenuListener(ToolDialog td) { |
|
3381 |
this.td = td; |
|
3382 |
} |
|
3383 |
||
3384 |
public void itemStateChanged(ItemEvent e) { |
|
3385 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3386 |
Choice names = (Choice)td.getComponent(ToolDialog.PD_NAME_CHOICE); |
2 | 3387 |
names.getAccessibleContext().setAccessibleName( |
3388 |
PolicyTool.splitToWords((String)e.getItem())); |
|
3389 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3390 |
if (((String)e.getItem()).indexOf(ToolDialog.PERM_NAME) != -1) |
2 | 3391 |
return; |
3392 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3393 |
TextField tf = (TextField)td.getComponent(ToolDialog.PD_NAME_TEXTFIELD); |
2 | 3394 |
tf.setText((String)e.getItem()); |
3395 |
} |
|
3396 |
} |
|
3397 |
||
3398 |
/** |
|
3399 |
* Event handler for Permission Actions Popup Menu |
|
3400 |
*/ |
|
3401 |
class PermissionActionsMenuListener implements ItemListener { |
|
3402 |
||
3403 |
private ToolDialog td; |
|
3404 |
||
3405 |
PermissionActionsMenuListener(ToolDialog td) { |
|
3406 |
this.td = td; |
|
3407 |
} |
|
3408 |
||
3409 |
public void itemStateChanged(ItemEvent e) { |
|
3410 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3411 |
Choice actions = (Choice)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3412 |
ToolDialog.PD_ACTIONS_CHOICE); |
2 | 3413 |
actions.getAccessibleContext().setAccessibleName((String)e.getItem()); |
3414 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3415 |
if (((String)e.getItem()).indexOf(ToolDialog.PERM_ACTIONS) != -1) |
2 | 3416 |
return; |
3417 |
||
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3418 |
TextField tf = (TextField)td.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3419 |
ToolDialog.PD_ACTIONS_TEXTFIELD); |
2 | 3420 |
if (tf.getText() == null || tf.getText().equals("")) { |
3421 |
tf.setText((String)e.getItem()); |
|
3422 |
} else { |
|
3423 |
if (tf.getText().indexOf((String)e.getItem()) == -1) |
|
3424 |
tf.setText(tf.getText() + ", " + (String)e.getItem()); |
|
3425 |
} |
|
3426 |
} |
|
3427 |
} |
|
3428 |
||
3429 |
/** |
|
3430 |
* Event handler for all the children dialogs/windows |
|
3431 |
*/ |
|
3432 |
class ChildWindowListener implements WindowListener { |
|
3433 |
||
3434 |
private ToolDialog td; |
|
3435 |
||
3436 |
ChildWindowListener(ToolDialog td) { |
|
3437 |
this.td = td; |
|
3438 |
} |
|
3439 |
||
3440 |
public void windowOpened(WindowEvent we) { |
|
3441 |
} |
|
3442 |
||
3443 |
public void windowClosing(WindowEvent we) { |
|
3444 |
// same as pressing the "cancel" button |
|
3445 |
td.setVisible(false); |
|
3446 |
td.dispose(); |
|
3447 |
} |
|
3448 |
||
3449 |
public void windowClosed(WindowEvent we) { |
|
3450 |
} |
|
3451 |
||
3452 |
public void windowIconified(WindowEvent we) { |
|
3453 |
} |
|
3454 |
||
3455 |
public void windowDeiconified(WindowEvent we) { |
|
3456 |
} |
|
3457 |
||
3458 |
public void windowActivated(WindowEvent we) { |
|
3459 |
} |
|
3460 |
||
3461 |
public void windowDeactivated(WindowEvent we) { |
|
3462 |
} |
|
3463 |
} |
|
3464 |
||
3465 |
/** |
|
3466 |
* Event handler for CancelButton button |
|
3467 |
*/ |
|
3468 |
class CancelButtonListener implements ActionListener { |
|
3469 |
||
3470 |
private ToolDialog td; |
|
3471 |
||
3472 |
CancelButtonListener(ToolDialog td) { |
|
3473 |
this.td = td; |
|
3474 |
} |
|
3475 |
||
3476 |
public void actionPerformed(ActionEvent e) { |
|
3477 |
td.setVisible(false); |
|
3478 |
td.dispose(); |
|
3479 |
} |
|
3480 |
} |
|
3481 |
||
3482 |
/** |
|
3483 |
* Event handler for ErrorOKButton button |
|
3484 |
*/ |
|
3485 |
class ErrorOKButtonListener implements ActionListener { |
|
3486 |
||
3487 |
private ToolDialog ed; |
|
3488 |
||
3489 |
ErrorOKButtonListener(ToolDialog ed) { |
|
3490 |
this.ed = ed; |
|
3491 |
} |
|
3492 |
||
3493 |
public void actionPerformed(ActionEvent e) { |
|
3494 |
ed.setVisible(false); |
|
3495 |
ed.dispose(); |
|
3496 |
} |
|
3497 |
} |
|
3498 |
||
3499 |
/** |
|
3500 |
* Event handler for StatusOKButton button |
|
3501 |
*/ |
|
3502 |
class StatusOKButtonListener implements ActionListener { |
|
3503 |
||
3504 |
private ToolDialog sd; |
|
3505 |
||
3506 |
StatusOKButtonListener(ToolDialog sd) { |
|
3507 |
this.sd = sd; |
|
3508 |
} |
|
3509 |
||
3510 |
public void actionPerformed(ActionEvent e) { |
|
3511 |
sd.setVisible(false); |
|
3512 |
sd.dispose(); |
|
3513 |
} |
|
3514 |
} |
|
3515 |
||
3516 |
/** |
|
3517 |
* Event handler for UserSaveYes button |
|
3518 |
*/ |
|
3519 |
class UserSaveYesButtonListener implements ActionListener { |
|
3520 |
||
3521 |
private ToolDialog us; |
|
3522 |
private PolicyTool tool; |
|
3523 |
private ToolWindow tw; |
|
3524 |
private int select; |
|
3525 |
||
3526 |
UserSaveYesButtonListener(ToolDialog us, PolicyTool tool, |
|
3527 |
ToolWindow tw, int select) { |
|
3528 |
this.us = us; |
|
3529 |
this.tool = tool; |
|
3530 |
this.tw = tw; |
|
3531 |
this.select = select; |
|
3532 |
} |
|
3533 |
||
3534 |
public void actionPerformed(ActionEvent e) { |
|
3535 |
||
3536 |
// first get rid of the window |
|
3537 |
us.setVisible(false); |
|
3538 |
us.dispose(); |
|
3539 |
||
3540 |
try { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3541 |
String filename = ((TextField)tw.getComponent( |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3542 |
ToolWindow.MW_FILENAME_TEXTFIELD)).getText(); |
2 | 3543 |
if (filename == null || filename.equals("")) { |
3544 |
us.displaySaveAsDialog(select); |
|
3545 |
||
3546 |
// the above dialog will continue with the originally |
|
3547 |
// requested command if necessary |
|
3548 |
} else { |
|
3549 |
// save the policy entries to a file |
|
3550 |
tool.savePolicy(filename); |
|
3551 |
||
3552 |
// display status |
|
3553 |
MessageFormat form = new MessageFormat |
|
3554 |
(PolicyTool.rb.getString |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
3555 |
("Policy.successfully.written.to.filename")); |
2 | 3556 |
Object[] source = {filename}; |
3557 |
tw.displayStatusDialog(null, form.format(source)); |
|
3558 |
||
3559 |
// now continue with the originally requested command |
|
3560 |
// (QUIT, NEW, or OPEN) |
|
3561 |
us.userSaveContinue(tool, tw, us, select); |
|
3562 |
} |
|
3563 |
} catch (Exception ee) { |
|
3564 |
// error -- just report it and bail |
|
3565 |
tw.displayErrorDialog(null, ee); |
|
3566 |
} |
|
3567 |
} |
|
3568 |
} |
|
3569 |
||
3570 |
/** |
|
3571 |
* Event handler for UserSaveNoButton |
|
3572 |
*/ |
|
3573 |
class UserSaveNoButtonListener implements ActionListener { |
|
3574 |
||
3575 |
private PolicyTool tool; |
|
3576 |
private ToolWindow tw; |
|
3577 |
private ToolDialog us; |
|
3578 |
private int select; |
|
3579 |
||
3580 |
UserSaveNoButtonListener(ToolDialog us, PolicyTool tool, |
|
3581 |
ToolWindow tw, int select) { |
|
3582 |
this.us = us; |
|
3583 |
this.tool = tool; |
|
3584 |
this.tw = tw; |
|
3585 |
this.select = select; |
|
3586 |
} |
|
3587 |
||
3588 |
public void actionPerformed(ActionEvent e) { |
|
3589 |
us.setVisible(false); |
|
3590 |
us.dispose(); |
|
3591 |
||
3592 |
// now continue with the originally requested command |
|
3593 |
// (QUIT, NEW, or OPEN) |
|
3594 |
us.userSaveContinue(tool, tw, us, select); |
|
3595 |
} |
|
3596 |
} |
|
3597 |
||
3598 |
/** |
|
3599 |
* Event handler for UserSaveCancelButton |
|
3600 |
*/ |
|
3601 |
class UserSaveCancelButtonListener implements ActionListener { |
|
3602 |
||
3603 |
private ToolDialog us; |
|
3604 |
||
3605 |
UserSaveCancelButtonListener(ToolDialog us) { |
|
3606 |
this.us = us; |
|
3607 |
} |
|
3608 |
||
3609 |
public void actionPerformed(ActionEvent e) { |
|
3610 |
us.setVisible(false); |
|
3611 |
us.dispose(); |
|
3612 |
||
3613 |
// do NOT continue with the originally requested command |
|
3614 |
// (QUIT, NEW, or OPEN) |
|
3615 |
} |
|
3616 |
} |
|
3617 |
||
3618 |
/** |
|
3619 |
* Event handler for ConfirmRemovePolicyEntryOKButtonListener |
|
3620 |
*/ |
|
3621 |
class ConfirmRemovePolicyEntryOKButtonListener implements ActionListener { |
|
3622 |
||
3623 |
private PolicyTool tool; |
|
3624 |
private ToolWindow tw; |
|
3625 |
private ToolDialog us; |
|
3626 |
||
3627 |
ConfirmRemovePolicyEntryOKButtonListener(PolicyTool tool, |
|
3628 |
ToolWindow tw, ToolDialog us) { |
|
3629 |
this.tool = tool; |
|
3630 |
this.tw = tw; |
|
3631 |
this.us = us; |
|
3632 |
} |
|
3633 |
||
3634 |
public void actionPerformed(ActionEvent e) { |
|
3635 |
// remove the entry |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3636 |
List list = (List)tw.getComponent(ToolWindow.MW_POLICY_LIST); |
2 | 3637 |
int index = list.getSelectedIndex(); |
3638 |
PolicyEntry entries[] = tool.getEntry(); |
|
3639 |
tool.removeEntry(entries[index]); |
|
3640 |
||
3641 |
// redraw the window listing |
|
3642 |
list = new List(40, false); |
|
3643 |
list.addActionListener(new PolicyListListener(tool, tw)); |
|
3644 |
entries = tool.getEntry(); |
|
3645 |
if (entries != null) { |
|
3646 |
for (int i = 0; i < entries.length; i++) |
|
3647 |
list.add(entries[i].headerToString()); |
|
3648 |
} |
|
3649 |
tw.replacePolicyList(list); |
|
3650 |
us.setVisible(false); |
|
3651 |
us.dispose(); |
|
3652 |
} |
|
3653 |
} |
|
3654 |
||
3655 |
/** |
|
3656 |
* Just a special name, so that the codes dealing with this exception knows |
|
3657 |
* it's special, and does not pop out a warning box. |
|
3658 |
*/ |
|
3659 |
class NoDisplayException extends RuntimeException { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3660 |
private static final long serialVersionUID = -4611761427108719794L; |
2 | 3661 |
} |
3662 |
||
3663 |
/** |
|
3664 |
* This is a java.awt.List that bind an Object to each String it holds. |
|
3665 |
*/ |
|
3666 |
class TaggedList extends List { |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3667 |
private static final long serialVersionUID = -5676238110427785853L; |
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
3668 |
|
7977
f47f211cd627
7008713: diamond conversion of kerberos5 and security tools
smarks
parents:
7532
diff
changeset
|
3669 |
private java.util.List<Object> data = new LinkedList<>(); |
2 | 3670 |
public TaggedList(int i, boolean b) { |
3671 |
super(i, b); |
|
3672 |
} |
|
3673 |
||
3674 |
public Object getObject(int index) { |
|
3675 |
return data.get(index); |
|
3676 |
} |
|
3677 |
||
3678 |
@Override @Deprecated public void add(String string) { |
|
3679 |
throw new AssertionError("should not call add in TaggedList"); |
|
3680 |
} |
|
3681 |
public void addTaggedItem(String string, Object object) { |
|
3682 |
super.add(string); |
|
3683 |
data.add(object); |
|
3684 |
} |
|
3685 |
||
3686 |
@Override @Deprecated public void replaceItem(String string, int index) { |
|
3687 |
throw new AssertionError("should not call replaceItem in TaggedList"); |
|
3688 |
} |
|
3689 |
public void replaceTaggedItem(String string, Object object, int index) { |
|
3690 |
super.replaceItem(string, index); |
|
3691 |
data.set(index, object); |
|
3692 |
} |
|
3693 |
||
3694 |
@Override @Deprecated public void remove(int index) { |
|
3695 |
// Cannot throw AssertionError, because replaceItem() call remove() internally |
|
3696 |
super.remove(index); |
|
3697 |
} |
|
3698 |
public void removeTaggedItem(int index) { |
|
3699 |
super.remove(index); |
|
3700 |
data.remove(index); |
|
3701 |
} |
|
3702 |
} |
|
3703 |
||
3704 |
/** |
|
3705 |
* Convenience Principal Classes |
|
3706 |
*/ |
|
3707 |
||
3708 |
class Prin { |
|
3709 |
public final String CLASS; |
|
3710 |
public final String FULL_CLASS; |
|
3711 |
||
3712 |
public Prin(String clazz, String fullClass) { |
|
3713 |
this.CLASS = clazz; |
|
3714 |
this.FULL_CLASS = fullClass; |
|
3715 |
} |
|
3716 |
} |
|
3717 |
||
3718 |
class KrbPrin extends Prin { |
|
3719 |
public KrbPrin() { |
|
3720 |
super("KerberosPrincipal", |
|
3721 |
"javax.security.auth.kerberos.KerberosPrincipal"); |
|
3722 |
} |
|
3723 |
} |
|
3724 |
||
3725 |
class X500Prin extends Prin { |
|
3726 |
public X500Prin() { |
|
3727 |
super("X500Principal", |
|
3728 |
"javax.security.auth.x500.X500Principal"); |
|
3729 |
} |
|
3730 |
} |
|
3731 |
||
3732 |
/** |
|
3733 |
* Convenience Permission Classes |
|
3734 |
*/ |
|
3735 |
||
3736 |
class Perm { |
|
3737 |
public final String CLASS; |
|
3738 |
public final String FULL_CLASS; |
|
3739 |
public final String[] TARGETS; |
|
3740 |
public final String[] ACTIONS; |
|
3741 |
||
3742 |
public Perm(String clazz, String fullClass, |
|
3743 |
String[] targets, String[] actions) { |
|
3744 |
||
3745 |
this.CLASS = clazz; |
|
3746 |
this.FULL_CLASS = fullClass; |
|
3747 |
this.TARGETS = targets; |
|
3748 |
this.ACTIONS = actions; |
|
3749 |
} |
|
3750 |
} |
|
3751 |
||
3752 |
class AllPerm extends Perm { |
|
3753 |
public AllPerm() { |
|
3754 |
super("AllPermission", "java.security.AllPermission", null, null); |
|
3755 |
} |
|
3756 |
} |
|
3757 |
||
3758 |
class AudioPerm extends Perm { |
|
3759 |
public AudioPerm() { |
|
3760 |
super("AudioPermission", |
|
3761 |
"javax.sound.sampled.AudioPermission", |
|
3762 |
new String[] { |
|
3763 |
"play", |
|
3764 |
"record" |
|
3765 |
}, |
|
3766 |
null); |
|
3767 |
} |
|
3768 |
} |
|
3769 |
||
3770 |
class AuthPerm extends Perm { |
|
3771 |
public AuthPerm() { |
|
3772 |
super("AuthPermission", |
|
3773 |
"javax.security.auth.AuthPermission", |
|
3774 |
new String[] { |
|
3775 |
"doAs", |
|
3776 |
"doAsPrivileged", |
|
3777 |
"getSubject", |
|
3778 |
"getSubjectFromDomainCombiner", |
|
3779 |
"setReadOnly", |
|
3780 |
"modifyPrincipals", |
|
3781 |
"modifyPublicCredentials", |
|
3782 |
"modifyPrivateCredentials", |
|
3783 |
"refreshCredential", |
|
3784 |
"destroyCredential", |
|
3785 |
"createLoginContext.<" + PolicyTool.rb.getString("name") + ">", |
|
3786 |
"getLoginConfiguration", |
|
3787 |
"setLoginConfiguration", |
|
3788 |
"createLoginConfiguration.<" + |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
3789 |
PolicyTool.rb.getString("configuration.type") + ">", |
2 | 3790 |
"refreshLoginConfiguration" |
3791 |
}, |
|
3792 |
null); |
|
3793 |
} |
|
3794 |
} |
|
3795 |
||
3796 |
class AWTPerm extends Perm { |
|
3797 |
public AWTPerm() { |
|
3798 |
super("AWTPermission", |
|
3799 |
"java.awt.AWTPermission", |
|
3800 |
new String[] { |
|
3801 |
"accessClipboard", |
|
3802 |
"accessEventQueue", |
|
3803 |
"accessSystemTray", |
|
3804 |
"createRobot", |
|
3805 |
"fullScreenExclusive", |
|
3806 |
"listenToAllAWTEvents", |
|
3807 |
"readDisplayPixels", |
|
3808 |
"replaceKeyboardFocusManager", |
|
3809 |
"setAppletStub", |
|
3810 |
"setWindowAlwaysOnTop", |
|
3811 |
"showWindowWithoutWarningBanner", |
|
3812 |
"toolkitModality", |
|
3813 |
"watchMousePointer" |
|
3814 |
}, |
|
3815 |
null); |
|
3816 |
} |
|
3817 |
} |
|
3818 |
||
3819 |
class DelegationPerm extends Perm { |
|
3820 |
public DelegationPerm() { |
|
3821 |
super("DelegationPermission", |
|
3822 |
"javax.security.auth.kerberos.DelegationPermission", |
|
3823 |
new String[] { |
|
3824 |
// allow user input |
|
3825 |
}, |
|
3826 |
null); |
|
3827 |
} |
|
3828 |
} |
|
3829 |
||
3830 |
class FilePerm extends Perm { |
|
3831 |
public FilePerm() { |
|
3832 |
super("FilePermission", |
|
3833 |
"java.io.FilePermission", |
|
3834 |
new String[] { |
|
3835 |
"<<ALL FILES>>" |
|
3836 |
}, |
|
3837 |
new String[] { |
|
3838 |
"read", |
|
3839 |
"write", |
|
3840 |
"delete", |
|
3841 |
"execute" |
|
3842 |
}); |
|
3843 |
} |
|
3844 |
} |
|
3845 |
||
20787
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
20754
diff
changeset
|
3846 |
class URLPerm extends Perm { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
20754
diff
changeset
|
3847 |
public URLPerm() { |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
20754
diff
changeset
|
3848 |
super("URLPermission", |
ab071ce90368
8014719: HttpClient/ProxyTest.java failing with IAE HttpURLPermission.parseURI
michaelm
parents:
20754
diff
changeset
|
3849 |
"java.net.URLPermission", |
17692
685c0741cfbb
8012261: update policytool to support java.net.HttpURLPermission
weijun
parents:
15013
diff
changeset
|
3850 |
new String[] { |
685c0741cfbb
8012261: update policytool to support java.net.HttpURLPermission
weijun
parents:
15013
diff
changeset
|
3851 |
"<"+ PolicyTool.rb.getString("url") + ">", |
685c0741cfbb
8012261: update policytool to support java.net.HttpURLPermission
weijun
parents:
15013
diff
changeset
|
3852 |
}, |
685c0741cfbb
8012261: update policytool to support java.net.HttpURLPermission
weijun
parents:
15013
diff
changeset
|
3853 |
new String[] { |
685c0741cfbb
8012261: update policytool to support java.net.HttpURLPermission
weijun
parents:
15013
diff
changeset
|
3854 |
"<" + PolicyTool.rb.getString("method.list") + ">:<" |
685c0741cfbb
8012261: update policytool to support java.net.HttpURLPermission
weijun
parents:
15013
diff
changeset
|
3855 |
+ PolicyTool.rb.getString("request.headers.list") + ">", |
685c0741cfbb
8012261: update policytool to support java.net.HttpURLPermission
weijun
parents:
15013
diff
changeset
|
3856 |
}); |
685c0741cfbb
8012261: update policytool to support java.net.HttpURLPermission
weijun
parents:
15013
diff
changeset
|
3857 |
} |
685c0741cfbb
8012261: update policytool to support java.net.HttpURLPermission
weijun
parents:
15013
diff
changeset
|
3858 |
} |
685c0741cfbb
8012261: update policytool to support java.net.HttpURLPermission
weijun
parents:
15013
diff
changeset
|
3859 |
|
3482
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
715
diff
changeset
|
3860 |
class InqSecContextPerm extends Perm { |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
715
diff
changeset
|
3861 |
public InqSecContextPerm() { |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
715
diff
changeset
|
3862 |
super("InquireSecContextPermission", |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
715
diff
changeset
|
3863 |
"com.sun.security.jgss.InquireSecContextPermission", |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
715
diff
changeset
|
3864 |
new String[] { |
3483
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
3865 |
"KRB5_GET_SESSION_KEY", |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
3866 |
"KRB5_GET_TKT_FLAGS", |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
3867 |
"KRB5_GET_AUTHZ_DATA", |
a16fce1820ef
6821190: more InquireType values for ExtendedGSSContext
weijun
parents:
3482
diff
changeset
|
3868 |
"KRB5_GET_AUTHTIME" |
3482
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
715
diff
changeset
|
3869 |
}, |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
715
diff
changeset
|
3870 |
null); |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
715
diff
changeset
|
3871 |
} |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
715
diff
changeset
|
3872 |
} |
4aaa66ce712d
6710360: export Kerberos session key to applications
weijun
parents:
715
diff
changeset
|
3873 |
|
2 | 3874 |
class LogPerm extends Perm { |
3875 |
public LogPerm() { |
|
3876 |
super("LoggingPermission", |
|
3877 |
"java.util.logging.LoggingPermission", |
|
3878 |
new String[] { |
|
3879 |
"control" |
|
3880 |
}, |
|
3881 |
null); |
|
3882 |
} |
|
3883 |
} |
|
3884 |
||
3885 |
class MgmtPerm extends Perm { |
|
3886 |
public MgmtPerm() { |
|
3887 |
super("ManagementPermission", |
|
3888 |
"java.lang.management.ManagementPermission", |
|
3889 |
new String[] { |
|
3890 |
"control", |
|
3891 |
"monitor" |
|
3892 |
}, |
|
3893 |
null); |
|
3894 |
} |
|
3895 |
} |
|
3896 |
||
3897 |
class MBeanPerm extends Perm { |
|
3898 |
public MBeanPerm() { |
|
3899 |
super("MBeanPermission", |
|
3900 |
"javax.management.MBeanPermission", |
|
3901 |
new String[] { |
|
3902 |
// allow user input |
|
3903 |
}, |
|
3904 |
new String[] { |
|
3905 |
"addNotificationListener", |
|
3906 |
"getAttribute", |
|
3907 |
"getClassLoader", |
|
3908 |
"getClassLoaderFor", |
|
3909 |
"getClassLoaderRepository", |
|
3910 |
"getDomains", |
|
3911 |
"getMBeanInfo", |
|
3912 |
"getObjectInstance", |
|
3913 |
"instantiate", |
|
3914 |
"invoke", |
|
3915 |
"isInstanceOf", |
|
3916 |
"queryMBeans", |
|
3917 |
"queryNames", |
|
3918 |
"registerMBean", |
|
3919 |
"removeNotificationListener", |
|
3920 |
"setAttribute", |
|
3921 |
"unregisterMBean" |
|
3922 |
}); |
|
3923 |
} |
|
3924 |
} |
|
3925 |
||
3926 |
class MBeanSvrPerm extends Perm { |
|
3927 |
public MBeanSvrPerm() { |
|
3928 |
super("MBeanServerPermission", |
|
3929 |
"javax.management.MBeanServerPermission", |
|
3930 |
new String[] { |
|
3931 |
"createMBeanServer", |
|
3932 |
"findMBeanServer", |
|
3933 |
"newMBeanServer", |
|
3934 |
"releaseMBeanServer" |
|
3935 |
}, |
|
3936 |
null); |
|
3937 |
} |
|
3938 |
} |
|
3939 |
||
3940 |
class MBeanTrustPerm extends Perm { |
|
3941 |
public MBeanTrustPerm() { |
|
3942 |
super("MBeanTrustPermission", |
|
3943 |
"javax.management.MBeanTrustPermission", |
|
3944 |
new String[] { |
|
3945 |
"register" |
|
3946 |
}, |
|
3947 |
null); |
|
3948 |
} |
|
3949 |
} |
|
3950 |
||
3951 |
class NetPerm extends Perm { |
|
3952 |
public NetPerm() { |
|
3953 |
super("NetPermission", |
|
3954 |
"java.net.NetPermission", |
|
3955 |
new String[] { |
|
3956 |
"setDefaultAuthenticator", |
|
3957 |
"requestPasswordAuthentication", |
|
3958 |
"specifyStreamHandler", |
|
3959 |
"setProxySelector", |
|
3960 |
"getProxySelector", |
|
3961 |
"setCookieHandler", |
|
3962 |
"getCookieHandler", |
|
3963 |
"setResponseCache", |
|
3964 |
"getResponseCache" |
|
3965 |
}, |
|
3966 |
null); |
|
3967 |
} |
|
3968 |
} |
|
3969 |
||
3970 |
class PrivCredPerm extends Perm { |
|
3971 |
public PrivCredPerm() { |
|
3972 |
super("PrivateCredentialPermission", |
|
3973 |
"javax.security.auth.PrivateCredentialPermission", |
|
3974 |
new String[] { |
|
3975 |
// allow user input |
|
3976 |
}, |
|
3977 |
new String[] { |
|
3978 |
"read" |
|
3979 |
}); |
|
3980 |
} |
|
3981 |
} |
|
3982 |
||
3983 |
class PropPerm extends Perm { |
|
3984 |
public PropPerm() { |
|
3985 |
super("PropertyPermission", |
|
3986 |
"java.util.PropertyPermission", |
|
3987 |
new String[] { |
|
3988 |
// allow user input |
|
3989 |
}, |
|
3990 |
new String[] { |
|
3991 |
"read", |
|
3992 |
"write" |
|
3993 |
}); |
|
3994 |
} |
|
3995 |
} |
|
3996 |
||
3997 |
class ReflectPerm extends Perm { |
|
3998 |
public ReflectPerm() { |
|
3999 |
super("ReflectPermission", |
|
4000 |
"java.lang.reflect.ReflectPermission", |
|
4001 |
new String[] { |
|
4002 |
"suppressAccessChecks" |
|
4003 |
}, |
|
4004 |
null); |
|
4005 |
} |
|
4006 |
} |
|
4007 |
||
4008 |
class RuntimePerm extends Perm { |
|
4009 |
public RuntimePerm() { |
|
4010 |
super("RuntimePermission", |
|
4011 |
"java.lang.RuntimePermission", |
|
4012 |
new String[] { |
|
4013 |
"createClassLoader", |
|
4014 |
"getClassLoader", |
|
4015 |
"setContextClassLoader", |
|
4016 |
"enableContextClassLoaderOverride", |
|
705
1db8adb3ea95
6711509: PolicyTool is misspelling Runtime permission - 'setSecurityManager' entry in the policy file
weijun
parents:
2
diff
changeset
|
4017 |
"setSecurityManager", |
2 | 4018 |
"createSecurityManager", |
4019 |
"getenv.<" + |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
4020 |
PolicyTool.rb.getString("environment.variable.name") + ">", |
2 | 4021 |
"exitVM", |
4022 |
"shutdownHooks", |
|
4023 |
"setFactory", |
|
4024 |
"setIO", |
|
4025 |
"modifyThread", |
|
4026 |
"stopThread", |
|
4027 |
"modifyThreadGroup", |
|
4028 |
"getProtectionDomain", |
|
4029 |
"readFileDescriptor", |
|
4030 |
"writeFileDescriptor", |
|
4031 |
"loadLibrary.<" + |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
4032 |
PolicyTool.rb.getString("library.name") + ">", |
2 | 4033 |
"accessClassInPackage.<" + |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
4034 |
PolicyTool.rb.getString("package.name")+">", |
2 | 4035 |
"defineClassInPackage.<" + |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
4036 |
PolicyTool.rb.getString("package.name")+">", |
2 | 4037 |
"accessDeclaredMembers", |
4038 |
"queuePrintJob", |
|
4039 |
"getStackTrace", |
|
4040 |
"setDefaultUncaughtExceptionHandler", |
|
4041 |
"preferences", |
|
4042 |
"usePolicy", |
|
4043 |
// "inheritedChannel" |
|
4044 |
}, |
|
4045 |
null); |
|
4046 |
} |
|
4047 |
} |
|
4048 |
||
4049 |
class SecurityPerm extends Perm { |
|
4050 |
public SecurityPerm() { |
|
4051 |
super("SecurityPermission", |
|
4052 |
"java.security.SecurityPermission", |
|
4053 |
new String[] { |
|
4054 |
"createAccessControlContext", |
|
4055 |
"getDomainCombiner", |
|
4056 |
"getPolicy", |
|
4057 |
"setPolicy", |
|
4058 |
"createPolicy.<" + |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
4059 |
PolicyTool.rb.getString("policy.type") + ">", |
2 | 4060 |
"getProperty.<" + |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
4061 |
PolicyTool.rb.getString("property.name") + ">", |
2 | 4062 |
"setProperty.<" + |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
4063 |
PolicyTool.rb.getString("property.name") + ">", |
2 | 4064 |
"insertProvider.<" + |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
4065 |
PolicyTool.rb.getString("provider.name") + ">", |
2 | 4066 |
"removeProvider.<" + |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
4067 |
PolicyTool.rb.getString("provider.name") + ">", |
2 | 4068 |
//"setSystemScope", |
4069 |
//"setIdentityPublicKey", |
|
4070 |
//"setIdentityInfo", |
|
4071 |
//"addIdentityCertificate", |
|
4072 |
//"removeIdentityCertificate", |
|
4073 |
//"printIdentity", |
|
4074 |
"clearProviderProperties.<" + |
|
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
4075 |
PolicyTool.rb.getString("provider.name") + ">", |
2 | 4076 |
"putProviderProperty.<" + |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
4077 |
PolicyTool.rb.getString("provider.name") + ">", |
2 | 4078 |
"removeProviderProperty.<" + |
7179
4afb81e50183
6987827: security/util/Resources.java needs improvement
weijun
parents:
6542
diff
changeset
|
4079 |
PolicyTool.rb.getString("provider.name") + ">", |
2 | 4080 |
//"getSignerPrivateKey", |
4081 |
//"setSignerKeyPair" |
|
4082 |
}, |
|
4083 |
null); |
|
4084 |
} |
|
4085 |
} |
|
4086 |
||
4087 |
class SerialPerm extends Perm { |
|
4088 |
public SerialPerm() { |
|
4089 |
super("SerializablePermission", |
|
4090 |
"java.io.SerializablePermission", |
|
4091 |
new String[] { |
|
4092 |
"enableSubclassImplementation", |
|
4093 |
"enableSubstitution" |
|
4094 |
}, |
|
4095 |
null); |
|
4096 |
} |
|
4097 |
} |
|
4098 |
||
4099 |
class ServicePerm extends Perm { |
|
4100 |
public ServicePerm() { |
|
4101 |
super("ServicePermission", |
|
4102 |
"javax.security.auth.kerberos.ServicePermission", |
|
4103 |
new String[] { |
|
4104 |
// allow user input |
|
4105 |
}, |
|
4106 |
new String[] { |
|
4107 |
"initiate", |
|
4108 |
"accept" |
|
4109 |
}); |
|
4110 |
} |
|
4111 |
} |
|
4112 |
||
4113 |
class SocketPerm extends Perm { |
|
4114 |
public SocketPerm() { |
|
4115 |
super("SocketPermission", |
|
4116 |
"java.net.SocketPermission", |
|
4117 |
new String[] { |
|
4118 |
// allow user input |
|
4119 |
}, |
|
4120 |
new String[] { |
|
4121 |
"accept", |
|
4122 |
"connect", |
|
4123 |
"listen", |
|
4124 |
"resolve" |
|
4125 |
}); |
|
4126 |
} |
|
4127 |
} |
|
4128 |
||
4129 |
class SQLPerm extends Perm { |
|
4130 |
public SQLPerm() { |
|
4131 |
super("SQLPermission", |
|
4132 |
"java.sql.SQLPermission", |
|
4133 |
new String[] { |
|
6542
155856185c1b
6845220: Need to update Policytool for Rowset 1.1 and JDBC 4.1 MR added permissions
weijun
parents:
5627
diff
changeset
|
4134 |
"setLog", |
155856185c1b
6845220: Need to update Policytool for Rowset 1.1 and JDBC 4.1 MR added permissions
weijun
parents:
5627
diff
changeset
|
4135 |
"callAbort", |
155856185c1b
6845220: Need to update Policytool for Rowset 1.1 and JDBC 4.1 MR added permissions
weijun
parents:
5627
diff
changeset
|
4136 |
"setSyncFactory", |
155856185c1b
6845220: Need to update Policytool for Rowset 1.1 and JDBC 4.1 MR added permissions
weijun
parents:
5627
diff
changeset
|
4137 |
"setNetworkTimeout", |
2 | 4138 |
}, |
4139 |
null); |
|
4140 |
} |
|
4141 |
} |
|
4142 |
||
4143 |
class SSLPerm extends Perm { |
|
4144 |
public SSLPerm() { |
|
4145 |
super("SSLPermission", |
|
4146 |
"javax.net.ssl.SSLPermission", |
|
4147 |
new String[] { |
|
4148 |
"setHostnameVerifier", |
|
4149 |
"getSSLSessionContext" |
|
4150 |
}, |
|
4151 |
null); |
|
4152 |
} |
|
4153 |
} |
|
4154 |
||
4155 |
class SubjDelegPerm extends Perm { |
|
4156 |
public SubjDelegPerm() { |
|
4157 |
super("SubjectDelegationPermission", |
|
4158 |
"javax.management.remote.SubjectDelegationPermission", |
|
4159 |
new String[] { |
|
4160 |
// allow user input |
|
4161 |
}, |
|
4162 |
null); |
|
4163 |
} |
|
4164 |
} |