org.jboss.web
Class AbstractWebDeployer

java.lang.Object
  extended byorg.jboss.web.AbstractWebDeployer
Direct Known Subclasses:
TomcatDeployer (src)

public abstract class AbstractWebDeployer
extends java.lang.Object

A template pattern class for web deployer integration into JBoss. This class should be subclasses by war deployers providers wishing to integrate into a JBoss server. It provides support for mapping the following web-app.xml/jboss-web.xml elements into the JBoss server JNDI namespace: - env-entry - resource-ref - resource-env-ref - ejb-ref - ejb-local-ref - security-domain Subclasses need to implement the performDeploy() and performUndeploy() methods to perform the container specific steps and return the web application info required by the AbstractWebContainer class. Integration with the JBossSX security framework is based on the establishment of a java:comp/env/security context as described in the linkSecurityDomain comments. The security context provides access to the JBossSX security mgr interface implementations for use by subclass request interceptors. A outline of the steps for authenticating a user is: // Get the username & password from the request context... String username = f(request); String password = f(request); // Get the JBoss security manager from the ENC context InitialContext iniCtx = new InitialContext(); SecurityManager securityMgr = (SecurityManager) iniCtx.lookup("java:comp/env/security/securityMgr"); SimplePrincipal principal = new SimplePrincipal(username); if( securityMgr.isValid(principal, password) ) { // Indicate the user is allowed access to the web content... // Propagate the user info to JBoss for any calls into made by the servlet SecurityAssociation.setPrincipal(principal); SecurityAssociation.setCredential(password.toCharArray()); } else { // Deny access... } An outline of the steps for authorizing the user is: // Get the username & required roles from the request context... String username = f(request); String[] roles = f(request); // Get the JBoss security manager from the ENC context InitialContext iniCtx = new InitialContext(); RealmMapping securityMgr = (RealmMapping) iniCtx.lookup("java:comp/env/security/realmMapping"); SimplePrincipal principal = new SimplePrincipal(username); Set requiredRoles = new HashSet(Arrays.asList(roles)); if( securityMgr.doesUserHaveRole(principal, requiredRoles) ) { // Indicate the user has the required roles for the web content... } else { // Deny access... } The one thing to be aware of is the relationship between the thread context class loader and the JNDI ENC context. Any method that attempts to access the JNDI ENC context must have the ClassLoader in the WebApplication returned from the performDeploy as its thread context ClassLoader or else the lookup for java:comp/env will fail with a name not found exception, or worse, it will receive some other web application ENC context. If your adapting a web container that is trying be compatible with both 1.1 and 1.2 Java VMs this is something you need to pay special attention to. For example, I have seen problems a request interceptor that was handling the authentication/authorization callouts in tomcat3.2.1 not having the same thread context ClassLoader as was used to dispatch the http service request.

See Also:
#performDeploy(WebApplication webApp, String warUrl, WebDescriptorParser webAppParser), performUndeploy(String, WebApplication), parseWebAppDescriptors(DeploymentInfo,ClassLoader, WebMetaData), linkSecurityDomain(String, Context), org.jboss.security.RealmMapping;, org.jboss.security.SimplePrincipal;, org.jboss.security.SecurityAssociation;

Field Summary
protected  java.lang.String defaultSecurityDomain
          The default security-domain name to use
static java.lang.String ERROR
           
protected  boolean java2ClassLoadingCompliance
          The parent class loader first model flag
protected  boolean lenientEjbLink
          If true, ejb-links that don't resolve don't cause an error (fallback to jndi-name)
protected  Logger (src) log
           
protected  MBeanServer (src) server
           
protected  boolean unpackWars
          A flag indicating if war archives should be unpacked
 
Constructor Summary
AbstractWebDeployer()
           
 
Method Summary
protected  void addEnvEntries(java.util.Iterator envEntries, javax.naming.Context envCtx)
           
protected  void createPermissions(WebMetaData (src)  metaData, PolicyConfiguration (src)  pc)
          Create the JACC permission based on the security constraints obtained from the web.xml metadata.
 java.lang.String[] getCompileClasspath(java.lang.ClassLoader loader)
          A utility method that walks up the ClassLoader chain starting at the given loader and queries each ClassLoader for a 'URL[] getURLs()' method from which a complete classpath of URL strings is built.
 java.lang.String getDefaultSecurityDomain()
          Get the default security domain implementation to use if a war does not declare a security-domain.
 boolean getJava2ClassLoadingCompliance()
          Get the flag indicating if the normal Java2 parent first class loading model should be used over the servlet 2.3 web container first model.
 boolean getLenientEjbLink()
          Get the flag indicating if ejb-link errors should be ignored in favour of trying the jndi-name in jboss-web.xml
 MBeanServer (src) getServer()
           
 java.lang.String[] getStandardCompileClasspath(java.lang.ClassLoader loader)
          A utility method that searches the given loader for the resources: "javax/servlet/resources/web-app_2_3.dtd", "org/apache/jasper/resources/jsp12.dtd", and "javax/ejb/EJBHome.class" and returns an array of URL strings.
 boolean getUnpackWars()
          Set the flag indicating if war archives should be unpacked.
abstract  void init(java.lang.Object containerConfig)
           
protected  void linkEjbLocalRefs(java.util.Iterator ejbRefs, javax.naming.Context envCtx, DeploymentInfo (src)  di)
           
protected  void linkEjbRefs(java.util.Iterator ejbRefs, javax.naming.Context envCtx, DeploymentInfo (src)  di)
           
protected  void linkMessageDestinationRefs(WebMetaData (src)  metaData, javax.naming.Context envCtx, DeploymentInfo (src)  di)
           
protected  void linkResourceEnvRefs(java.util.Iterator resourceEnvRefs, javax.naming.Context envCtx)
           
protected  void linkResourceRefs(java.util.Iterator resourceRefs, javax.naming.Context envCtx)
           
protected  void linkSecurityDomain(java.lang.String securityDomain, javax.naming.Context envCtx)
          This creates a java:comp/env/security context that contains a securityMgr binding pointing to an AuthenticationManager implementation and a realmMapping binding pointing to a RealmMapping implementation.
protected  void parseWebAppDescriptors(DeploymentInfo (src)  di, java.lang.ClassLoader loader, WebMetaData (src)  metaData)
          This method is invoked from within subclass performDeploy() method implementations when they invoke WebDescriptorParser.parseWebAppDescriptors().
protected abstract  void performDeploy(WebApplication (src)  webApp, java.lang.String warUrl, AbstractWebContainer.WebDescriptorParser (src)  webAppParser)
          This method is called by the deploy() method template and must be overriden by subclasses to perform the web container specific deployment steps.
protected abstract  void performUndeploy(java.lang.String warUrl, WebApplication (src)  webApp)
          Called as part of the undeploy() method template to ask the subclass for perform the web container specific undeployment steps.
 void setDefaultSecurityDomain(java.lang.String defaultSecurityDomain)
          Set the default security domain implementation to use if a war does not declare a security-domain.
 void setJava2ClassLoadingCompliance(boolean flag)
          Set the flag indicating if the normal Java2 parent first class loading model should be used over the servlet 2.3 web container first model.
 void setLenientEjbLink(boolean flag)
          Set the flag indicating if ejb-link errors should be ignored in favour of trying the jndi-name in jboss-web.xml
 void setServer(MBeanServer (src)  server)
           
 void setUnpackWars(boolean flag)
          Get the flag indicating if war archives should be unpacked.
 WebApplication (src) start(DeploymentInfo (src)  di)
          A template pattern implementation of the deploy() method.
 void stop(DeploymentInfo (src)  di)
          A template pattern implementation of the undeploy() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR

public static final java.lang.String ERROR
See Also:
Constant Field Values (src)

log

protected Logger (src)  log

server

protected MBeanServer (src)  server

java2ClassLoadingCompliance

protected boolean java2ClassLoadingCompliance
The parent class loader first model flag


unpackWars

protected boolean unpackWars
A flag indicating if war archives should be unpacked


lenientEjbLink

protected boolean lenientEjbLink
If true, ejb-links that don't resolve don't cause an error (fallback to jndi-name)


defaultSecurityDomain

protected java.lang.String defaultSecurityDomain
The default security-domain name to use

Constructor Detail

AbstractWebDeployer

public AbstractWebDeployer()
Method Detail

init

public abstract void init(java.lang.Object containerConfig)
                   throws java.lang.Exception
Throws:
java.lang.Exception

getServer

public MBeanServer (src)  getServer()

setServer

public void setServer(MBeanServer (src)  server)

getJava2ClassLoadingCompliance

public boolean getJava2ClassLoadingCompliance()
Get the flag indicating if the normal Java2 parent first class loading model should be used over the servlet 2.3 web container first model.

Returns:
true for parent first, false for the servlet 2.3 model

setJava2ClassLoadingCompliance

public void setJava2ClassLoadingCompliance(boolean flag)
Set the flag indicating if the normal Java2 parent first class loading model should be used over the servlet 2.3 web container first model.

Parameters:
flag - true for parent first, false for the servlet 2.3 model

getUnpackWars

public boolean getUnpackWars()
Set the flag indicating if war archives should be unpacked. This may need to be set to false as long extraction paths under deploy can show up as deployment failures on some platforms.

Returns:
true is war archives should be unpacked

setUnpackWars

public void setUnpackWars(boolean flag)
Get the flag indicating if war archives should be unpacked. This may need to be set to false as long extraction paths under deploy can show up as deployment failures on some platforms.

Parameters:
flag - , true is war archives should be unpacked

getLenientEjbLink

public boolean getLenientEjbLink()
Get the flag indicating if ejb-link errors should be ignored in favour of trying the jndi-name in jboss-web.xml

Returns:
a boolean value

setLenientEjbLink

public void setLenientEjbLink(boolean flag)
Set the flag indicating if ejb-link errors should be ignored in favour of trying the jndi-name in jboss-web.xml


getDefaultSecurityDomain

public java.lang.String getDefaultSecurityDomain()
Get the default security domain implementation to use if a war does not declare a security-domain.

Returns:
jndi name of the security domain binding to use.

setDefaultSecurityDomain

public void setDefaultSecurityDomain(java.lang.String defaultSecurityDomain)
Set the default security domain implementation to use if a war does not declare a security-domain.

Parameters:
defaultSecurityDomain - - jndi name of the security domain binding to use.

start

public WebApplication (src)  start(DeploymentInfo (src)  di)
                     throws DeploymentException (src) 
A template pattern implementation of the deploy() method. This method calls the performDeploy() method to perform the container specific deployment steps and registers the returned WebApplication in the deployment map. The steps performed are: ClassLoader appClassLoader = thread.getContextClassLoader(); URLClassLoader warLoader = URLClassLoader.newInstance(empty, appClassLoader); thread.setContextClassLoader(warLoader); WebDescriptorParser webAppParser = ...; WebMetaData metaData = di.metaData; // Create JACC permissions, contextID, etc. ... WebApplication warInfo = new WebApplication(metaData); performDeploy(warInfo, warUrl, webAppParser); deploymentMap.put(warUrl, warInfo); thread.setContextClassLoader(appClassLoader); The subclass performDeploy() implementation needs to invoke webAppParser.parseWebAppDescriptors(loader, warInfo) to have the JNDI java:comp/env namespace setup before any web app component can access this namespace. Also, an MBean for each servlet deployed should be created and its JMX ObjectName placed into the DeploymentInfo.mbeans list so that the JSR77 layer can create the approriate model view. The servlet MBean needs to provide access to the min, max and total time in milliseconds. Expose this information via MinServiceTime, MaxServiceTime and TotalServiceTime attributes to integrate seemlessly with the JSR77 factory layer.

Parameters:
di - The deployment info that contains the context-root element value from the J2EE application/module/web application.xml descriptor. This may be null if war was is not being deployed as part of an enterprise application. It also contains the URL of the web application war.
Throws:
DeploymentException (src)

performDeploy

protected abstract void performDeploy(WebApplication (src)  webApp,
                                      java.lang.String warUrl,
                                      AbstractWebContainer.WebDescriptorParser (src)  webAppParser)
                               throws java.lang.Exception
This method is called by the deploy() method template and must be overriden by subclasses to perform the web container specific deployment steps.

Parameters:
webApp - The web application information context. This contains the metadata such as the context-root element value from the J2EE application/module/web application.xml descriptor and virtual-host.
warUrl - The string for the URL of the web application war.
webAppParser - The callback interface the web container should use to setup the web app JNDI environment for use by the web app components. This needs to be invoked after the web app class loader is known, but before and web app components attempt to access the java:comp/env JNDI namespace.
Throws:
java.lang.Exception

stop

public void stop(DeploymentInfo (src)  di)
          throws DeploymentException (src) 
A template pattern implementation of the undeploy() method. This method calls the performUndeploy() method to perform the container specific undeployment steps and unregisters the the warUrl from the deployment map.

Throws:
DeploymentException (src)

performUndeploy

protected abstract void performUndeploy(java.lang.String warUrl,
                                        WebApplication (src)  webApp)
                                 throws java.lang.Exception
Called as part of the undeploy() method template to ask the subclass for perform the web container specific undeployment steps.

Throws:
java.lang.Exception

parseWebAppDescriptors

protected void parseWebAppDescriptors(DeploymentInfo (src)  di,
                                      java.lang.ClassLoader loader,
                                      WebMetaData (src)  metaData)
                               throws java.lang.Exception
This method is invoked from within subclass performDeploy() method implementations when they invoke WebDescriptorParser.parseWebAppDescriptors().

Parameters:
loader - the ClassLoader for the web application. May not be null.
metaData - the WebMetaData from the WebApplication object passed to the performDeploy method.
Throws:
java.lang.Exception

addEnvEntries

protected void addEnvEntries(java.util.Iterator envEntries,
                             javax.naming.Context envCtx)
                      throws java.lang.ClassNotFoundException,
                             javax.naming.NamingException
Throws:
java.lang.ClassNotFoundException
javax.naming.NamingException

linkResourceEnvRefs

protected void linkResourceEnvRefs(java.util.Iterator resourceEnvRefs,
                                   javax.naming.Context envCtx)
                            throws javax.naming.NamingException
Throws:
javax.naming.NamingException

linkResourceRefs

protected void linkResourceRefs(java.util.Iterator resourceRefs,
                                javax.naming.Context envCtx)
                         throws javax.naming.NamingException
Throws:
javax.naming.NamingException

linkMessageDestinationRefs

protected void linkMessageDestinationRefs(WebMetaData (src)  metaData,
                                          javax.naming.Context envCtx,
                                          DeploymentInfo (src)  di)
                                   throws javax.naming.NamingException,
                                          DeploymentException (src) 
Throws:
javax.naming.NamingException
DeploymentException (src)

linkEjbRefs

protected void linkEjbRefs(java.util.Iterator ejbRefs,
                           javax.naming.Context envCtx,
                           DeploymentInfo (src)  di)
                    throws javax.naming.NamingException
Throws:
javax.naming.NamingException

linkEjbLocalRefs

protected void linkEjbLocalRefs(java.util.Iterator ejbRefs,
                                javax.naming.Context envCtx,
                                DeploymentInfo (src)  di)
                         throws javax.naming.NamingException
Throws:
javax.naming.NamingException

linkSecurityDomain

protected void linkSecurityDomain(java.lang.String securityDomain,
                                  javax.naming.Context envCtx)
                           throws javax.naming.NamingException
This creates a java:comp/env/security context that contains a securityMgr binding pointing to an AuthenticationManager implementation and a realmMapping binding pointing to a RealmMapping implementation. If the jboss-web.xml descriptor contained a security-domain element then the bindings are LinkRefs to the jndi name specified by the security-domain element. If there was no security-domain element then the bindings are to NullSecurityManager instance which simply allows all access.

Throws:
javax.naming.NamingException

getStandardCompileClasspath

public java.lang.String[] getStandardCompileClasspath(java.lang.ClassLoader loader)
A utility method that searches the given loader for the resources: "javax/servlet/resources/web-app_2_3.dtd", "org/apache/jasper/resources/jsp12.dtd", and "javax/ejb/EJBHome.class" and returns an array of URL strings. Any jar: urls are reduced to the underlying portion of the 'jar:!/{entry}' construct.


getCompileClasspath

public java.lang.String[] getCompileClasspath(java.lang.ClassLoader loader)
A utility method that walks up the ClassLoader chain starting at the given loader and queries each ClassLoader for a 'URL[] getURLs()' method from which a complete classpath of URL strings is built.


createPermissions

protected void createPermissions(WebMetaData (src)  metaData,
                                 PolicyConfiguration (src)  pc)
                          throws PolicyContextException (src) 
Create the JACC permission based on the security constraints obtained from the web.xml metadata.

Parameters:
metaData -
pc -
Throws:
PolicyContextException (src)