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;
17:
18: import java.util.Iterator;
19:
20: /**
21: * Grants access if the user holds any of the authorities listed in the configuration attributes starting with
22: * "MOCK_".
23: *
24: * @author Ben Alex
25: * @version $Id: MockAccessDecisionManager.java 1496 2006-05-23 13:38:33Z benalex $
26: */
27: public class MockAccessDecisionManager implements AccessDecisionManager {
28: //~ Methods ========================================================================================================
29:
30: public void decide(Authentication authentication, Object object,
31: ConfigAttributeDefinition config)
32: throws AccessDeniedException {
33: Iterator iter = config.getConfigAttributes();
34:
35: while (iter.hasNext()) {
36: ConfigAttribute attr = (ConfigAttribute) iter.next();
37:
38: if (this .supports(attr)) {
39: for (int i = 0; i < authentication.getAuthorities().length; i++) {
40: if (attr.getAttribute().equals(
41: authentication.getAuthorities()[i]
42: .getAuthority())) {
43: return;
44: }
45: }
46: }
47: }
48:
49: throw new AccessDeniedException(
50: "Didn't hold required authority");
51: }
52:
53: public boolean supports(ConfigAttribute attribute) {
54: if (attribute.getAttribute().startsWith("MOCK_")) {
55: return true;
56: } else {
57: return false;
58: }
59: }
60:
61: public boolean supports(Class clazz) {
62: return true;
63: }
64: }
|