Fixed Logout, Empty White Page, Session Timeout 47/109147/1
authorSudarshan Kumar <sudarshan.kumar@att.com>
Mon, 15 Jun 2020 06:46:09 +0000 (12:16 +0530)
committerSudarshan Kumar <sudarshan.kumar@att.com>
Mon, 15 Jun 2020 06:48:12 +0000 (12:18 +0530)
Logout, Empty White Page, Session Timeout Issues- fixed

Issue-ID: PORTAL-920
Change-Id: Ie96c5015397b88887e2fbc5422ce526eaacc8562
Signed-off-by: Sudarshan Kumar <sudarshan.kumar@att.com>
ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/LogoutController.java
ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/LogoutControllerTest.java
ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/header/header.component.html
ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/layout/components/header/header.component.ts
ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/columns/column-list/column-list.component.ts
ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/form-fields/form-fields.component.ts
ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/log/log.component.ts
ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/pages/analytics/Report_List/Report/sql/sql.component.ts
ecomp-sdk/epsdk-app-overlay/src/main/webapp/ngapp/src/app/shared/interceptors/header-interceptor.ts

index bbd08c4..d41bf23 100644 (file)
  */
 package org.onap.portalapp.controller.core;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.servlet.http.HttpServletRequest;
 
 import org.onap.portalsdk.core.controller.UnRestrictedBaseController;
-import org.onap.portalsdk.core.domain.User;
-import org.onap.portalsdk.core.logging.aspect.MetricsLog;
 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
-import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
-import org.onap.portalsdk.core.web.support.UserUtils;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
 import org.springframework.web.servlet.ModelAndView;
 
 @Controller
@@ -59,8 +55,6 @@ public class LogoutController extends UnRestrictedBaseController {
 
        private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(LogoutController.class);
 
-       private User user;
-
        /**
         * 
         * invalidates the current application session, then redirects to portal logout
@@ -72,53 +66,12 @@ public class LogoutController extends UnRestrictedBaseController {
        public ModelAndView globalLogout(HttpServletRequest request) {
                ModelAndView modelView = null;
                try {
-                       chatRoomLogout(request);
                        request.getSession().invalidate();
-                       String portalUrl = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL);
-                       String portalDomain = portalUrl.substring(0, portalUrl.lastIndexOf('/'));
-                       String redirectUrl = portalDomain + "/logout.htm";
-                       modelView = new ModelAndView("redirect:" + redirectUrl);
+                       Map<String, Object> model = new HashMap<>();
+                       return new ModelAndView("login", "model", model);
                } catch (Exception e) {
                        logger.error(EELFLoggerDelegate.errorLogger, "Logout failed", e);
                }
                return modelView;
        }
-
-       /**
-        * 
-        * invalidates the current session (application logout) and redirects user to
-        * Portal.
-        * 
-        * @param request
-        * @return modelView
-        */
-       @RequestMapping(value = { "/app_logout.htm" }, method = RequestMethod.GET)
-       public ModelAndView appLogout(HttpServletRequest request) {
-               ModelAndView modelView = null;
-               try {
-                       chatRoomLogout(request);
-                       modelView = new ModelAndView(
-                                       "redirect:" + PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL));
-                       UserUtils.clearUserSession(request);
-                       request.getSession().invalidate();
-               } catch (Exception e) {
-                       logger.error(EELFLoggerDelegate.errorLogger, "Application Logout failed", e);
-               }
-               return modelView;
-       }
-
-       @MetricsLog
-       public void chatRoomLogout(HttpServletRequest request) {
-               request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
-               setUser(UserUtils.getUserSession(request));
-       }
-
-       public User getUser() {
-               return user;
-       }
-
-       public void setUser(User user) {
-               this.user = user;
-       }
-
 }
index 8883cfa..71d7277 100644 (file)
@@ -37,9 +37,6 @@
  */
 package org.onap.portalapp.controller.core;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -111,46 +108,4 @@ public class LogoutControllerTest {
                                                .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("http://portal.api.simpledemo.onap.org:8989/ONAPPORTAL/login.htm");
                logoutController.globalLogout(mockedRequest);
        }
-       
-       @Test
-       public void globalLogoutExceptionTest(){
-               PowerMockito.mockStatic(PortalApiProperties.class);
-               PowerMockito.mockStatic(PortalApiConstants.class);
-               Mockito.when(PortalApiProperties
-                                               .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("http://portal.api.simpledemo.onap.org:8989/ONAPPORTAL/login.htm");             
-               assertNull(logoutController.globalLogout(mockedRequest));
-       }
-       
-       @Test
-       public void appLogoutTest(){
-               ModelAndView actualModelView = new ModelAndView("redirect:http://portal.api.simpledemo.onap.org:8989/ONAPPORTAL/login.htm");
-               PowerMockito.mockStatic(PortalApiProperties.class);
-               PowerMockito.mockStatic(PortalApiConstants.class);
-               PowerMockito.mockStatic(RequestContextHolder.class);
-               ServletRequestAttributes ServletRequestAttributes = new ServletRequestAttributes(mockedRequest);
-               Mockito.when(RequestContextHolder.currentRequestAttributes()).thenReturn(ServletRequestAttributes);
-               Mockito.when(PortalApiProperties
-                                               .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("http://portal.api.simpledemo.onap.org:8989/ONAPPORTAL/login.htm");             
-               ModelAndView expectedModelView = logoutController.appLogout(mockedRequest);
-               assertEquals(actualModelView.getViewName(), expectedModelView.getViewName());
-       }
-       
-       @Test
-       public void appLogoutExceptionTest(){
-               PowerMockito.mockStatic(PortalApiProperties.class);
-               PowerMockito.mockStatic(PortalApiConstants.class);
-               Mockito.when(PortalApiProperties
-                                               .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("http://portal.api.simpledemo.onap.org:8989/ONAPPORTAL/login.htm");             
-               assertNull(logoutController.appLogout(mockedRequest));
-       }
-       
-       @Test
-       public void getUserTest(){
-               User expectedUser = new User();
-               expectedUser.setActive(false);
-               user.setActive(false);
-               logoutController.setUser(user);
-               User actualUser = logoutController.getUser();
-               assertEquals(expectedUser.getActive(), actualUser.getActive());
-       }
 }
index 04701ca..59ab1c4 100644 (file)
@@ -22,7 +22,7 @@
                             <div>userId:</div>{{userId}}</span></div>
                         <br/>    
                             <div id="reg-logout-div" style="padding-top: 8px">
-                                    <a href="logout.htm" id="allLogout" class="btn btn-primary">
+                                    <a href="{{logOutURL}}" id="allLogout" class="btn btn-primary">
                                       Log out
                                   </a>
                               </div>
index 7bf5c64..16dc654 100644 (file)
@@ -41,6 +41,7 @@ import { HeaderService } from '../../../shared/services/header/header.service';
 import { UserService } from 'src/app/shared/services/user/user.service';
 import { User } from 'src/app/shared/services/user/user';
 import { CookieService } from 'ngx-cookie-service';
+import { environment } from 'src/environments/environment';
 
 @Component({
     selector: 'app-header',
@@ -57,9 +58,18 @@ export class HeaderComponent implements OnInit {
     userName;
     appName:string;
     showHeader:boolean = true;
+    logOutURL = environment.baseUrl;
 
 
-        constructor(public router: Router,public headerService: HeaderService,public cookieService: CookieService) {
+    constructor(public router: Router,public headerService: HeaderService,public cookieService: CookieService) {
+
+        if(window.location.pathname.split('/').length > 3) {
+            var portNum = ( window.location.port === '' || window.location.port === '0' ) ?  '' : ':'+ window.location.port;
+            this.logOutURL = window.location.protocol + "//" + window.location.hostname + portNum + window.location.pathname.substring(0, this.nthIndex(window.location.pathname, "/", 2) + 0) + '/logout.htm';
+        } else {
+            this.logOutURL = environment.baseUrl + 'logout.htm';                        
+        }
+        
 
         this.router.events.subscribe(val => {
             if (
@@ -103,4 +113,13 @@ export class HeaderComponent implements OnInit {
     onLoggedout() {
         localStorage.removeItem('isLoggedin');
     }
+
+    nthIndex(str, pat, n) {
+        var L = str.length, i = -1;
+        while (n-- && i++ < L) {
+          i = str.indexOf(pat, i);
+          if (i < 0) break;
+        }
+        return i;
+    }
 }
index fc34ccc..e3bab3b 100644 (file)
@@ -76,16 +76,20 @@ export class FormFieldsComponent implements OnInit {
   }
 
   ngOnInit() {
+    this.showSpinner = true;
     this._formFieldsService.getListOfFormFields()
       .subscribe((responseFormFields) => {
+        this.showSpinner = true;
         for (let m = 0; m < responseFormFields.length; m++) {
           responseFormFields[m]["orderSeq"] = m + 1;
           this.formFieldsListObj.push(responseFormFields[m]);
         }
-
+        this.showSpinner = false;
         this._formFieldsService.getFormFieldGroupsData(this.reportId1)
           .subscribe((responseGroupsData) => {
+            this.showSpinner = true;
             this.Groups = JSON.parse(responseGroupsData["formFieldGroupsJSON"]);
+            this.showSpinner = false;
           });     
     });
   }
index 62c7d7a..897aa03 100644 (file)
@@ -46,6 +46,7 @@ export class SQLComponent implements OnInit {
     }
 
     ngOnInit() {
+        this.showSpinner = true;
         this.showSaveSQLDialog = false;
         this.SQLPostResponse = true;
         this.ValidatePostResponse = {};
index 5097376..1539877 100644 (file)
@@ -42,9 +42,22 @@ import {
     HttpHandler,
     HttpRequest,
     HttpHeaders,
+    HttpErrorResponse
 } from '@angular/common/http';
-import { Observable } from 'rxjs';
+import { Observable, throwError} from 'rxjs';
 import { v4 as uuid } from 'uuid';
+import { catchError } from 'rxjs/internal/operators/catchError';
+import { environment } from '../../../environments/environment';
+
+function nthIndex(str, pat, n) {
+    var L = str.length, i = -1;
+    while (n-- && i++ < L) {
+      i = str.indexOf(pat, i);
+      if (i < 0) break;
+    }
+    return i;
+}
+
 export class HeaderInterceptor implements HttpInterceptor {
     intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
         const headerSettings: { [name: string]: string | string[]; } = {};
@@ -58,6 +71,23 @@ export class HeaderInterceptor implements HttpInterceptor {
         const newHeader = new HttpHeaders(headerSettings);
         const clonedRequest = req.clone({ headers: newHeader, withCredentials: true });
         // Pass the cloned request instead of the original request to the next handle
-        return next.handle(clonedRequest);
+        //return next.handle(clonedRequest);
+        var url = '';
+        return next.handle(clonedRequest).pipe(
+            catchError(error => {
+                if ( error instanceof HttpErrorResponse ) {
+                    if ( error.status === 0 ) { // If 0(302) Redirect to Login Page
+                        if(window.location.pathname.split('/').length > 3) {
+                            var portNum = ( window.location.port === '' || window.location.port === '0' ) ?  '' : ':'+ window.location.port;
+                            url = window.location.protocol + "//" + window.location.hostname + portNum + window.location.pathname.substring(0, nthIndex(window.location.pathname, "/", 2) + 0) + '/login.htm';
+                            window.open( url, '_self' );
+                        } else {
+                            window.open( environment.baseUrl + 'login.htm', '_self' );                         
+                        }
+                    }
+                }
+                return throwError(error);
+            })
+        );
     }
 }
\ No newline at end of file