KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > ac > impl > ConfigurableAccessControllerResolver


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.lenya.ac.impl;
19
20 import org.apache.avalon.framework.configuration.Configurable;
21 import org.apache.avalon.framework.configuration.Configuration;
22 import org.apache.avalon.framework.configuration.ConfigurationException;
23 import org.apache.lenya.ac.AccessControlException;
24 import org.apache.lenya.ac.AccessController;
25
26 /**
27  * Configurable access controller resolver.
28  * @version $Id: ConfigurableAccessControllerResolver.java 43241 2004-08-16 16:36:57Z andreas $
29  */

30 public class ConfigurableAccessControllerResolver
31     extends AbstractAccessControllerResolver
32     implements Configurable {
33
34     /**
35      * @see org.apache.lenya.ac.impl.AbstractAccessControllerResolver#doResolveAccessController(java.lang.String)
36      */

37     public AccessController doResolveAccessController(String JavaDoc webappUrl)
38         throws AccessControlException {
39         AccessController accessController = null;
40
41         try {
42             accessController =
43                 (AccessController) getManager().lookup(
44                     AccessController.ROLE + "/" + accessControllerType);
45
46             if (accessController instanceof Configurable) {
47                 ((Configurable) accessController).configure(accessControllerConfiguration);
48             }
49
50         } catch (Exception JavaDoc e) {
51             throw new AccessControlException(e);
52         }
53
54         return accessController;
55     }
56
57     protected static final String JavaDoc ACCESS_CONTROLLER_ELEMENT = "access-controller";
58     protected static final String JavaDoc TYPE_ATTRIBUTE = "type";
59     private String JavaDoc accessControllerType;
60
61     private Configuration accessControllerConfiguration;
62
63     /**
64      * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
65      */

66     public void configure(Configuration configuration) throws ConfigurationException {
67         accessControllerConfiguration = configuration.getChild(ACCESS_CONTROLLER_ELEMENT);
68         accessControllerType = accessControllerConfiguration.getAttribute(TYPE_ATTRIBUTE);
69     }
70
71 }
72
Popular Tags