Add asserts to silence Sonar warnings re tests
[portal/ric-dashboard.git] / webapp-backend / src / test / java / org / oransc / ric / portal / dashboard / config / WebSecurityMockConfiguration.java
index 8d06693..257b4a4 100644 (file)
@@ -2,7 +2,7 @@
  * ========================LICENSE_START=================================
  * O-RAN-SC
  * %%
- * Copyright (C) 2019 AT&T Intellectual Property and Nokia
+ * Copyright (C) 2019 AT&T Intellectual Property
  * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 package org.oransc.ric.portal.dashboard.config;
 
-import java.io.File;
-import java.io.IOException;
 import java.lang.invoke.MethodHandles;
-import java.util.HashSet;
-import java.util.Set;
 
-import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
-import org.onap.portalsdk.core.restful.domain.EcompRole;
-import org.onap.portalsdk.core.restful.domain.EcompUser;
+import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestCentralService;
 import org.oransc.ric.portal.dashboard.DashboardConstants;
-import org.oransc.ric.portal.dashboard.LoginServlet;
-import org.oransc.ric.portal.dashboard.portalapi.DashboardUserManager;
+import org.oransc.ric.portal.dashboard.portalapi.PortalAuthManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.web.servlet.ServletRegistrationBean;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Profile;
@@ -58,12 +50,18 @@ public class WebSecurityMockConfiguration extends WebSecurityConfigurerAdapter {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-       public WebSecurityMockConfiguration(@Value("${userfile}") final String userFilePath) {
-               logger.debug("ctor: user file path {}", userFilePath);
-       }
+       // Although constructor arguments are recommended over field injection,
+       // this results in fewer lines of code.
+       @Value("${portalapi.decryptor}")
+       private String decryptor;
+       @Value("${portalapi.usercookie}")
+       private String userCookie;
+       @Value("${userfile}")
+       private String userFilePath;
 
        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
+               logger.debug("configure");
                PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
                auth.inMemoryAuthentication() //
                                .passwordEncoder(encoder) //
@@ -93,34 +91,11 @@ public class WebSecurityMockConfiguration extends WebSecurityConfigurerAdapter {
        }
 
        @Bean
-       public ServletRegistrationBean<LoginServlet> loginServlet() {
-               LoginServlet servlet = new LoginServlet();
-               final ServletRegistrationBean<LoginServlet> servletBean = new ServletRegistrationBean<>(servlet,
-                               DashboardConstants.LOGIN_PAGE);
-               servletBean.setName("LoginServlet");
-               return servletBean;
-       }
-
-       // This implementation is so light it can be used during tests.
-       @Bean
-       public DashboardUserManager dashboardUserManager() throws IOException, PortalAPIException {
-               File f = new File("/tmp/users.json");
-               if (f.exists())
-                       f.delete();
-               DashboardUserManager um = new DashboardUserManager(f.getAbsolutePath());
-               // Mock user for convenience in testing
-               EcompUser demo = new EcompUser();
-               demo.setLoginId("demo");
-               demo.setFirstName("Demo");
-               demo.setLastName("User");
-               demo.setActive(true);
-               EcompRole role = new EcompRole();
-               role.setName("view");
-               Set<EcompRole> roles = new HashSet<>();
-               roles.add(role);
-               demo.setRoles(roles);
-               um.createUser(demo);
-               return um;
+       public PortalAuthManager portalAuthManagerBean() throws Exception {
+               logger.debug("portalAuthManagerBean");
+               return new PortalAuthManager(IPortalRestCentralService.CREDENTIALS_APP,
+                               IPortalRestCentralService.CREDENTIALS_USER, IPortalRestCentralService.CREDENTIALS_PASS, decryptor,
+                               userCookie);
        }
 
 }