01: /**
02: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
03: *
04: * This program is free software; you can redistribute it and/or modify
05: * it under the terms of the latest version of the GNU Lesser General
06: * Public License as published by the Free Software Foundation;
07: *
08: * This program is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: * GNU Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public License
14: * along with this program (LICENSE.txt); if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16: */package org.jamwiki.authentication;
17:
18: import javax.servlet.http.HttpServletRequest;
19: import javax.servlet.http.HttpServletResponse;
20: import org.acegisecurity.AuthenticationException;
21: import org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint;
22: import org.jamwiki.utils.WikiLogger;
23: import org.jamwiki.utils.WikiUtil;
24:
25: /**
26: * This class is a hack implemented to work around the fact that the default
27: * Acegi classes can only redirect to a single, hard-coded URL. Due to the
28: * fact that JAMWiki may have multiple virtual wikis this class overrides some
29: * of the default Acegi behavior to allow additional flexibility. Hopefully
30: * future versions of Acegi will add additional flexibility and this class
31: * can be removed.
32: */
33: public class JAMWikiAuthenticationProcessingFilterEntryPoint extends
34: AuthenticationProcessingFilterEntryPoint {
35:
36: /** Standard logger. */
37: private static final WikiLogger logger = WikiLogger
38: .getLogger(JAMWikiAuthenticationProcessingFilterEntryPoint.class
39: .getName());
40:
41: /**
42: * Return the URL to redirect to in case of a login being required. This method
43: * uses the configured login URL and prepends the virtual wiki.
44: */
45: protected String determineUrlToUseForThisRequest(
46: HttpServletRequest request, HttpServletResponse response,
47: AuthenticationException exception) {
48: String uri = request.getRequestURI();
49: // FIXME - move the "strip after semicolon" code to WikiUtil
50: int pathParamIndex = uri.indexOf(';');
51: if (pathParamIndex > 0) {
52: // strip everything after the first semi-colon
53: uri = uri.substring(0, pathParamIndex);
54: }
55: String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
56: return "/" + virtualWiki + this.getLoginFormUrl();
57: }
58: }
|