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 java.util.Iterator;
19: import javax.servlet.http.HttpServletRequest;
20: import org.acegisecurity.ConfigAttribute;
21: import org.acegisecurity.ConfigAttributeDefinition;
22: import org.acegisecurity.intercept.web.FilterInvocationDefinitionSourceEditor;
23: import org.acegisecurity.intercept.web.PathBasedFilterInvocationDefinitionMap;
24: import org.jamwiki.utils.WikiLogger;
25:
26: /**
27: * This class provides a configurable bean object that can be used with the
28: * JAMWikiAccessDeniedHandler to retrieve URL-specific error messages to
29: * present to the user in the case of authorization or authentication failures.
30: */
31: public class JAMWikiErrorMessageProvider {
32:
33: private static final WikiLogger logger = WikiLogger
34: .getLogger(JAMWikiErrorMessageProvider.class.getName());
35: private String urlPatterns;
36:
37: /**
38: *
39: */
40: public String getErrorMessageKey(HttpServletRequest request) {
41: return this .retrieveErrorKey(request);
42: }
43:
44: /**
45: *
46: */
47: public String getUrlPatterns() {
48: return this .urlPatterns;
49: }
50:
51: /**
52: *
53: */
54: private ConfigAttributeDefinition retrieveConfigAttributeDefinition(
55: HttpServletRequest request) {
56: String uri = request.getRequestURI();
57: if (uri == null) {
58: return null;
59: }
60: FilterInvocationDefinitionSourceEditor editor = new FilterInvocationDefinitionSourceEditor();
61: editor.setAsText(this .getUrlPatterns());
62: PathBasedFilterInvocationDefinitionMap map = (PathBasedFilterInvocationDefinitionMap) editor
63: .getValue();
64: return map.lookupAttributes(uri);
65: }
66:
67: /**
68: *
69: */
70: private String retrieveErrorKey(HttpServletRequest request) {
71: ConfigAttributeDefinition attrs = this
72: .retrieveConfigAttributeDefinition(request);
73: if (attrs != null) {
74: Iterator configIterator = attrs.getConfigAttributes();
75: if (configIterator.hasNext()) {
76: ConfigAttribute attr = (ConfigAttribute) configIterator
77: .next();
78: return attr.getAttribute();
79: }
80: }
81: return null;
82: }
83:
84: /**
85: *
86: */
87: public void setUrlPatterns(String urlPatterns) {
88: this.urlPatterns = urlPatterns;
89: }
90: }
|