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 public class RoleInfo
33 {
34 private boolean _isAnyRole;
35 private boolean _checked;
36 private boolean _forbidden;
37 private UserDataConstraint _userDataConstraint;
38
39 private final Set<String> _roles = new CopyOnWriteArraySet<String>();
40
41 public RoleInfo()
42 {
43 }
44
45 public boolean isChecked()
46 {
47 return _checked;
48 }
49
50 public void setChecked(boolean checked)
51 {
52 this._checked = checked;
53 if (!checked)
54 {
55 _forbidden=false;
56 _roles.clear();
57 _isAnyRole=false;
58 }
59 }
60
61 public boolean isForbidden()
62 {
63 return _forbidden;
64 }
65
66 public void setForbidden(boolean forbidden)
67 {
68 this._forbidden = forbidden;
69 if (forbidden)
70 {
71 _checked = true;
72 _userDataConstraint = null;
73 _isAnyRole=false;
74 _roles.clear();
75 }
76 }
77
78 public boolean isAnyRole()
79 {
80 return _isAnyRole;
81 }
82
83 public void setAnyRole(boolean anyRole)
84 {
85 this._isAnyRole=anyRole;
86 if (anyRole)
87 {
88 _checked = true;
89 _roles.clear();
90 }
91 }
92
93 public UserDataConstraint getUserDataConstraint()
94 {
95 return _userDataConstraint;
96 }
97
98 public void setUserDataConstraint(UserDataConstraint userDataConstraint)
99 {
100 if (userDataConstraint == null) throw new NullPointerException("Null UserDataConstraint");
101 if (this._userDataConstraint == null)
102 {
103 this._userDataConstraint = userDataConstraint;
104 }
105 else
106 {
107 this._userDataConstraint = this._userDataConstraint.combine(userDataConstraint);
108 }
109 }
110
111 public Set<String> getRoles()
112 {
113 return _roles;
114 }
115
116 public void addRole(String role)
117 {
118 _roles.add(role);
119 }
120
121 public void combine(RoleInfo other)
122 {
123 if (other._forbidden)
124 setForbidden(true);
125 else if (!other._checked)
126 setChecked(true);
127 else if (other._isAnyRole)
128 setAnyRole(true);
129 else if (!_isAnyRole)
130 {
131 for (String r : other._roles)
132 _roles.add(r);
133 }
134
135 setUserDataConstraint(other._userDataConstraint);
136 }
137
138 @Override
139 public String toString()
140 {
141 return "{RoleInfo"+(_forbidden?",F":"")+(_checked?",C":"")+(_isAnyRole?",*":_roles)+"}";
142 }
143 }