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