[PORTAL-7] Rebase
[portal.git] / ecomp-portal-BE-os / src / main / java / org / openecomp / portalapp / controller / ECOMPLogoutController.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 package org.openecomp.portalapp.controller;
21
22 import javax.servlet.http.Cookie;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25
26 import org.openecomp.portalapp.portal.domain.EPUser;
27 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
28 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
29 import org.openecomp.portalapp.portal.utils.EPSystemProperties;
30 import org.openecomp.portalapp.util.EPUserUtils;
31 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.springframework.context.annotation.EnableAspectJAutoProxy;
33 import org.springframework.context.annotation.Profile;
34 import org.springframework.stereotype.Controller;
35 import org.springframework.web.bind.annotation.RequestMapping;
36 import org.springframework.web.bind.annotation.RequestMethod;
37 import org.springframework.web.context.request.RequestContextHolder;
38 import org.springframework.web.context.request.ServletRequestAttributes;
39 import org.springframework.web.servlet.ModelAndView;
40
41 @Controller
42 @RequestMapping("/")
43 @org.springframework.context.annotation.Configuration
44 @EnableAspectJAutoProxy
45 @Profile("src")
46 public class ECOMPLogoutController extends EPUnRestrictedBaseController{
47         
48         private EPUser user;
49         private static final String EP_SERVICE = "EPService";
50         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ECOMPLogoutController.class);
51
52         @EPAuditLog
53         @RequestMapping(value = {"/logout.htm" }, method = RequestMethod.GET)
54         public ModelAndView logOut(HttpServletRequest request,
55                                                                 HttpServletResponse response) throws Exception {
56         
57                 ModelAndView modelView = null;
58                                 
59                 chatRoomLogout(request);
60                 logger.debug(EELFLoggerDelegate.debugLogger, "ECOMPLogoutController.handleRequestInternal - Logout request received.");
61                 
62                 modelView = new ModelAndView("redirect:login.htm");
63                 
64                 /**
65                 if (UserUtils.isClientMobileDevice(request)){
66                 modelView.setViewName(modelView.getViewName().concat("?viewType=mobile"));
67                 }
68                 */
69                 String cookieDoamin = EPSystemProperties.getProperty(EPSystemProperties.COOKIE_DOMAIN);
70                 Cookie epCookie = new Cookie(EP_SERVICE, "");
71                 epCookie.setMaxAge(0);
72                 epCookie.setDomain(cookieDoamin);
73                 epCookie.setPath("/");
74                 
75                 Cookie appHeaderCookie = new Cookie("show_app_header", "");
76                 appHeaderCookie.setMaxAge(0);
77                 appHeaderCookie.setDomain(cookieDoamin);
78                 appHeaderCookie.setPath("/");
79                 
80                 Cookie appTabCookie = new Cookie("cookieTabs", "");
81                 appTabCookie.setMaxAge(0);
82                 appTabCookie.setDomain(cookieDoamin);
83                 appTabCookie.setPath("/");
84                 
85                 Cookie appVisInvisTabCookie = new Cookie("visInVisCookieTabs", "");
86                 appVisInvisTabCookie.setMaxAge(0);
87                 appVisInvisTabCookie.setDomain(cookieDoamin);
88                 appVisInvisTabCookie.setPath("/");
89                 
90             response.addCookie(epCookie);       
91             response.addCookie(appHeaderCookie);
92             response.addCookie(appTabCookie);
93             response.addCookie(appVisInvisTabCookie);
94                 request.getSession().invalidate();
95                 
96                 logger.debug(EELFLoggerDelegate.debugLogger, "ECOMPLogoutController.handleRequestInternal - Successfully processed the logout request.");
97                 
98                 return modelView;
99         }
100         
101         @EPMetricsLog
102         public void chatRoomLogout(HttpServletRequest request){
103                 request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); 
104                 setUser(EPUserUtils.getUserSession(request));
105         }
106         
107         public EPUser getUser() {
108                 return user;
109         }
110         
111         public void setUser(EPUser user) {
112                 this.user = user;
113         }
114 }