source: branches/TaskRewrite/src/plugins/acegi-0.5.1/src/java/org/codehaus/groovy/grails/plugins/springsecurity/WithAjaxAuthenticationProcessingFilterEntryPoint.java @ 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.6 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.http.HttpServletRequest;
18import javax.servlet.http.HttpServletResponse;
19
20import org.springframework.security.AuthenticationException;
21import org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint;
22
23/**
24 * {@link AuthenticationProcessingFilterEntryPoint} with Ajax login form option if
25 * Method Access is denied returns <code>null</code>.
26 *
27 * @author T.Yamamoto
28 * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a>
29 */
30public class WithAjaxAuthenticationProcessingFilterEntryPoint extends AuthenticationProcessingFilterEntryPoint {
31
32        /**
33         * Default value for the name of the Ajax header.
34         */
35        public static final String AJAX_HEADER = "X-Requested-With";
36
37        private String ajaxLoginFormUrl;
38        private String ajaxHeader = AJAX_HEADER;
39
40        /**
41         * {@inheritDoc}
42         * @see org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint#determineUrlToUseForThisRequest(
43         *      javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
44         *      org.springframework.security.AuthenticationException)
45         */
46        @Override
47        protected String determineUrlToUseForThisRequest(
48                        final HttpServletRequest request, final HttpServletResponse response,
49                        final AuthenticationException exception) {
50
51                if (request.getHeader(ajaxHeader) != null && ajaxLoginFormUrl != null) {
52                        return ajaxLoginFormUrl;
53                }
54
55                return getLoginFormUrl();
56        }
57
58        /**
59         * Dependency injection for the Ajax login form url, e.g. '/login/authAjax'.
60         * @param url  the url
61         */
62        public void setAjaxLoginFormUrl(final String url) {
63                if (url != null && !url.startsWith("/")) {
64                        throw new IllegalArgumentException("ajaxLoginFormUrl must begin with '/'");
65                }
66                ajaxLoginFormUrl = url;
67        }
68
69        /**
70         * Dependency injection for the Ajax header name; defaults to 'X-Requested-With'.
71         * @param header  the header name
72         */
73        public void setAjaxHeader(final String header) {
74                ajaxHeader = header;
75        }
76}
Note: See TracBrowser for help on using the repository browser.