01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software
10: * distributed under the License is distributed on an "AS IS" BASIS,
11: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: * See the License for the specific language governing permissions and
13: * limitations under the License.
14: */
15:
16: package org.acegisecurity.vote;
17:
18: import org.acegisecurity.Authentication;
19: import org.acegisecurity.ConfigAttribute;
20: import org.acegisecurity.ConfigAttributeDefinition;
21: import org.springframework.core.Ordered;
22:
23: import java.util.Iterator;
24:
25: /**
26: * Implementation of an {@link AccessDecisionVoter} for unit testing.
27: * <p>
28: * If the {@link ConfigAttribute#getAttribute()} has a value of
29: * <code>DENY_AGAIN_FOR_SURE</code>, the voter will vote to deny access.
30: * </p>
31: * <p>
32: * All comparisons are case sensitive.
33: * </p>
34: *
35: * @author Ben Alex
36: * @version $Id: DenyAgainVoter.java 1922 2007-07-06 13:34:43Z vishalpuri $
37: */
38: public class DenyAgainVoter implements AccessDecisionVoter, Ordered {
39: public static int DEFAULT_ORDER = Ordered.LOWEST_PRECEDENCE;
40:
41: private int order = DEFAULT_ORDER;
42:
43: // ~ Methods
44: // ========================================================================================================
45:
46: public boolean supports(ConfigAttribute attribute) {
47: if ("DENY_AGAIN_FOR_SURE".equals(attribute.getAttribute())) {
48: return true;
49: } else {
50: return false;
51: }
52: }
53:
54: public boolean supports(Class clazz) {
55: return true;
56: }
57:
58: public int vote(Authentication authentication, Object object,
59: ConfigAttributeDefinition config) {
60: Iterator iter = config.getConfigAttributes();
61:
62: while (iter.hasNext()) {
63: ConfigAttribute attribute = (ConfigAttribute) iter.next();
64:
65: if (this .supports(attribute)) {
66: return ACCESS_DENIED;
67: }
68: }
69:
70: return ACCESS_ABSTAIN;
71: }
72:
73: public void setOrder(int order) {
74: this .order = order;
75: }
76:
77: public int getOrder() {
78: return order;
79: }
80:
81: }
|