01: // ========================================================================
02: // $Id: StrictRoleCheckPolicy.java 1001 2006-09-23 09:31:51Z janb $
03: // Copyright 2003-2004 Mort Bay Consulting Pty. Ltd.
04: // ------------------------------------------------------------------------
05: // Licensed under the Apache License, Version 2.0 (the "License");
06: // you may not use this file except in compliance with the License.
07: // You may obtain a copy of the License at
08: // http://www.apache.org/licenses/LICENSE-2.0
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14: // ========================================================================
15:
16: package org.mortbay.jetty.plus.jaas;
17:
18: import java.security.Principal;
19: import java.security.acl.Group;
20: import java.util.Enumeration;
21:
22: /* ---------------------------------------------------- */
23: /** StrictRoleCheckPolicy
24: * <p>Enforces that if a runAsRole is present, then the
25: * role to check must be the same as that runAsRole and
26: * the set of static roles is ignored.
27: *
28: *
29: *
30: * @org.apache.xbean.XBean description ="Check only topmost role in stack of roles for user"
31: */
32: public class StrictRoleCheckPolicy implements RoleCheckPolicy {
33:
34: public boolean checkRole(String roleName, Principal runAsRole,
35: Group roles) {
36: //check if this user has had any temporary role pushed onto
37: //them. If so, then only check if the user has that role.
38: if (runAsRole != null) {
39: return (roleName.equals(runAsRole.getName()));
40: } else {
41: if (roles == null)
42: return false;
43: Enumeration rolesEnum = roles.members();
44: boolean found = false;
45: while (rolesEnum.hasMoreElements() && !found) {
46: Principal p = (Principal) rolesEnum.nextElement();
47: found = roleName.equals(p.getName());
48: }
49: return found;
50: }
51:
52: }
53:
54: }
|