2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.security.authorization;
18 import static org.wamblee.security.authorization.AuthorizationResult.DENIED;
19 import static org.wamblee.security.authorization.AuthorizationResult.GRANTED;
21 import org.wamblee.usermgt.User;
24 * Test authorization rule that also counts the number of times the rule
27 * @author Erik Brakkee
29 public class TestAuthorizationRule extends UrlAuthorizationRule {
31 * Counts the number of matches.
33 private int matches = 0;
36 * Creates a new TestAuthorizationRule object.
39 public TestAuthorizationRule(AuthorizationResult aResult, String aGroup,
40 String aPath, Class<? extends Operation> aOperation) {
41 super(aResult, new GroupUserCondition(aGroup),
42 new StartsWithPathCondition(aPath), TestResource.class,
43 new IsaOperationCondition(aOperation));
47 * Creates a new TestAuthorizationRule object.
49 protected TestAuthorizationRule() {
57 * org.wamblee.security.authorization.UrlAuthorizationRule#getPath(java.
61 protected String getResourcePath(Object aResource) {
62 return ((TestResource) aResource).getPath();
69 * org.wamblee.security.authorization.UrlAuthorizationRule#isAllowed(java
70 * .lang.Object, org.wamblee.security.authorization.Operation,
71 * org.wamblee.usermgt.UserAccessor)
74 public AuthorizationResult isAllowed(Object aResource,
75 Operation aOperation, User aUser) {
76 AuthorizationResult result = super.isAllowed(aResource, aOperation,
79 if (result.equals(GRANTED) || result.equals(DENIED)) {
86 public int getMatchCount() {