2 * Copyright 2005 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.
17 package org.wamblee.security.authorization;
19 import static org.wamblee.security.authorization.AuthorizationResult.DENIED;
20 import static org.wamblee.security.authorization.AuthorizationResult.GRANTED;
22 import org.wamblee.usermgt.User;
25 * Test authorization rule that also counts the number of times the rule matches.
27 * @author Erik Brakkee
29 public class TestAuthorizationRule extends UrlAuthorizationRule {
32 * Counts the number of matches.
34 private int _matches = 0;
36 public TestAuthorizationRule( AuthorizationResult aResult, String aGroup,
37 String aPath, Class<? extends Operation> aOperation) {
38 super(aResult, new GroupUserCondition(aGroup),
39 new StartsWithPathCondition(aPath), TestResource.class, new IsaOperationCondition(aOperation));
42 protected TestAuthorizationRule() {
47 * @see org.wamblee.security.authorization.UrlAuthorizationRule#getPath(java.lang.Object)
50 protected String getResourcePath(Object aResource) {
51 return ((TestResource)aResource).getPath();
55 * @see org.wamblee.security.authorization.UrlAuthorizationRule#isAllowed(java.lang.Object, org.wamblee.security.authorization.Operation, org.wamblee.usermgt.UserAccessor)
58 public AuthorizationResult isAllowed(Object aResource, Operation anOperation, User aUser) {
60 AuthorizationResult result = super.isAllowed(aResource, anOperation, aUser);
61 if ( result.equals(GRANTED) || result.equals(DENIED)) {
67 public int getMatchCount() {