2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.web;
12 import javax.servlet.http.HttpServletRequest;
13 import javax.servlet.http.HttpServletResponse;
14 import javax.servlet.http.HttpSession;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18 import org.springframework.security.core.Authentication;
19 import org.springframework.security.web.authentication.logout.LogoutHandler;
21 import org.opendaylight.controller.sal.utils.ServiceHelper;
22 import org.opendaylight.controller.usermanager.IUserManager;
24 public class ControllerLogoutHandler implements LogoutHandler {
26 private static final Logger logger = LoggerFactory
27 .getLogger(ControllerLogoutHandler.class);
30 public void logout(HttpServletRequest request,
31 HttpServletResponse response, Authentication authentication) {
32 if (authentication != null) {
33 String userName = authentication.getName();
34 if (userName != null) {
35 IUserManager userManager = (IUserManager) ServiceHelper
36 .getGlobalInstance(IUserManager.class, this);
37 if (userManager != null) {
38 userManager.userLogout(userName);
39 HttpSession session = request.getSession();
40 userManager.getSessionManager().invalidateSessions(userName, session.getId());
44 .error("UserMgr ref is null. Logout is not done cleanly");
48 .error("User name is null in authentication. Logout is not done cleanly");