467bd3c9a8b432dd6647d1002997d909f9f5768f
[portal/sdk.git] /
1 /*-
2  * ================================================================================
3  * ECOMP Portal SDK
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.core;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25 import org.openecomp.portalsdk.core.controller.UnRestrictedBaseController;
26 import org.openecomp.portalsdk.core.domain.User;
27 import org.openecomp.portalsdk.core.logging.format.AlarmSeverityEnum;
28 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
29 import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants;
30 import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties;
31 import org.openecomp.portalsdk.core.web.support.UserUtils;
32 import org.springframework.stereotype.Controller;
33 import org.springframework.web.bind.annotation.RequestMapping;
34 import org.springframework.web.bind.annotation.RequestMethod;
35 import org.springframework.web.context.request.RequestContextHolder;
36 import org.springframework.web.context.request.ServletRequestAttributes;
37 import org.springframework.web.servlet.ModelAndView;
38
39 @Controller
40 @RequestMapping("/")
41 public class LogoutController extends UnRestrictedBaseController{
42
43         private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(LogoutController.class);
44
45         private User user;
46         
47         /**
48          * @param request
49          * @param response
50          * @return modelView
51          * 
52          * globalLogout will invalid the current application session, then redirects to portal logout
53          */
54         @RequestMapping(value = {"/logout.htm" }, method = RequestMethod.GET)
55         public ModelAndView globalLogout(HttpServletRequest request, HttpServletResponse response) {
56                 ModelAndView modelView = null;
57                 try{
58                         chatRoomLogout(request);
59                         request.getSession().invalidate();
60                         String portalUrl = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL);      
61                         String portalDomain = portalUrl.substring(0, portalUrl.lastIndexOf('/'));
62                         String redirectUrl = portalDomain+"/logout.htm";
63                         modelView = new ModelAndView("redirect:"+redirectUrl);
64                 }catch(Exception e){
65                         logger.error(EELFLoggerDelegate.errorLogger, "Logout Error: " + e.getMessage(),AlarmSeverityEnum.MAJOR);
66                 }
67                 return modelView;
68         }
69
70         /**
71          * @param request
72          * @param response
73          * @return modelView
74          * 
75          * appLogout is a function that will invalid the current session (application logout) and redirects user to Portal.
76          */
77         @RequestMapping(value = {"/app_logout.htm" }, method = RequestMethod.GET)
78         public ModelAndView appLogout(HttpServletRequest request, HttpServletResponse response) {
79                 ModelAndView modelView = null;
80                 try{
81                         chatRoomLogout(request);
82                     modelView = new ModelAndView("redirect:"+PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL));
83                         UserUtils.clearUserSession(request);                    
84                         request.getSession().invalidate();
85                 }catch(Exception e){
86                         logger.error(EELFLoggerDelegate.errorLogger, "Application Logout Error: " + e.getMessage(),AlarmSeverityEnum.MAJOR);
87                 }
88                 return modelView;
89         }
90
91
92         public void chatRoomLogout(HttpServletRequest request){
93                 request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest(); 
94                 setUser(UserUtils.getUserSession(request));
95                 // if(getUser()!=null){
96                 // Long login_IdLong = getUser().getId();
97                 // String name = getUser().getFirstName();
98                 // String login_IdStr = Long.toString(login_IdLong);
99                 // }
100                 //UserListName.getInstance().delUserName(name);
101                 //UserListID.getInstance().delUserName(login_IdStr);
102         }
103
104         public User getUser() {
105                 return user;
106         }
107
108         public void setUser(User user) {
109                 this.user = user;
110         }
111
112
113 }