01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.portal.tools.helper;
18:
19: import java.util.StringTokenizer;
20:
21: import org.apache.cocoon.portal.profile.PortalUser;
22:
23: /**
24: * A role matcher matching against several role.
25: *
26: * @version CVS $Id: MultipleRoleMatcher.java 433543 2006-08-22 06:22:54Z crossley $
27: */
28: public class MultipleRoleMatcher implements RoleMatcher {
29:
30: /**
31: * The character used to seperate multiple roles.
32: */
33: public static final String ROLE_SEPARATOR = "+";
34:
35: /**
36: * The role.
37: */
38: private String[] roles;
39:
40: /**
41: * Creates a new MultipleRoleMatcher.
42: */
43: public MultipleRoleMatcher(String roles) {
44: StringTokenizer tokenizer = new StringTokenizer(roles,
45: ROLE_SEPARATOR, false);
46:
47: this .roles = new String[tokenizer.countTokens()];
48:
49: String token;
50: int i = 0;
51: while (tokenizer.hasMoreTokens()) {
52: token = tokenizer.nextToken();
53: this .roles[i] = token;
54: i++;
55: }
56: }
57:
58: /**
59: * Overridden from superclass.
60: *
61: * @see RoleMatcher#matches(PortalUser)
62: */
63: public boolean matches(PortalUser user) {
64: // The user must have all roles
65: int length = this .roles.length;
66: for (int i = 0; i < length; i++) {
67: if (!user.isUserInRole(this .roles[i])) {
68: return false;
69: }
70: }
71: return true;
72: }
73: }
|