nexus site path corrected
[portal.git] / ecomp-portal-BE / 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.stereotype.Controller;
34 import org.springframework.web.bind.annotation.RequestMapping;
35 import org.springframework.web.bind.annotation.RequestMethod;
36 import org.springframework.web.context.request.RequestContextHolder;
37 import org.springframework.web.context.request.ServletRequestAttributes;
38 import org.springframework.web.servlet.ModelAndView;
39
40 @Controller
41 @RequestMapping("/")
42 @org.springframework.context.annotation.Configuration
43 @EnableAspectJAutoProxy
44 public class ECOMPLogoutController extends EPUnRestrictedBaseController{
45         
46         private EPUser user;
47         private static final String EP_SERVICE = "EPService";
48         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ECOMPLogoutController.class);
49
50         @EPAuditLog
51         @RequestMapping(value = {"/logout.htm" }, method = RequestMethod.GET)
52         public ModelAndView logOut(HttpServletRequest request,
53                                                                 HttpServletResponse response) throws Exception {
54         
55                 ModelAndView modelView = null;
56                                 
57                 chatRoomLogout(request);
58                 logger.debug(EELFLoggerDelegate.debugLogger, "ECOMPLogoutController.handleRequestInternal - Logout request received.");
59                 
60                 modelView = new ModelAndView("redirect:login.htm");
61                 
62                 /**
63                 if (UserUtils.isClientMobileDevice(request)){
64                 modelView.setViewName(modelView.getViewName().concat("?viewType=mobile"));
65                 }
66                 */
67                 String cookieDoamin = EPSystemProperties.getProperty(EPSystemProperties.COOKIE_DOMAIN);
68                 Cookie epCookie = new Cookie(EP_SERVICE, "");
69                 epCookie.setMaxAge(0);
70                 epCookie.setDomain(cookieDoamin);
71                 epCookie.setPath("/");
72                 
73                 Cookie appHeaderCookie = new Cookie("show_app_header", "");
74                 appHeaderCookie.setMaxAge(0);
75                 appHeaderCookie.setDomain(cookieDoamin);
76                 appHeaderCookie.setPath("/");
77                 
78                 Cookie appTabCookie = new Cookie("cookieTabs", "");
79                 appTabCookie.setMaxAge(0);
80                 appTabCookie.setDomain(cookieDoamin);
81                 appTabCookie.setPath("/");
82                 
83                 Cookie appVisInvisTabCookie = new Cookie("visInVisCookieTabs", "");
84                 appVisInvisTabCookie.setMaxAge(0);
85                 appVisInvisTabCookie.setDomain(cookieDoamin);
86                 appVisInvisTabCookie.setPath("/");
87                 
88             response.addCookie(epCookie);       
89             response.addCookie(appHeaderCookie);
90             response.addCookie(appTabCookie);
91             response.addCookie(appVisInvisTabCookie);
92                 request.getSession().invalidate();
93                 
94                 logger.debug(EELFLoggerDelegate.debugLogger, "ECOMPLogoutController.handleRequestInternal - Successfully processed the logout request.");
95                 
96                 return modelView;
97         }
98         
99         @EPMetricsLog
100         public void chatRoomLogout(HttpServletRequest request){
101                 request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); 
102                 setUser(EPUserUtils.getUserSession(request));
103         }
104         
105         public EPUser getUser() {
106                 return user;
107         }
108         
109         public void setUser(EPUser user) {
110                 this.user = user;
111         }
112 }