source: branches/TaskRewrite/src/plugins/acegi-0.5.1/src/groovy/org/codehaus/groovy/grails/plugins/springsecurity/GrailsAuthenticationProcessingFilter.groovy @ 58

Last change on this file since 58 was 58, checked in by gav, 15 years ago

Configure BootStrap? with latest concepts.
Install and setup Acegi plugin with custom views.
Test Fixture plugin in a test app but couldn't get it to work with Acegi encodePassword() so gave up.

File size: 2.9 KB
Line 
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 */
15package org.codehaus.groovy.grails.plugins.springsecurity
16
17import javax.servlet.FilterChain
18import javax.servlet.ServletException
19import javax.servlet.http.HttpServletRequest
20import javax.servlet.http.HttpServletResponse
21
22import org.springframework.security.Authentication
23import org.springframework.security.AuthenticationException
24import org.springframework.security.ui.webapp.AuthenticationProcessingFilter
25
26/**
27 * Extends the default {@link AuthenticationProcessingFilter} to override the <code>sendRedirect()</code>
28 * logic and always send absolute redirects.
29 *
30 * @author Tsuyoshi Yamamoto
31 */
32class GrailsAuthenticationProcessingFilter extends AuthenticationProcessingFilter {
33
34        /**
35         * Dependency injection for the authentication service.
36         */
37        def authenticateService
38
39        /**
40         * Dependency injection for the Ajax auth fail url.
41         */
42        String ajaxAuthenticationFailureUrl
43
44        /**
45         * {@inheritDoc}
46         * @see org.springframework.security.ui.AbstractProcessingFilter#doFilterHttp(
47         *      javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
48         *      javax.servlet.FilterChain)
49         */
50        @Override
51        void doFilterHttp(HttpServletRequest request, HttpServletResponse response,
52                        FilterChain chain) throws IOException, ServletException {
53
54                SecurityRequestHolder.set request, response
55                try {
56                        super.doFilterHttp(request, response, chain)
57                }
58                finally {
59                        SecurityRequestHolder.reset()
60                }
61        }
62
63        /**
64         * {@inheritDoc}
65         * @see org.springframework.security.ui.AbstractProcessingFilter#sendRedirect(
66         *      javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
67         *      java.lang.String)
68         */
69        @Override
70        protected void sendRedirect(
71                        HttpServletRequest request,
72                        HttpServletResponse response,
73                        String url) throws IOException {
74                RedirectUtils.sendRedirect(request, response, url);
75        }
76
77        /**
78         * {@inheritDoc}
79         * @see org.springframework.security.ui.AbstractProcessingFilter#determineFailureUrl(
80         *      javax.servlet.http.HttpServletRequest, org.springframework.security.AuthenticationException)
81         */
82        @Override
83        protected String determineFailureUrl(HttpServletRequest request, AuthenticationException failed) {
84                String url = super.determineFailureUrl(request, failed)
85                if (url == authenticationFailureUrl && authenticateService.isAjax(request)) {
86                        url = ajaxAuthenticationFailureUrl ?: authenticationFailureUrl
87                }
88                return url
89        }
90}
Note: See TracBrowser for help on using the repository browser.