2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.security;
22 import java.util.concurrent.CopyOnWriteArraySet;
27 * Badly named class that holds the role and user data constraint info for a
28 * path/http method combination, extracted and combined from security
31 * @version $Rev: 4793 $ $Date: 2009-03-19 00:00:01 +0100 (Thu, 19 Mar 2009) $
35 private boolean _isAnyAuth;
36 private boolean _isAnyRole;
37 private boolean _checked;
38 private boolean _forbidden;
39 private UserDataConstraint _userDataConstraint;
42 * List of permitted roles
44 private final Set<String> _roles = new CopyOnWriteArraySet<String>();
50 public boolean isChecked()
55 public void setChecked(boolean checked)
57 this._checked = checked;
67 public boolean isForbidden()
72 public void setForbidden(boolean forbidden)
74 this._forbidden = forbidden;
78 _userDataConstraint = null;
85 public boolean isAnyRole()
90 public void setAnyRole(boolean anyRole)
92 this._isAnyRole=anyRole;
97 public boolean isAnyAuth ()
102 public void setAnyAuth(boolean anyAuth)
104 this._isAnyAuth=anyAuth;
109 public UserDataConstraint getUserDataConstraint()
111 return _userDataConstraint;
114 public void setUserDataConstraint(UserDataConstraint userDataConstraint)
116 if (userDataConstraint == null) throw new NullPointerException("Null UserDataConstraint");
117 if (this._userDataConstraint == null)
120 this._userDataConstraint = userDataConstraint;
124 this._userDataConstraint = this._userDataConstraint.combine(userDataConstraint);
128 public Set<String> getRoles()
133 public void addRole(String role)
138 public void combine(RoleInfo other)
140 if (other._forbidden)
142 else if (!other._checked) // TODO is this the right way around???
144 else if (other._isAnyRole)
146 else if (other._isAnyAuth)
148 else if (!_isAnyRole)
150 for (String r : other._roles)
154 setUserDataConstraint(other._userDataConstraint);
158 public String toString()
160 return "{RoleInfo"+(_forbidden?",F":"")+(_checked?",C":"")+(_isAnyRole?",*":_roles)+(_userDataConstraint!=null?","+_userDataConstraint:"")+"}";