1 23 24 package com.sun.enterprise.web; 25 26 import java.io.File ; 27 import java.io.FileInputStream ; 28 import java.io.InputStream ; 29 import java.io.IOException ; 30 import java.util.Properties ; 31 import org.apache.catalina.Authenticator; 32 33 import org.apache.catalina.Container; 34 import org.apache.catalina.Context; 35 import org.apache.catalina.Lifecycle; 36 import org.apache.catalina.LifecycleEvent; 37 import org.apache.catalina.LifecycleListener; 38 import org.apache.catalina.Pipeline; 39 import org.apache.catalina.Realm; 40 import org.apache.catalina.Valve; 41 import org.apache.catalina.core.ContainerBase; 42 import org.apache.catalina.deploy.LoginConfig; 43 import org.apache.catalina.deploy.SecurityConstraint; 44 import org.apache.catalina.startup.ContextConfig; 45 import org.apache.catalina.core.StandardEngine; 46 import com.sun.org.apache.commons.digester.Digester; 47 import org.xml.sax.InputSource ; 48 import org.xml.sax.SAXParseException ; 49 50 import com.sun.enterprise.deployment.WebBundleDescriptor; 51 52 import java.util.logging.Logger ; 53 import java.util.logging.Level ; 54 import com.sun.logging.LogDomains; 55 56 62 63 public class WebModuleContextConfig extends ContextConfig { 64 65 private static Logger logger = LogDomains.getLogger(LogDomains.WEB_LOGGER); 66 67 public final static int CHILDREN = 0; 68 public final static int SERVLET_MAPPINGS = 1; 69 public final static int LOCAL_EJBS = 2; 70 public final static int EJBS = 3; 71 public final static int ENVIRONMENTS = 4; 72 public final static int ERROR_PAGES = 5; 73 public final static int FILTER_DEFS = 6; 74 public final static int FILTER_MAPS = 7; 75 public final static int APPLICATION_LISTENERS = 8; 76 public final static int RESOURCES = 9; 77 public final static int APPLICATION_PARAMETERS = 10; 78 public final static int MESSAGE_DESTINATIONS = 11; 79 public final static int MESSAGE_DESTINATION_REFS = 12; 80 public final static int MIME_MAPPINGS = 13; 81 82 83 86 protected File file; 87 88 89 92 private WebBundleDescriptor webBundleDescriptor; 93 94 95 98 public WebModuleContextConfig(){ 99 } 100 101 102 105 public void setDescriptor(WebBundleDescriptor wbd){ 106 webBundleDescriptor = wbd; 107 } 108 109 110 115 public void lifecycleEvent(LifecycleEvent event) { 116 117 try { 119 context = (Context) event.getLifecycle(); 120 } catch (ClassCastException e) { 121 return; 122 } 123 124 if (event.getType().equals(Lifecycle.START_EVENT)) 127 start(); 128 else if (event.getType().equals(Lifecycle.STOP_EVENT)) 129 stop(); 130 } 131 132 133 136 protected synchronized void start() { 137 138 try{ 139 TomcatDeploymentConfig.configureWebModule((WebModule)context, 140 webBundleDescriptor); 141 } catch (Throwable t){ 142 context.setAvailable(false); 143 144 Object [] objs = {context.getName(), t}; 145 logger.log(Level.SEVERE, 146 "webModuleContextConfig.webModuleDisabled", objs); 147 } 148 149 context.setConfigured(false); 150 authenticatorConfig(); 151 managerConfig(); 152 context.setConfigured(true); 153 154 } 155 156 157 160 protected synchronized void authenticatorConfig() { 161 162 LoginConfig loginConfig = context.getLoginConfig(); 163 if (loginConfig == null) { 164 loginConfig = new LoginConfig("NONE", null, null, null); 165 context.setLoginConfig(loginConfig); 166 } 167 168 if (context instanceof Authenticator) 170 return; 171 if (context instanceof ContainerBase) { 172 Pipeline pipeline = ((ContainerBase) context).getPipeline(); 173 if (pipeline != null) { 174 Valve basic = pipeline.getBasic(); 175 if ((basic != null) && (basic instanceof Authenticator)) 176 return; 177 Valve valves[] = pipeline.getValves(); 178 for (int i = 0; i < valves.length; i++) { 179 if (valves[i] instanceof Authenticator) 180 return; 181 } 182 } 183 } else { 184 return; } 186 187 191 Realm rlm = context.getRealm(); 193 if (rlm == null) { 194 logger.log(Level.SEVERE, "webModuleContextConfig.missingRealm"); 196 ok = false; 197 return; 198 } 199 200 rlm.setRealmName(loginConfig.getRealmName(), 203 loginConfig.getAuthMethod()); 204 205 207 212 Valve authenticator = null; 213 if (customAuthenticators != null) { 214 authenticator = (Valve) 215 customAuthenticators.get(loginConfig.getAuthMethod()); 216 } 217 if (authenticator == null) { 218 if (authenticators == null) { 220 try { 221 InputStream is=this.getClass().getClassLoader().getResourceAsStream("org/apache/catalina/startup/Authenticators.properties"); 222 if( is!=null ) { 223 authenticators = new Properties (); 224 authenticators.load(is); 225 } else { 226 logger.log(Level.SEVERE, "webModuleContextConfig.authenticatorResources"); 227 ok=false; 228 return; 229 } 230 } catch (IOException e) { 231 logger.log(Level.SEVERE, "webModuleContextConfig.authenticatorResources", e); 232 ok = false; 233 return; 234 } 235 } 236 237 String authenticatorName = null; 239 240 String authMethod = loginConfig.getAuthMethod(); 244 if (authMethod == null) { 245 authMethod = "NONE"; 246 } 247 authenticatorName = authenticators.getProperty(authMethod); 248 253 254 if (authenticatorName == null) { 255 logger.log(Level.SEVERE, "webModuleContextConfig.authenticatorMissing", 256 loginConfig.getAuthMethod()); 257 ok = false; 258 return; 259 } 260 261 try { 263 Class authenticatorClass = Class.forName(authenticatorName); 264 authenticator = (Valve) authenticatorClass.newInstance(); 265 } catch (Throwable t) { 266 logger.log(Level.SEVERE, "webModuleContextConfig.authenticatorInstantiate", authenticatorName); 267 logger.log(Level.SEVERE, "webModuleContextConfig.authenticatorInstantiate", t); 268 ok = false; 269 } 270 } 271 272 if (authenticator != null && context instanceof ContainerBase) { 273 Pipeline pipeline = ((ContainerBase) context).getPipeline(); 274 if (pipeline != null) { 275 ((ContainerBase) context).addValve(authenticator); 276 if (logger.isLoggable(Level.FINEST)) { 277 logger.log(Level.FINEST, "webModuleContextConfig.authenticatorConfigured", 278 loginConfig.getAuthMethod()); 279 } 280 } 281 } 282 } 283 284 285 290 protected void defaultConfig() { 291 ; 292 } 293 } 294 | Popular Tags |