1 | /* Copyright 2006-2009 the original author or authors. |
---|
2 | * |
---|
3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | * you may not use this file except in compliance with the License. |
---|
5 | * You may obtain a copy of the License at |
---|
6 | * |
---|
7 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | * |
---|
9 | * Unless required by applicable law or agreed to in writing, software |
---|
10 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | * See the License for the specific language governing permissions and |
---|
13 | * limitations under the License. |
---|
14 | */ |
---|
15 | package org.codehaus.groovy.grails.plugins.springsecurity |
---|
16 | |
---|
17 | import javax.servlet.http.HttpServletRequest |
---|
18 | import javax.servlet.http.HttpServletResponse |
---|
19 | |
---|
20 | import org.springframework.beans.factory.FactoryBean |
---|
21 | import org.springframework.beans.factory.InitializingBean |
---|
22 | import org.springframework.beans.factory.annotation.Required |
---|
23 | import org.springframework.security.ui.logout.LogoutFilter |
---|
24 | import org.springframework.security.ui.logout.LogoutHandler |
---|
25 | |
---|
26 | /** |
---|
27 | * Configures a {@link LogoutFilter} given a list of {@link LogoutHandler}s. |
---|
28 | * |
---|
29 | * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a> |
---|
30 | */ |
---|
31 | class LogoutFilterFactoryBean implements FactoryBean, InitializingBean { |
---|
32 | |
---|
33 | private List<LogoutHandler> _handlers |
---|
34 | private LogoutFilter _logoutFilter |
---|
35 | private String _logoutSuccessUrl |
---|
36 | |
---|
37 | /** |
---|
38 | * {@inheritDoc} |
---|
39 | * @see org.springframework.beans.factory.FactoryBean#getObject() |
---|
40 | */ |
---|
41 | LogoutFilter getObject() { |
---|
42 | return _logoutFilter |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | * {@inheritDoc} |
---|
47 | * @see org.springframework.beans.factory.FactoryBean#getObjectType() |
---|
48 | */ |
---|
49 | Class<LogoutFilter> getObjectType() { |
---|
50 | return LogoutFilter |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * {@inheritDoc} |
---|
55 | * @see org.springframework.beans.factory.FactoryBean#isSingleton() |
---|
56 | */ |
---|
57 | boolean isSingleton() { |
---|
58 | return true |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | * {@inheritDoc} |
---|
63 | * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() |
---|
64 | */ |
---|
65 | void afterPropertiesSet() { |
---|
66 | _logoutFilter = new FixRedirectLogoutFilter(_logoutSuccessUrl, _handlers as LogoutHandler[]) |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * Dependency injection for the logout success url. |
---|
71 | * @param logoutSuccessUrl the url |
---|
72 | */ |
---|
73 | @Required |
---|
74 | void setLogoutSuccessUrl(String logoutSuccessUrl) { |
---|
75 | _logoutSuccessUrl = logoutSuccessUrl |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | * Dependency injection for the handlers. |
---|
80 | * @param handlers the handlers |
---|
81 | */ |
---|
82 | @Required |
---|
83 | void setHandlers(List<LogoutHandler> handlers) { |
---|
84 | _handlers = handlers |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * Overrides the default redirect behavior to use {@link RedirectUtils#sendRedirect(HttpServletRequest, HttpServletResponse, String)}. |
---|
90 | */ |
---|
91 | class FixRedirectLogoutFilter extends LogoutFilter { |
---|
92 | |
---|
93 | FixRedirectLogoutFilter(String logoutSuccessUrl, LogoutHandler[] handlers) { |
---|
94 | super(logoutSuccessUrl, handlers) |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * {@inheritDoc} |
---|
99 | * @see org.springframework.security.ui.logout.LogoutFilter#sendRedirect( |
---|
100 | * javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String) |
---|
101 | */ |
---|
102 | @Override |
---|
103 | protected void sendRedirect( |
---|
104 | HttpServletRequest request, |
---|
105 | HttpServletResponse response, |
---|
106 | String url) throws IOException { |
---|
107 | RedirectUtils.sendRedirect(request, response, url) |
---|
108 | } |
---|
109 | } |
---|