001: //========================================================================
002: //$Id: JBossWebXmlConfiguration.java 1241 2006-11-17 19:21:19Z janb $
003: //Copyright 2006 Mort Bay Consulting Pty. Ltd.
004: //------------------------------------------------------------------------
005: //Licensed under the Apache License, Version 2.0 (the "License");
006: //you may not use this file except in compliance with the License.
007: //You may obtain a copy of the License at
008: //http://www.apache.org/licenses/LICENSE-2.0
009: //Unless required by applicable law or agreed to in writing, software
010: //distributed under the License is distributed on an "AS IS" BASIS,
011: //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: //See the License for the specific language governing permissions and
013: //limitations under the License.
014: //========================================================================
015:
016: package org.jboss.jetty;
017:
018: import org.jboss.jetty.security.JBossUserRealm;
019: import org.jboss.logging.Logger;
020: import org.jboss.metadata.WebMetaData;
021: import org.mortbay.jetty.security.UserRealm;
022: import org.mortbay.jetty.webapp.WebXmlConfiguration;
023: import org.mortbay.xml.XmlParser;
024:
025: /**
026: * JBossWebXmlConfiguration
027: *
028: * Extends the jetty WebXmlConfiguration to provide jboss
029: * handling of various elements in the web.xml
030: */
031: public class JBossWebXmlConfiguration extends WebXmlConfiguration {
032: protected static Logger __log = Logger
033: .getLogger(JBossWebAppContext.class);
034:
035: public JBossWebXmlConfiguration() {
036: super ();
037: }
038:
039: public JBossWebAppContext getJBossWebApplicationContext() {
040: return (JBossWebAppContext) getWebAppContext();
041: }
042:
043: protected void initWebXmlElement(String element,
044: org.mortbay.xml.XmlParser.Node node) throws Exception {
045: //avoid jetty printing a debug message about not implementing these elements
046: //because jboss implements it for us
047: if ("resource-ref".equals(element)
048: || "resource-env-ref".equals(element)
049: || "env-entry".equals(element)
050: || "ejb-ref".equals(element)
051: || "ejb-local-ref".equals(element)
052: || "security-domain".equals(element)) {
053: //ignore
054: }
055: // these are handled by Jetty
056: else
057: super .initWebXmlElement(element, node);
058: }
059:
060: protected void initSessionConfig(XmlParser.Node node) {
061: XmlParser.Node tNode = node.get("session-timeout");
062: if (tNode != null) {
063: getJBossWebApplicationContext()._timeOutPresent = true;
064: getJBossWebApplicationContext()._timeOutMinutes = Integer
065: .parseInt(tNode.toString(false, true));
066: }
067: // pass up to our super class so they can do all this again !
068: super .initSessionConfig(node);
069: }
070:
071: protected void initLoginConfig(XmlParser.Node node) {
072: // check if a realm has been explicitly set
073: String realmName = null;
074: UserRealm userRealm = getJBossWebApplicationContext()
075: .getSecurityHandler().getUserRealm();
076: if (userRealm != null)
077: realmName = userRealm.getName();
078:
079: //use a security domain from jboss-web.xml
080: if (null == realmName) {
081: WebMetaData metaData = getJBossWebApplicationContext()._webApp
082: .getMetaData();
083: realmName = metaData.getSecurityDomain();
084: if (null != realmName) {
085: if (realmName.endsWith("/"))
086: realmName = realmName.substring(0, realmName
087: .length());
088: int idx = realmName.lastIndexOf('/');
089: if (idx >= 0)
090: realmName = realmName.substring(idx + 1);
091: }
092: }
093:
094: if (__log.isDebugEnabled())
095: __log.debug("Realm is : " + realmName);
096:
097: if (realmName != null) {
098: JBossUserRealm realm = new JBossUserRealm(realmName,
099: getJBossWebApplicationContext()
100: .getSubjectAttribute());
101: getJBossWebApplicationContext().setRealm(realm);
102: getJBossWebApplicationContext().getSecurityHandler()
103: .setUserRealm(realm);
104: }
105: super.initLoginConfig(node);
106: }
107:
108: }
|