01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.lenya.ac.impl;
20:
21: import org.apache.avalon.framework.configuration.Configurable;
22: import org.apache.avalon.framework.configuration.Configuration;
23: import org.apache.avalon.framework.configuration.ConfigurationException;
24: import org.apache.lenya.ac.AccessControlException;
25: import org.apache.lenya.ac.AccessController;
26:
27: /**
28: * Configurable access controller resolver.
29: * @version $Id: ConfigurableAccessControllerResolver.java 473861 2006-11-12 03:51:14Z gregor $
30: */
31: public class ConfigurableAccessControllerResolver extends
32: AbstractAccessControllerResolver implements Configurable {
33:
34: /**
35: * @see org.apache.lenya.ac.impl.AbstractAccessControllerResolver#doResolveAccessController(java.lang.String)
36: */
37: public AccessController doResolveAccessController(String webappUrl)
38: throws AccessControlException {
39: AccessController accessController = null;
40:
41: try {
42: accessController = (AccessController) getManager().lookup(
43: AccessController.ROLE + "/"
44: + this .accessControllerType);
45:
46: if (accessController instanceof Configurable) {
47: ((Configurable) accessController)
48: .configure(this .accessControllerConfiguration);
49: }
50:
51: } catch (Exception e) {
52: throw new AccessControlException(e);
53: }
54:
55: return accessController;
56: }
57:
58: protected static final String ACCESS_CONTROLLER_ELEMENT = "access-controller";
59: protected static final String TYPE_ATTRIBUTE = "type";
60: private String accessControllerType;
61:
62: private Configuration accessControllerConfiguration;
63:
64: /**
65: * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
66: */
67: public void configure(Configuration configuration)
68: throws ConfigurationException {
69: this.accessControllerConfiguration = configuration
70: .getChild(ACCESS_CONTROLLER_ELEMENT);
71: this.accessControllerType = this.accessControllerConfiguration
72: .getAttribute(TYPE_ATTRIBUTE);
73: }
74:
75: }
|