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.*;
20 import javax.persistence.DiscriminatorValue;
21 import javax.persistence.Entity;
22 import javax.persistence.Transient;
25 * Test authorization rule that also counts the number of times the rule
28 * @author Erik Brakkee
31 @DiscriminatorValue("TEST")
32 public class TestAuthorizationRule extends UrlAuthorizationRule {
34 * Counts the number of matches.
37 private int matches = 0;
40 * Creates a new TestAuthorizationRule object.
43 public TestAuthorizationRule(AuthorizationResult aResult, String aGroup,
44 String aPath, Class<? extends Operation> aOperation) {
45 super(aResult, new GroupUserCondition(aGroup),
46 new StartsWithPathCondition(aPath), TestResource.class,
47 new IsaOperationCondition(aOperation));
51 * Creates a new TestAuthorizationRule object.
53 protected TestAuthorizationRule() {
61 * org.wamblee.security.authorization.UrlAuthorizationRule#getPath(java.
65 protected String getResourcePath(Object aResource) {
66 return ((TestResource) aResource).getPath();
70 public AuthorizationResult isAllowed(Object aResource,
71 Operation aOperation, String aUser) {
72 AuthorizationResult result = super.isAllowed(aResource, aOperation,
75 if (result.equals(GRANTED) || result.equals(DENIED)) {
82 public int getMatchCount() {