source: branches/TaskRewrite/src/plugins/acegi-0.5.1/src/java/org/codehaus/groovy/grails/plugins/springsecurity/facebook/FacebookLogoutHandler.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.5 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.facebook;
16
17import javax.servlet.http.Cookie;
18import javax.servlet.http.HttpServletRequest;
19import javax.servlet.http.HttpServletResponse;
20
21import org.springframework.beans.factory.InitializingBean;
22import org.springframework.security.Authentication;
23import org.springframework.security.ui.logout.LogoutHandler;
24import org.springframework.util.Assert;
25import org.springframework.util.StringUtils;
26
27/**
28 * Removes cookies at logout.
29 *
30 * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a>
31 */
32public class FacebookLogoutHandler implements LogoutHandler, InitializingBean {
33
34        private String _apiKey;
35
36        /**
37         * {@inheritDoc}
38         * @see org.springframework.security.ui.logout.LogoutHandler#logout(
39         *      javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse,
40         *      org.springframework.security.Authentication)
41         */
42        public void logout(final HttpServletRequest request, final HttpServletResponse response,
43                        final Authentication authentication) {
44
45                Cookie[] cookies = request.getCookies();
46                if (cookies != null) {
47                        String path = StringUtils.hasLength(request.getContextPath()) ? request.getContextPath() : "/";
48                        for (Cookie cookie : cookies) {
49                                if (cookie.getName().startsWith(_apiKey)) {
50                                        cancelCookie(cookie.getName(), path, response);
51                                }
52                        }
53                }
54        }
55
56        private void cancelCookie(final String name, final String path, final HttpServletResponse response) {
57      Cookie cookie = new Cookie(name, null);
58      cookie.setMaxAge(0);
59      cookie.setPath(path);
60      response.addCookie(cookie);
61        }
62
63        /**
64         * Dependency injection for the API key.
65         * @param key  the key
66         */
67        public void setApiKey(final String key) {
68                _apiKey = key;
69        }
70
71        /**
72         * {@inheritDoc}
73         * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
74         */
75        public void afterPropertiesSet() {
76      Assert.notNull(_apiKey, "API key must be specified");
77        }
78}
Note: See TracBrowser for help on using the repository browser.