Add error handling in PortalRestCentralServiceImpl 41/3441/1
authorLott, Christopher (cl778h) <cl778h@att.com>
Wed, 22 Apr 2020 00:49:29 +0000 (20:49 -0400)
committerLott, Christopher (cl778h) <cl778h@att.com>
Thu, 23 Apr 2020 20:35:06 +0000 (16:35 -0400)
Change-Id: I3e7523079fcdf0ec614908063f4417c0b35352e5
Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/WebSecurityConfiguration.java
dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/portalapi/PortalRestCentralServiceImpl.java
dashboard/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/WebSecurityMockConfiguration.java
dashboard/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/controller/DefaultContextTest.java
dashboard/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/controller/PortalRestCentralServiceTest.java

index 0a3f022..f1fcca9 100644 (file)
@@ -113,7 +113,7 @@ public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
        @Bean
        public PortalAuthManager portalAuthManagerBean() throws ClassNotFoundException, IllegalAccessException,
                        InstantiationException, InvocationTargetException, NoSuchMethodException {
-               logger.debug("portalAuthManagerBean");
+               logger.debug("portalAuthManagerBean: appName {}", appName);
                return new PortalAuthManager(appName, portalApiUsername, portalApiPassword, decryptor, userCookie);
        }
 
@@ -128,7 +128,7 @@ public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
         */
        public PortalAuthenticationFilter portalAuthenticationFilterBean() throws ClassNotFoundException,
                        IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
-               logger.debug("portalAuthenticationFilterBean");
+               logger.debug("portalAuthenticationFilterBean: portalapiSecurity {}", portalapiSecurity);
                return new PortalAuthenticationFilter(portalapiSecurity, portalAuthManagerBean(), this.userManager);
        }
 
index 93ebc82..7f4114d 100644 (file)
@@ -51,12 +51,19 @@ public class PortalRestCentralServiceImpl implements IPortalRestCentralService {
        private final DashboardUserManager userManager;
 
        public PortalRestCentralServiceImpl() throws IOException, PortalAPIException {
-               final ApplicationContext context = SpringContextCache.getApplicationContext();
-               authManager = context.getBean(PortalAuthManager.class);
-               userManager = context.getBean(DashboardUserManager.class);
-               logger.debug("ctor: authManager has credentials for app {}",
-                               authManager.getAppCredentials().get(IPortalRestCentralService.CREDENTIALS_APP));
-               logger.debug("ctor: userManager has list size {}", userManager.getUsers().size());
+               try {
+                       final ApplicationContext context = SpringContextCache.getApplicationContext();
+                       authManager = context.getBean(PortalAuthManager.class);
+                       userManager = context.getBean(DashboardUserManager.class);
+                       logger.debug("ctor: authManager fetched credentials for app {}",
+                                       authManager.getAppCredentials().get(IPortalRestCentralService.CREDENTIALS_APP));
+                       logger.debug("ctor: userManager has list size {}", userManager.getUsers().size());
+               } catch (Exception ex) {
+                       // Log the exception before it's discarded by class
+                       // PortalRestAPICentralServiceImpl
+                       logger.error("ctor failed", ex);
+                       throw ex;
+               }
        }
 
        /*
index 2c111db..c90c3d6 100644 (file)
@@ -21,7 +21,6 @@ package org.oransc.ric.portal.dashboard.config;
 
 import java.lang.invoke.MethodHandles;
 
-import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestCentralService;
 import org.oransc.ric.portal.dashboard.DashboardConstants;
 import org.oransc.ric.portal.dashboard.portalapi.PortalAuthManager;
 import org.slf4j.Logger;
@@ -98,8 +97,8 @@ public class WebSecurityMockConfiguration extends WebSecurityConfigurerAdapter {
 
        @Bean
        public PortalAuthManager portalAuthManagerBean() throws Exception {
-               logger.debug("portalAuthManagerBean");
-               return new PortalAuthManager(IPortalRestCentralService.CREDENTIALS_APP, portalApiUsername, portalApiPassword,
+               logger.debug("portalAuthManagerBean: app {}", appName);
+               return new PortalAuthManager(appName, portalApiUsername, portalApiPassword,
                                decryptor, userCookie);
        }
 
index b233eaf..aaa48eb 100644 (file)
@@ -61,7 +61,7 @@ public class DefaultContextTest {
        public void contextLoads() {
                // Silence Sonar warning about missing assertion.
                Assertions.assertTrue(logger.isWarnEnabled());
-               logger.info("DefaultContextTest#contextLoads on default profile");
+               logger.info("contextLoads on default profile");
        }
 
 }
index 48aa084..4446c43 100644 (file)
@@ -54,7 +54,7 @@ public class PortalRestCentralServiceTest extends AbstractControllerTest {
        public void getAnalyticsTest() {
                // paths are hardcoded here exactly like the EPSDK-FW library :(
                URI uri = buildUri(null, PortalApiConstants.API_PREFIX, "/analytics");
-               logger.info("Invoking {}", uri);
+               logger.info("getAnalyticsTest invoking {}", uri);
                ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, null, String.class);
                // No Portal is available so this always fails
                Assertions.assertTrue(response.getStatusCode().is4xxClientError());
@@ -64,7 +64,7 @@ public class PortalRestCentralServiceTest extends AbstractControllerTest {
        public void getErrorPageTest() {
                // Send unauthorized request
                URI uri = buildUri(null, "/favicon.ico");
-               logger.info("Invoking {}", uri);
+               logger.info("getErrorPageTest invoking {}", uri);
                ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.GET, null, String.class);
                Assertions.assertTrue(response.getStatusCode().is4xxClientError());
                Assertions.assertTrue(response.getBody().contains("Static error page"));
@@ -100,6 +100,7 @@ public class PortalRestCentralServiceTest extends AbstractControllerTest {
                HttpEntity<Object> requestEntity = getEntityWithAuthHeaders(createEcompUser(loginId));
                ResponseEntity<String> response = restTemplate.exchange(create, HttpMethod.POST, requestEntity, String.class);
                logger.info("createUserTest response {}", response);
+               Assertions.assertNotNull(response);
                Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
        }
 
@@ -120,6 +121,7 @@ public class PortalRestCentralServiceTest extends AbstractControllerTest {
                logger.info("updateUserTest invoking {}", update);
                response = restTemplate.exchange(update, HttpMethod.POST, requestEntity, String.class);
                logger.info("updateUserTest response {}", response);
+               Assertions.assertNotNull(response);
                Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
        }