001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/CmsWorkplaceLoginHandler.java,v $
003: * Date : $Date: 2008-02-27 12:05:45 $
004: * Version: $Revision: 1.4 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace;
033:
034: import org.opencms.file.CmsObject;
035: import org.opencms.file.CmsResource;
036: import org.opencms.main.CmsException;
037: import org.opencms.main.CmsResourceInitException;
038: import org.opencms.main.I_CmsResourceInit;
039: import org.opencms.security.CmsOrganizationalUnit;
040:
041: import javax.servlet.http.HttpServletRequest;
042: import javax.servlet.http.HttpServletResponse;
043:
044: /**
045: * Resource init handler that loads the login form with the right parameters.<p>
046: *
047: * The login uri must have following format:<br>
048: * <code>/${CONTEXT}/${SERVLET}/system/login/${OU_PATH}</code><p>
049: *
050: * for example:<br>
051: * <code>/opencms/opencms/system/login/intranet/marketing</code><p>
052: *
053: * @author Michael Moossen
054: *
055: * @version $Revision: 1.4 $
056: *
057: * @since 6.5.6
058: */
059: public class CmsWorkplaceLoginHandler implements I_CmsResourceInit {
060:
061: /** The login handler path. */
062: public static final String LOGIN_HANDLER = "/system/login";
063:
064: /** The login form path. */
065: public static final String LOGIN_FORM = "/system/login/index.html";
066:
067: /**
068: * @see org.opencms.main.I_CmsResourceInit#initResource(org.opencms.file.CmsResource, org.opencms.file.CmsObject, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
069: */
070: public CmsResource initResource(CmsResource resource,
071: CmsObject cms, HttpServletRequest req,
072: HttpServletResponse res) throws CmsResourceInitException {
073:
074: // only do something if the resource was not found
075: if (resource != null) {
076: return resource;
077: }
078: String uri = cms.getRequestContext().getUri();
079: // check if the resource starts with the LOGIN_HANDLER
080: if (!uri.startsWith(LOGIN_HANDLER)) {
081: return resource;
082: }
083: // check if the uri has a dot, that is if a page is requested
084: if (uri.indexOf('.') > -1) {
085: return resource;
086: }
087: String storedSiteRoot = cms.getRequestContext().getSiteRoot();
088: try {
089: // we now must switch to the root site to read the resource
090: cms.getRequestContext().setSiteRoot("/");
091: // read the resource
092: resource = cms.readResource(LOGIN_FORM);
093: } catch (CmsException e) {
094: throw new CmsResourceInitException(e.getMessageContainer(),
095: e);
096: } finally {
097: // restore the siteroot
098: cms.getRequestContext().setSiteRoot(storedSiteRoot);
099: // resource may be null in case of an error
100: if (resource != null) {
101: // modify the uri to the one of the real resource
102: cms.getRequestContext().setUri(
103: cms.getSitePath(resource));
104: }
105: }
106: // get the ou path
107: String ou = uri.substring(LOGIN_HANDLER.length());
108: if (!ou.startsWith(CmsOrganizationalUnit.SEPARATOR)) {
109: ou = CmsOrganizationalUnit.SEPARATOR + ou;
110: }
111: if (!ou.endsWith(CmsOrganizationalUnit.SEPARATOR)) {
112: ou += CmsOrganizationalUnit.SEPARATOR;
113: }
114: req.setAttribute(CmsLogin.PARAM_PREDEF_OUFQN, ou);
115: return resource;
116: }
117: }
|