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 javax.persistence.DiscriminatorValue;
22 import javax.persistence.Entity;
23 import javax.persistence.Transient;
25 import org.wamblee.usermgt.User;
28 * Test authorization rule that also counts the number of times the rule
31 * @author Erik Brakkee
34 @DiscriminatorValue("TEST")
35 public class TestAuthorizationRule extends UrlAuthorizationRule {
37 * Counts the number of matches.
40 private int matches = 0;
43 * Creates a new TestAuthorizationRule object.
46 public TestAuthorizationRule(AuthorizationResult aResult, String aGroup,
47 String aPath, Class<? extends Operation> aOperation) {
48 super(aResult, new GroupUserCondition(aGroup),
49 new StartsWithPathCondition(aPath), TestResource.class,
50 new IsaOperationCondition(aOperation));
54 * Creates a new TestAuthorizationRule object.
56 protected TestAuthorizationRule() {
64 * org.wamblee.security.authorization.UrlAuthorizationRule#getPath(java.
68 protected String getResourcePath(Object aResource) {
69 return ((TestResource) aResource).getPath();
76 * org.wamblee.security.authorization.UrlAuthorizationRule#isAllowed(java
77 * .lang.Object, org.wamblee.security.authorization.Operation,
78 * org.wamblee.usermgt.UserAccessor)
81 public AuthorizationResult isAllowed(Object aResource,
82 Operation aOperation, User aUser) {
83 AuthorizationResult result = super.isAllowed(aResource, aOperation,
86 if (result.equals(GRANTED) || result.equals(DENIED)) {
93 public int getMatchCount() {