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