01: package pnuts.security;
02:
03: import java.security.*;
04: import java.util.Enumeration;
05:
06: public class FilterPermissions extends PermissionCollection {
07:
08: private PermissionCollection base;
09: private PermissionCollection notPermitted;
10:
11: public FilterPermissions(PermissionCollection base,
12: PermissionCollection notPermitted) {
13: this .base = base;
14: this .notPermitted = notPermitted;
15: }
16:
17: public FilterPermissions(PermissionCollection base,
18: Permission notPermitted) {
19: this .base = base;
20: PermissionCollection col = new Permissions();
21: col.add(notPermitted);
22: this .notPermitted = col;
23: }
24:
25: public void add(Permission permission) {
26: base.add(permission);
27: }
28:
29: public boolean implies(Permission permission) {
30: if (notPermitted.implies(permission)) {
31: return false;
32: }
33: return base.implies(permission);
34: }
35:
36: public Enumeration elements() {
37: return base.elements();
38: }
39:
40: public String toString() {
41: StringBuffer sbuf = new StringBuffer();
42: sbuf.append(getClass().getName());
43: sbuf.append("@");
44: sbuf.append(hashCode());
45: sbuf.append("(\n");
46: for (Enumeration e = base.elements(); e.hasMoreElements();) {
47: sbuf.append(e.nextElement());
48: sbuf.append("\n");
49: }
50: sbuf.append("\n");
51: for (Enumeration e = notPermitted.elements(); e
52: .hasMoreElements();) {
53: sbuf.append(e.nextElement());
54: sbuf.append("\n");
55: }
56: sbuf.append(")");
57: return sbuf.toString();
58: }
59: }
|