01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.web.tomcat.security;
23:
24: /**
25: * An enum for the mode for handling the role-name=* security authorization
26: * mode.
27: *
28: * @author Scott.Stark@jboss.org
29: * @version $Revision: 57206 $
30: */
31: public class AllRolesMode {
32: private String name;
33: /** Use the strict servlet spec interpretation which requires that the user
34: * have one of the web-app/security-role/role-name
35: */
36: public static final AllRolesMode STRICT_MODE = new AllRolesMode(
37: "strict");
38: /** Allow any authenticated user
39: */
40: public static final AllRolesMode AUTH_ONLY_MODE = new AllRolesMode(
41: "authOnly");
42: /** Allow any authenticated user only if there are no web-app/security-roles
43: */
44: public static final AllRolesMode STRICT_AUTH_ONLY_MODE = new AllRolesMode(
45: "strictAuthOnly");
46:
47: static AllRolesMode toMode(String name) {
48: AllRolesMode mode;
49: if (name.equalsIgnoreCase(STRICT_MODE.name))
50: mode = STRICT_MODE;
51: else if (name.equalsIgnoreCase(AUTH_ONLY_MODE.name))
52: mode = AUTH_ONLY_MODE;
53: else if (name.equalsIgnoreCase(STRICT_AUTH_ONLY_MODE.name))
54: mode = STRICT_AUTH_ONLY_MODE;
55: else
56: throw new IllegalStateException(
57: "Unknown mode, must be one of: strict, authOnly, strictAuthOnly");
58: return mode;
59: }
60:
61: private AllRolesMode(String name) {
62: this .name = name;
63: }
64:
65: public boolean equals(Object o) {
66: boolean equals = false;
67: if (o instanceof AllRolesMode) {
68: AllRolesMode mode = (AllRolesMode) o;
69: equals = name.equals(mode.name);
70: }
71: return equals;
72: }
73:
74: public int hashCode() {
75: return name.hashCode();
76: }
77:
78: public String toString() {
79: return "AllRolesMode(" + name + ")";
80: }
81: }
|