Set secure flag & log exception
[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,
80                 "ECOMPLogoutController.handleRequestInternal - Logout request received.");
81
82         modelView = new ModelAndView("redirect:login.htm");
83
84         /**
85          * if (UserUtils.isClientMobileDevice(request)){
86          * modelView.setViewName(modelView.getViewName().concat("?viewType=mobile")); }
87          */
88         String cookieDoamin = EPSystemProperties.getProperty(EPSystemProperties.COOKIE_DOMAIN);
89         Cookie epCookie = new Cookie(EP_SERVICE, "");
90         epCookie.setSecure(true);
91         epCookie.setMaxAge(0);
92         epCookie.setDomain(cookieDoamin);
93         epCookie.setPath("/");
94
95         Cookie appHeaderCookie = new Cookie("show_app_header", "");
96         appHeaderCookie.setSecure(true);
97         appHeaderCookie.setMaxAge(0);
98         appHeaderCookie.setDomain(cookieDoamin);
99         appHeaderCookie.setPath("/");
100
101         Cookie appTabCookie = new Cookie("cookieTabs", "");
102         appTabCookie.setSecure(true);
103         appTabCookie.setMaxAge(0);
104         appTabCookie.setDomain(cookieDoamin);
105         appTabCookie.setPath("/");
106
107         Cookie appVisInvisTabCookie = new Cookie("visInVisCookieTabs", "");
108         appVisInvisTabCookie.setSecure(true);
109         appVisInvisTabCookie.setMaxAge(0);
110         appVisInvisTabCookie.setDomain(cookieDoamin);
111         appVisInvisTabCookie.setPath("/");
112
113         response.addCookie(epCookie);
114         response.addCookie(appHeaderCookie);
115         response.addCookie(appTabCookie);
116         response.addCookie(appVisInvisTabCookie);
117         request.getSession().invalidate();
118
119         logger.debug(EELFLoggerDelegate.debugLogger,
120                 "ECOMPLogoutController.handleRequestInternal - Successfully processed the logout request.");
121
122         return modelView;
123     }
124
125     @EPMetricsLog
126     public void chatRoomLogout(HttpServletRequest request) {
127         request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
128         setUser(EPUserUtils.getUserSession(request));
129     }
130
131     public EPUser getUser() {
132         return user;
133     }
134
135     public void setUser(EPUser user) {
136         this.user = user;
137     }
138 }