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.
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;
25 * Test authorization rule that also counts the number of times the rule
28 * @author Erik Brakkee
30 public class TestAuthorizationRule extends UrlAuthorizationRule {
32 * Counts the number of matches.
34 private int matches = 0;
37 * Creates a new TestAuthorizationRule object.
39 * @param aResult DOCUMENT ME!
40 * @param aGroup DOCUMENT ME!
41 * @param aPath DOCUMENT ME!
42 * @param aOperation DOCUMENT ME!
44 public TestAuthorizationRule(AuthorizationResult aResult, String aGroup,
45 String aPath, Class<?extends Operation> aOperation) {
46 super(aResult, new GroupUserCondition(aGroup),
47 new StartsWithPathCondition(aPath), TestResource.class,
48 new IsaOperationCondition(aOperation));
52 * Creates a new TestAuthorizationRule object.
54 protected TestAuthorizationRule() {
59 * @see org.wamblee.security.authorization.UrlAuthorizationRule#getPath(java.lang.Object)
64 * @param aResource DOCUMENT ME!
66 * @return DOCUMENT ME!
69 protected String getResourcePath(Object aResource) {
70 return ((TestResource) aResource).getPath();
74 * @see org.wamblee.security.authorization.UrlAuthorizationRule#isAllowed(java.lang.Object, org.wamblee.security.authorization.Operation, org.wamblee.usermgt.UserAccessor)
79 * @param aResource DOCUMENT ME!
80 * @param anOperation DOCUMENT ME!
81 * @param aUser DOCUMENT ME!
83 * @return DOCUMENT ME!
86 public AuthorizationResult isAllowed(Object aResource,
87 Operation anOperation, User aUser) {
88 AuthorizationResult result = super.isAllowed(aResource, anOperation,
91 if (result.equals(GRANTED) || result.equals(DENIED)) {
101 * @return DOCUMENT ME!
103 public int getMatchCount() {
110 public void reset() {