1 22 package org.jboss.web.tomcat.security.config; 23 24 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 import java.util.Properties ; 30 import java.util.Set ; 31 32 import javax.naming.InitialContext ; 33 import javax.naming.NamingException ; 34 35 import org.apache.catalina.Authenticator; 36 import org.apache.catalina.startup.ContextConfig; 37 import org.jboss.logging.Logger; 38 39 47 public class JBossContextConfig extends ContextConfig 48 { 49 private static Logger log = Logger.getLogger(JBossContextConfig.class); 50 51 private boolean isTrace = log.isTraceEnabled(); 52 53 56 public JBossContextConfig() 57 { 58 super(); 59 try 60 { 61 Map authMap = this.getAuthenticators(); 62 if(authMap.size() > 0) 63 customAuthenticators = authMap; 64 }catch(Exception e) 65 { 66 log.debug("Failed to customize authenticators::",e); 68 } 69 } 70 71 76 private Map getAuthenticators() throws Exception 77 { 78 Map cmap = new HashMap (); 79 ClassLoader tcl = Thread.currentThread().getContextClassLoader(); 80 81 Properties authProps = this.getAuthenticatorsFromJndi(); 82 if(authProps != null) 83 { 84 Set keys = authProps.keySet(); 85 Iterator iter = keys != null ? keys.iterator() : null; 86 while(iter != null && iter.hasNext()) 87 { 88 String key = (String )iter.next(); 89 String authenticatorStr = (String )authProps.get(key); 90 Class authClass = tcl.loadClass(authenticatorStr); 91 cmap.put(key, (Authenticator)authClass.newInstance()); 92 } 93 } 94 if(isTrace) 95 log.trace("Authenticators plugged in::"+cmap); 96 return cmap; 97 } 98 99 107 private Properties getAuthenticatorsFromJndi() throws NamingException 108 { 109 return (Properties )(new InitialContext ()).lookup("TomcatAuthenticators"); 110 } 111 } 112 | Popular Tags |