062a2e2a8a909a78d03e5b48efe32c0099adf493
[portal.git] / ecomp-portal-BE-os / src / main / java / org / onap / portalapp / controller / ECOMPLogoutController.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 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  * 
37  */
38 package org.onap.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.onap.portalapp.controller.EPUnRestrictedBaseController;
45 import org.onap.portalapp.portal.domain.EPUser;
46 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
47 import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
48 import org.onap.portalapp.portal.utils.EPSystemProperties;
49 import org.onap.portalapp.util.EPUserUtils;
50 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
51 import org.springframework.context.annotation.EnableAspectJAutoProxy;
52 import org.springframework.context.annotation.Profile;
53 import org.springframework.stereotype.Controller;
54 import org.springframework.web.bind.annotation.RequestMapping;
55 import org.springframework.web.bind.annotation.RequestMethod;
56 import org.springframework.web.context.request.RequestContextHolder;
57 import org.springframework.web.context.request.ServletRequestAttributes;
58 import org.springframework.web.servlet.ModelAndView;
59
60 @Controller
61 @RequestMapping("/")
62 @org.springframework.context.annotation.Configuration
63 @EnableAspectJAutoProxy
64 @Profile("src")
65 public class ECOMPLogoutController extends EPUnRestrictedBaseController{
66         
67         private EPUser user;
68         private static final String EP_SERVICE = "EPService";
69         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ECOMPLogoutController.class);
70
71         @EPAuditLog
72         @RequestMapping(value = {"/logout.htm" }, method = RequestMethod.GET)
73         public ModelAndView logOut(HttpServletRequest request,
74                                                                 HttpServletResponse response) throws Exception {
75         
76                 ModelAndView modelView = null;
77                                 
78                 chatRoomLogout(request);
79                 logger.debug(EELFLoggerDelegate.debugLogger, "ECOMPLogoutController.handleRequestInternal - Logout request received.");
80                 
81                 modelView = new ModelAndView("redirect:login.htm");
82                 
83                 /**
84                 if (UserUtils.isClientMobileDevice(request)){
85                 modelView.setViewName(modelView.getViewName().concat("?viewType=mobile"));
86                 }
87                 */
88                 String cookieDoamin = EPSystemProperties.getProperty(EPSystemProperties.COOKIE_DOMAIN);
89                 Cookie epCookie = new Cookie(EP_SERVICE, "");
90                 epCookie.setMaxAge(0);
91                 epCookie.setDomain(cookieDoamin);
92                 epCookie.setPath("/");
93                 
94                 Cookie appHeaderCookie = new Cookie("show_app_header", "");
95                 appHeaderCookie.setMaxAge(0);
96                 appHeaderCookie.setDomain(cookieDoamin);
97                 appHeaderCookie.setPath("/");
98                 
99                 Cookie appTabCookie = new Cookie("cookieTabs", "");
100                 appTabCookie.setMaxAge(0);
101                 appTabCookie.setDomain(cookieDoamin);
102                 appTabCookie.setPath("/");
103                 
104                 Cookie appVisInvisTabCookie = new Cookie("visInVisCookieTabs", "");
105                 appVisInvisTabCookie.setMaxAge(0);
106                 appVisInvisTabCookie.setDomain(cookieDoamin);
107                 appVisInvisTabCookie.setPath("/");
108                 
109             response.addCookie(epCookie);       
110             response.addCookie(appHeaderCookie);
111             response.addCookie(appTabCookie);
112             response.addCookie(appVisInvisTabCookie);
113                 request.getSession().invalidate();
114                 
115                 logger.debug(EELFLoggerDelegate.debugLogger, "ECOMPLogoutController.handleRequestInternal - Successfully processed the logout request.");
116                 
117                 return modelView;
118         }
119         
120         @EPMetricsLog
121         public void chatRoomLogout(HttpServletRequest request){
122                 request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); 
123                 setUser(EPUserUtils.getUserSession(request));
124         }
125         
126         public EPUser getUser() {
127                 return user;
128         }
129         
130         public void setUser(EPUser user) {
131                 this.user = user;
132         }
133 }