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:
22: /**
23: * Indicates a class is responsible for voting on authorization decisions.
24: *
25: * <p>
26: * The coordination of voting (ie polling <code>AccessDecisionVoter</code>s,
27: * tallying their responses, and making the final authorization decision) is
28: * performed by an {@link org.acegisecurity.AccessDecisionManager}.
29: * </p>
30: *
31: * @author Ben Alex
32: * @version $Id: AccessDecisionVoter.java 1784 2007-02-24 21:00:24Z luke_t $
33: */
34: public interface AccessDecisionVoter {
35: //~ Static fields/initializers =====================================================================================
36:
37: int ACCESS_GRANTED = 1;
38: int ACCESS_ABSTAIN = 0;
39: int ACCESS_DENIED = -1;
40:
41: //~ Methods ========================================================================================================
42:
43: /**
44: * Indicates whether this <code>AccessDecisionVoter</code> is able to vote on the passed
45: * <code>ConfigAttribute</code>.<p>This allows the <code>AbstractSecurityInterceptor</code> to check every
46: * configuration attribute can be consumed by the configured <code>AccessDecisionManager</code> and/or
47: * <code>RunAsManager</code> and/or <code>AfterInvocationManager</code>.</p>
48: *
49: * @param attribute a configuration attribute that has been configured against the
50: * <code>AbstractSecurityInterceptor</code>
51: *
52: * @return true if this <code>AccessDecisionVoter</code> can support the passed configuration attribute
53: */
54: boolean supports(ConfigAttribute attribute);
55:
56: /**
57: * Indicates whether the <code>AccessDecisionVoter</code> implementation is able to provide access control
58: * votes for the indicated secured object type.
59: *
60: * @param clazz the class that is being queried
61: *
62: * @return true if the implementation can process the indicated class
63: */
64: boolean supports(Class clazz);
65:
66: /**
67: * Indicates whether or not access is granted.
68: * <p>The decision must be affirmative (<code>ACCESS_GRANTED</code>), negative (<code>ACCESS_DENIED</code>)
69: * or the <code>AccessDecisionVoter</code> can abstain (<code>ACCESS_ABSTAIN</code>) from voting.
70: * Under no circumstances should implementing classes return any other value. If a weighting of results is desired,
71: * this should be handled in a custom {@link org.acegisecurity.AccessDecisionManager} instead.
72: * </p>
73: * <p>Unless an <code>AccessDecisionVoter</code> is specifically intended to vote on an access control
74: * decision due to a passed method invocation or configuration attribute parameter, it must return
75: * <code>ACCESS_ABSTAIN</code>. This prevents the coordinating <code>AccessDecisionManager</code> from counting
76: * votes from those <code>AccessDecisionVoter</code>s without a legitimate interest in the access control
77: * decision.
78: * </p>
79: * <p>Whilst the method invocation is passed as a parameter to maximise flexibility in making access
80: * control decisions, implementing classes must never modify the behaviour of the method invocation (such as
81: * calling <Code>MethodInvocation.proceed()</code>).</p>
82: *
83: * @param authentication the caller invoking the method
84: * @param object the secured object
85: * @param config the configuration attributes associated with the method being invoked
86: *
87: * @return either {@link #ACCESS_GRANTED}, {@link #ACCESS_ABSTAIN} or {@link #ACCESS_DENIED}
88: */
89: int vote(Authentication authentication, Object object,
90: ConfigAttributeDefinition config);
91: }
|