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: * Returns a new run-as identity if configuration attribute RUN_AS is found. The new identity is simply an empty
22: * {@link MockRunAsAuthenticationToken}.
23: *
24: * @author Ben Alex
25: * @version $Id: MockRunAsManager.java 1496 2006-05-23 13:38:33Z benalex $
26: */
27: public class MockRunAsManager implements RunAsManager {
28: //~ Methods ========================================================================================================
29:
30: public Authentication buildRunAs(Authentication authentication,
31: Object object, ConfigAttributeDefinition config) {
32: Iterator iter = config.getConfigAttributes();
33:
34: while (iter.hasNext()) {
35: ConfigAttribute attr = (ConfigAttribute) iter.next();
36:
37: if (this .supports(attr)) {
38: Authentication response = new MockRunAsAuthenticationToken();
39: response.setAuthenticated(true);
40:
41: return response;
42: }
43: }
44:
45: return null;
46: }
47:
48: public boolean supports(ConfigAttribute attribute) {
49: if (attribute.getAttribute().startsWith("RUN_AS")) {
50: return true;
51: } else {
52: return false;
53: }
54: }
55:
56: public boolean supports(Class clazz) {
57: return true;
58: }
59: }
|