1 16 package org.apache.juddi.auth; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 import org.apache.juddi.util.Config; 21 import org.apache.juddi.util.Loader; 22 23 34 public class AuthenticatorFactory 35 { 36 private static Log log = LogFactory.getLog(AuthenticatorFactory.class); 38 39 private static final String IMPL_KEY = "juddi.auth"; 41 private static final String DEFAULT_IMPL = "org.apache.juddi.auth.DefaultAuthenticator"; 42 43 private static Authenticator auth = null; 45 46 51 public static Authenticator getAuthenticator() 52 { 53 if (auth == null) 54 auth = createAuthenticator(); 55 return auth; 56 } 57 58 63 private static synchronized Authenticator createAuthenticator() 64 { 65 if (auth != null) 66 return auth; 67 68 String className = Config.getStringProperty(IMPL_KEY,DEFAULT_IMPL); 70 71 log.debug("Authenticator Implementation = " + className); 73 74 Class authClass = null; 75 try 76 { 77 authClass = Loader.getClassForName(className); 79 } 80 catch(ClassNotFoundException e) 81 { 82 log.error("The specified Authenticator class '" + className + 83 "' was not found in classpath."); 84 log.error(e); 85 } 86 87 try 88 { 89 auth = (Authenticator)authClass.newInstance(); 91 } 92 catch(Exception e) 93 { 94 log.error("Exception while attempting to instantiate the " + 95 "implementation of Authenticator: " + authClass.getName() + 96 "\n" + e.getMessage()); 97 log.error(e); 98 } 99 100 return auth; 101 } 102 103 104 105 106 107 108 109 public static void main(String [] args) 110 throws Exception 111 { 112 Authenticator auth = AuthenticatorFactory.getAuthenticator(); 113 if (auth != null) 114 { 115 System.out.println("Got Authenticator: "+auth.getClass().getName()); 116 117 String userID = auth.authenticate("sviens","password"); 118 119 System.out.println("The id "+userID+" was successfully authenticated."); 120 } 121 else 122 System.out.println("Sorry: getAuthenticator returned 'null'."); 123 } 124 } | Popular Tags |