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