KickJava   Java API By Example, From Geeks To Geeks.

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


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.Configuration;
19 import org.apache.avalon.framework.configuration.ConfigurationException;
20 import org.apache.avalon.framework.configuration.Configurable;
21 import org.apache.avalon.framework.service.ServiceManager;
22 import org.apache.avalon.framework.service.ServiceException;
23 import org.outerj.daisy.authentication.*;
24
25 /**
26  * Constructs and registers NtlmAuthenticationSchemes with the UserAuthenticator.
27  *
28  * @avalon.component version="1.0" name="ntlm-authentication-scheme" lifestyle="singleton"
29  */

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

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