01: /*
02: * $Id: CompoundAuthorizationStrategy.java,v 1.6 2006/01/14 22:45:04
03: * jonathanlocke Exp $ $Revision: 459200 $ $Date: 2006-02-12 08:51:40 +0100 (Sun, 12 Feb 2006) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.authorization.strategies;
19:
20: import java.util.ArrayList;
21:
22: import wicket.Component;
23: import wicket.authorization.Action;
24: import wicket.authorization.IAuthorizationStrategy;
25:
26: /**
27: * Compound implementation of the IAuthorizationStrategy that lets you chain two
28: * or more strategies together.
29: *
30: * @author ivaynberg
31: */
32: public class CompoundAuthorizationStrategy implements
33: IAuthorizationStrategy {
34: /** List of strategies to consult */
35: private ArrayList strategies = new ArrayList();
36:
37: /**
38: * Adds a strategy to the chain
39: *
40: * @param strategy
41: * Strategy to add
42: */
43: public final void add(IAuthorizationStrategy strategy) {
44: if (strategy == null) {
45: throw new IllegalArgumentException(
46: "Strategy argument cannot be null");
47: }
48: strategies.add(strategy);
49: }
50:
51: /**
52: * @see wicket.authorization.IAuthorizationStrategy#isInstantiationAuthorized(java.lang.Class)
53: */
54: public final boolean isInstantiationAuthorized(Class componentClass) {
55: int size = strategies.size();
56: for (int i = 0; i < size; i++) {
57: IAuthorizationStrategy strategy = (IAuthorizationStrategy) strategies
58: .get(i);
59: if (!strategy.isInstantiationAuthorized(componentClass)) {
60: return false;
61: }
62: }
63: return true;
64: }
65:
66: /**
67: * @see wicket.authorization.IAuthorizationStrategy#isActionAuthorized(wicket.Component,
68: * wicket.authorization.Action)
69: */
70: public final boolean isActionAuthorized(Component component,
71: Action action) {
72: int size = strategies.size();
73: for (int i = 0; i < size; i++) {
74: IAuthorizationStrategy strategy = (IAuthorizationStrategy) strategies
75: .get(i);
76: if (!strategy.isActionAuthorized(component, action)) {
77: return false;
78: }
79: }
80: return true;
81: }
82: }
|