01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.commons.chain.web;
17:
18: import java.security.Principal;
19:
20: /**
21: * <p>Mock <strong>Principal</strong> object for low-level unit tests.</p>
22: */
23:
24: public class MockPrincipal implements Principal {
25:
26: public MockPrincipal() {
27: super ();
28: this .name = "";
29: this .roles = new String[0];
30: }
31:
32: public MockPrincipal(String name) {
33: super ();
34: this .name = name;
35: this .roles = new String[0];
36: }
37:
38: public MockPrincipal(String name, String roles[]) {
39: super ();
40: this .name = name;
41: this .roles = roles;
42: }
43:
44: protected String name = null;
45:
46: protected String roles[] = null;
47:
48: public String getName() {
49: return (this .name);
50: }
51:
52: public boolean isUserInRole(String role) {
53: for (int i = 0; i < roles.length; i++) {
54: if (role.equals(roles[i])) {
55: return (true);
56: }
57: }
58: return (false);
59: }
60:
61: public boolean equals(Object o) {
62: if (o == null) {
63: return (false);
64: }
65: if (!(o instanceof Principal)) {
66: return (false);
67: }
68: Principal p = (Principal) o;
69: if (name == null) {
70: return (p.getName() == null);
71: } else {
72: return (name.equals(p.getName()));
73: }
74: }
75:
76: public int hashCode() {
77: if (name == null) {
78: return ("".hashCode());
79: } else {
80: return (name.hashCode());
81: }
82: }
83:
84: }
|