📄 ch13s16.html
字号:
Object data;
...
// WebApplication property getters/setters...
}</pre></div><div class="calloutlist"><a name="d0e9357"></a><table border="0" summary="Callout list"><tr><td width="5%" valign="top" align="left"><a name="d0e9358"></a><a href="#howto.webcontainer.deploy"><img src="1.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/1.png" alt="1" border="0"></a> </td><td valign="top" align="left"><p>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:
WebApplication warInfo = performDeploy(ctxPath, warUrl);
ClassLoader loader = warInfo.getClassLoader();
Element webApp = warInfo.getWebApp();
Element jbossWeb = warInfo.getJbossWeb();
parseWebAppDescriptors(loader, webApp, jbossWeb);
deploymentMap.put(warUrl, warInfo);
@param ctxPath, 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.
@param warUrl, The string for the URL of the web application war.</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e9361"></a><a href="#howto.webcontainer.performDeploy"><img src="2.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/2.png" alt="2" border="0"></a> </td><td valign="top" align="left"><p>The method is called by the deploy() method and must be overriden by
subclasses to perform the web container specific deployment steps. A WebApplication object must
be returned that contains the web application class loader, web-app.xml web-app document element
and the jboss-web.xml jboss-web document element if a jboss-web.xml existed in the war.
@param ctxPath, 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.
@param warUrl, The string for the URL of the web application war.
@return WebApplication, the web application information required by the
AbstractWebContainer class to setup the JNDI ENC and track the war
deployment status.</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e9364"></a><a href="#howto.webcontainer.undeploy"><img src="3.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/3.png" alt="3" border="0"></a> </td><td valign="top" align="left"><p>A template pattern implementation of the undeploy() method. This method
calls the subclass performUndeploy() method to perform the container specific undeployment steps and unregisters the
the warUrl from the deployment map.</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e9367"></a><a href="#howto.webcontainer.performUndeploy"><img src="4.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/4.png" alt="4" border="0"></a> </td><td valign="top" align="left"><p>performUndeploy</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e9370"></a><a href="#howto.webcontainer.parseWebAppDescriptors"><img src="5.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/5.png" alt="5" border="0"></a> </td><td valign="top" align="left"><p> This method is called as part of the deploy() method template to
parse the web-app.xml and jboss-web.xml deployment descriptors from a
war deployment. The method creates the ENC(java:comp/env) env-entry,
resource-ref, and ejb-ref element values. The creation of the env-entry
values does not require a jboss-web.xml descriptor. The creation of the
resource-ref and ejb-ref elements does require a jboss-web.xml descriptor
for the JNDI name of the deployed resources/EJBs.
Because the ENC context is private to the web application, the web
application class loader is used to identify the ENC. The class loader
is used because each war typically requires a unique class loader to
isolate the web application classes/resources. This means that the
ClassLoader passed to this method must be the thread context ClassLoader
seen by the server/jsp pages during init/destroy/service/etc. method
invocations if these methods interace with the JNDI ENC context.
@param loader, the ClassLoader for the web application. May not be null.
@param webApp, the root element of thw web-app.xml descriptor. May not be null.
@param jbossWeb, the root element of thw jboss-web.xml descriptor. May be null
to indicate that no jboss-web.xml descriptor exists.</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e9373"></a><a href="#howto.webcontainer.addEnvEntries"><img src="6.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/6.png" alt="6" border="0"></a> </td><td valign="top" align="left"><p>The addEnvEntries creates the java:comp/env web container
env-entry bindings that were specified in the web-app.xml descriptor.</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e9376"></a><a href="#howto.webcontainer.linkResourceRefs"><img src="7.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/7.png" alt="7" border="0"></a> </td><td valign="top" align="left"><p>The linkResourceRefs method maps the java:comp/env/xxx web container
JNDI ENC resource elements onto the deployed JNDI names using the mappings specified in the
jboss-web.xml descriptor</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e9379"></a><a href="#howto.webcontainer.linkEjbRefs"><img src="8.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/8.png" alt="8" border="0"></a> </td><td valign="top" align="left"><p>The linkEjbRefs method maps the java:comp/env/ejb web container
JNDI ENC ejb elements onto the deployed JNDI names using the mappings specified in the
jboss-web.xml descriptor.</p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e9382"></a><a href="#howto.webcontainer.linkSecurityDomain"><img src="9.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/9.png" alt="9" border="0"></a> </td><td valign="top" align="left"><p>This creates a java:comp/env/security context that contains a
securityMgr binding pointing to an EJBSecurityMgr 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.</p></td></tr></table></div></div><div class="section"><a name="howto.webcontainer.Subclassing"></a><div class="titlepage"><div><h3 class="title"><a name="howto.webcontainer.Subclassing"></a>Integrating a Web Container by Subclassing AbstractWebContainer</h3></div></div><p>To integrate your web container into JBoss create a subclass of AbstractWebContainer and implement
the required performDeploy(String, String) and performUndeploy(String) methods. See the performDeploy and performUndeploy
method notes in the preceeding section for details of the method implementations.</p></div><div class="section"><a name="howto.webcontainer.Security"></a><div class="titlepage"><div><h3 class="title"><a name="howto.webcontainer.Security"></a>Delegating Web Container Authentication and Authorization to JBoss</h3></div></div><p>Ideally both web application and ejb authentication and authorization is handled
by the same security code. To enable this for your web container you must hook into the JBoss security
layer. This typically requires a request interceptor that maps from the web container security callouts
to the JBoss security api calls. Integration with the JBossSX security framework is based on the establishment
of a java:comp/env/security context as described in the linkSecurityDomain(String, Context) method comments
in the overview section. 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:<div class="example"><p><a name="d0e9395"></a><b>Example 13.1. Authentication Steps</b></p><pre class="programlisting"> // Get the username and 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();
EJBSecurityManager securityMgr = (EJBSecurityManager) 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...
}</pre></div>An outline of the steps for authorizing a user with the JBossSX api is:<div class="example"><p><a name="d0e9401"></a><b>Example 13.2. Authorization Steps</b></p><pre class="programlisting"> // Get the username and 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...
}</pre></div>
</p></div></div><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="432" height="79"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch13.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch13.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch13s21.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch13s21.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -