1/*2 * Copyright 2001-2008 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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 *16 */1718package org.apache.juddi.v3.auth;
1920import org.apache.commons.configuration.ConfigurationException;
21import org.apache.commons.logging.Log;
22import org.apache.commons.logging.LogFactory;
23import org.apache.juddi.ClassUtil;
24import org.apache.juddi.config.AppConfig;
25import org.apache.juddi.config.Property;
262728/**29 * @author Steve Viens (sviens@apache.org)30 * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>31 */32publicclassAuthenticatorFactory {
33privatestatic Log log = LogFactory.getLog(AuthenticatorFactory.class);
3435// Default authenticator implementation36privatestaticfinal String DEFAULT_IMPL = "org.apache.juddi.v3.auth.JUDDIAuthenticator";
3738// the shared Authenticator instance39privatestaticAuthenticator auth = null;
404142/**43 * Returns a new instance of a AuthenticatorFactory.44 * 45 * @return Authenticator46 */47publicstaticsynchronizedAuthenticator getAuthenticator() {
48if (auth == null)
49 auth = createAuthenticator();
50return auth;
51 }
5253/**54 * Returns a new instance of a Authenticator.55 * 56 * @return Authenticator57 */58privatestaticsynchronizedAuthenticator createAuthenticator() {
59if (auth != null)
60return auth;
6162 String className = DEFAULT_IMPL;
63try {
64// grab class name of the Authenticator implementation to create65 className = AppConfig.getConfiguration().getString(Property.JUDDI_AUTHENTICATOR, DEFAULT_IMPL);
66 }
67catch(ConfigurationException ce) {
68 log.error("Configuration exception occurred retrieving: " + Property.JUDDI_AUTHENTICATOR);
69 }
7071// write the Authenticator implementation name to the log72 log.debug("Authenticator Implementation = " + className);
7374 Class<?> authClass = null;
75try {
76// Use Loader to locate & load the Authenticator implementation77 authClass = ClassUtil.forName(className, AuthenticatorFactory.class);
78 }
79catch(ClassNotFoundException e) {
80 log.error("The specified Authenticator class '" + className + "' was not found in classpath.");
81 log.error(e);
82 }
8384try {
85if (authClass!=null) {
86// try to instantiate the Authenticator implementation87 auth = (Authenticator)authClass.newInstance();
88 } else {
89 log.error("Could not load " + className + " authClass is null");
90 }
91 }
92catch(Exception e) {
93 log.error("Exception while attempting to instantiate the implementation of Authenticator: " + className + "\n" + e.getMessage());
94 log.error(e);
95 }
9697return auth;
98 }
99 }