1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.security;
15
16 import java.util.Set;
17 import java.util.concurrent.CopyOnWriteArraySet;
18
19
20
21
22
23
24
25
26
27 public class RoleInfo
28 {
29 private boolean _isAnyRole;
30 private boolean _checked;
31 private boolean _forbidden;
32 private UserDataConstraint _userDataConstraint;
33
34 private final Set<String> _roles = new CopyOnWriteArraySet<String>();
35
36 public RoleInfo()
37 {
38 }
39
40 public boolean isChecked()
41 {
42 return _checked;
43 }
44
45 public void setChecked(boolean checked)
46 {
47 this._checked = checked;
48 if (!checked)
49 {
50 _forbidden=false;
51 _roles.clear();
52 _isAnyRole=false;
53 }
54 }
55
56 public boolean isForbidden()
57 {
58 return _forbidden;
59 }
60
61 public void setForbidden(boolean forbidden)
62 {
63 this._forbidden = forbidden;
64 if (forbidden)
65 {
66 _checked = true;
67 _userDataConstraint = null;
68 _isAnyRole=false;
69 _roles.clear();
70 }
71 }
72
73 public boolean isAnyRole()
74 {
75 return _isAnyRole;
76 }
77
78 public void setAnyRole(boolean anyRole)
79 {
80 this._isAnyRole=anyRole;
81 if (anyRole)
82 {
83 _checked = true;
84 _roles.clear();
85 }
86 }
87
88 public UserDataConstraint getUserDataConstraint()
89 {
90 return _userDataConstraint;
91 }
92
93 public void setUserDataConstraint(UserDataConstraint userDataConstraint)
94 {
95 if (userDataConstraint == null) throw new NullPointerException("Null UserDataConstraint");
96 if (this._userDataConstraint == null)
97 {
98 this._userDataConstraint = userDataConstraint;
99 }
100 else
101 {
102 this._userDataConstraint = this._userDataConstraint.combine(userDataConstraint);
103 }
104 }
105
106 public Set<String> getRoles()
107 {
108 return _roles;
109 }
110
111 public void addRole(String role)
112 {
113 _roles.add(role);
114 }
115
116 public void combine(RoleInfo other)
117 {
118 if (other._forbidden)
119 setForbidden(true);
120 else if (!other._checked)
121 setChecked(true);
122 else if (other._isAnyRole)
123 setAnyRole(true);
124 else if (!_isAnyRole)
125 {
126 for (String r : other._roles)
127 _roles.add(r);
128 }
129
130 setUserDataConstraint(other._userDataConstraint);
131 }
132
133 @Override
134 public String toString()
135 {
136 return "{RoleInfo"+(_forbidden?",F":"")+(_checked?",C":"")+(_isAnyRole?",*":_roles)+"}";
137 }
138 }