KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > authentication > impl > LdapAuthenticationFactory


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
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 package org.outerj.daisy.authentication.impl;
17
18 import org.apache.avalon.framework.configuration.Configurable;
19 import org.apache.avalon.framework.configuration.Configuration;
20 import org.apache.avalon.framework.configuration.ConfigurationException;
21 import org.apache.avalon.framework.service.ServiceManager;
22 import org.apache.avalon.framework.service.ServiceException;
23 import org.outerj.daisy.authentication.*;
24
25 import java.util.*;
26
27 /**
28  * Constructs and registers LdapAuthenticationSchemes with the UserAuthenticator.
29  *
30  * @avalon.component version="1.0" name="ldap-authentication-scheme" lifestyle="singleton"
31  */

32 public class LdapAuthenticationFactory extends AbstractAuthenticationFactory implements Configurable {
33     /**
34      * @avalon.dependency key="auth-scheme-registrar" type="org.outerj.daisy.authentication.AuthenticationSchemeRegistrar"
35      */

36     public void service(ServiceManager serviceManager) throws ServiceException {
37         super.service(serviceManager);
38     }
39     
40     public void configure(Configuration configuration) throws ConfigurationException {
41         Configuration[] schemeConfs = configuration.getChildren("scheme");
42         for (int i = 0; i < schemeConfs.length; i++) {
43             String JavaDoc name = schemeConfs[i].getAttribute("name");
44             String JavaDoc description = schemeConfs[i].getAttribute("description");
45             Configuration[] properties = schemeConfs[i].getChild("environment").getChildren("property");
46             Map templateEnvironment = new HashMap();
47             for (int k = 0; k < properties.length; k++) {
48                 templateEnvironment.put(properties[k].getAttribute("name"), properties[k].getAttribute("value"));
49             }
50             UserCreator userCreator = UserCreatorFactory.createUser(schemeConfs[i], name);
51             AuthenticationScheme scheme = new LdapAuthenticationScheme(name, description, templateEnvironment, userCreator, logger);
52             Configuration cacheConf = schemeConfs[i].getChild("cache");
53             if (cacheConf.getAttributeAsBoolean("enabled")) {
54                 int maxCacheSize = cacheConf.getAttributeAsInteger("maxCacheSize", 3000);
55                 long maxCacheDuration = cacheConf.getAttributeAsLong("maxCacheDuration", 30 * 60 * 1000); // default: half an hour
56
scheme = new CachingAuthenticationScheme(scheme, maxCacheDuration, maxCacheSize);
57             }
58             schemes.add(scheme);
59         }
60     }
61 }
62
Popular Tags