1 17 package org.apache.ldap.server.authn; 18 19 20 import org.apache.ldap.common.util.StringTools; 21 import org.apache.ldap.server.jndi.EnvKeys; 22 23 import javax.naming.NamingException ; 24 import java.io.FileInputStream ; 25 import java.util.Hashtable ; 26 import java.util.Properties ; 27 28 29 35 public class AuthenticatorConfigBuilder 36 { 37 38 private final static GenericAuthenticatorConfig[] EMPTY = new GenericAuthenticatorConfig[0]; 39 40 41 50 public static GenericAuthenticatorConfig getAuthenticatorConfig( String authenticatorName, Hashtable env ) 51 throws NamingException 52 { 53 final StringBuffer buf = new StringBuffer (); 54 final GenericAuthenticatorConfig config = new GenericAuthenticatorConfig(); 55 56 60 config.setAuthenticatorName( authenticatorName ); 61 62 66 buf.setLength( 0 ); 67 buf.append( EnvKeys.AUTHENTICATOR_CLASS ).append( authenticatorName ); 68 String authenticatorClass = ( String ) env.get( buf.toString() ); 69 70 if ( authenticatorClass != null ) 71 { 72 config.setAuthenticatorClass( authenticatorClass ); 73 } 74 75 79 buf.setLength( 0 ); 80 buf.append( EnvKeys.AUTHENTICATOR_PROPERTIES ).append( authenticatorName ); 81 String propertiesFile = ( String ) env.get( buf.toString() ); 82 83 if ( propertiesFile != null ) 84 { 85 try 86 { 87 Properties properties = config.getProperties(); 88 properties.load( new FileInputStream ( propertiesFile ) ); 89 config.setProperties( properties ); 90 } 91 catch ( Exception e ) 92 { 93 throw new NamingException ( e.getMessage() ); 94 } 95 } 96 97 return config; 98 } 99 100 101 109 public static GenericAuthenticatorConfig[] getAuthenticatorConfigs( Hashtable env ) 110 throws NamingException 111 { 112 String idList = ( String ) env.get( EnvKeys.AUTHENTICATORS ); 113 114 if ( idList == null || idList.trim().length() == 0 ) 116 { 117 return EMPTY; 118 } 119 120 idList = StringTools.deepTrim( idList ); 121 final String [] ids = idList.split( " " ); 122 final GenericAuthenticatorConfig[] configs = new GenericAuthenticatorConfig[ids.length]; 123 for ( int ii = 0; ii < configs.length; ii++ ) 124 { 125 configs[ii] = getAuthenticatorConfig( ids[ii], env ); 126 } 127 128 return configs; 129 } 130 } 131 | Popular Tags |