Merge "Fixed few security issues from the dependencies"
authorSunder Tattavarada <statta@research.att.com>
Thu, 18 Jun 2020 19:46:13 +0000 (19:46 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 18 Jun 2020 19:46:13 +0000 (19:46 +0000)
1  2 
ecomp-portal-BE-common/pom.xml
ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/MicroserviceProxyController.java
ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/ExternalAccessRolesControllerTest.java

                        <artifactId>jaxb-api</artifactId>
                        <version>2.4.0-b180830.0359</version>
                </dependency>
-               <dependency>
-                       <groupId>org.springframework.boot</groupId>
-                       <artifactId>spring-boot-starter</artifactId>
-                       <version>1.3.1.RELEASE</version>
-                       <exclusions>
-                               <exclusion>
-                                       <groupId>org.slf4j</groupId>
-                                       <artifactId>log4j-over-slf4j</artifactId>
-                               </exclusion>
-                       </exclusions>
-               </dependency>
+               
                <!-- Hibernate -->
                <dependency>
                        <groupId>org.hibernate</groupId>
                <dependency>
                        <groupId>com.fasterxml.jackson.core</groupId>
                        <artifactId>jackson-annotations</artifactId>
-                       <version>2.8.10</version>
+                       <version>2.10.0</version>
                </dependency>
                <dependency>
                        <groupId>com.fasterxml.jackson.core</groupId>
                        <artifactId>jackson-core</artifactId>
-                       <version>2.8.10</version>
+                       <version>2.10.0</version>
                </dependency>
                <dependency>
                        <groupId>com.fasterxml.jackson.core</groupId>
                        <artifactId>jackson-databind</artifactId>
-                       <version>2.8.11.4</version>
+                       <version>2.10.0</version>
                </dependency>
                <dependency>
                        <groupId>postgresql</groupId>
                                <artifactId>jersey-servlet</artifactId> 
                                </exclusion> 
                        </exclusions> 
 -      
 -                      
                </dependency>
                <dependency>
                        <groupId>org.projectlombok</groupId>
@@@ -53,7 -53,9 +53,7 @@@ import org.onap.portalsdk.core.logging.
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.EnableAspectJAutoProxy;
  import org.springframework.web.bind.annotation.PathVariable;
 -import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.GetMapping;
 -import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RestController;
  import org.springframework.web.client.HttpClientErrorException;
  
@@@ -103,9 -105,16 +103,16 @@@ public class MicroserviceProxyControlle
         */
        private boolean isValidJSON(String response) {
                try {
+                       if(response != null && !response.isEmpty())
+                       {
                        final ObjectMapper mapper = new ObjectMapper();
                        mapper.readTree(response);
                        return true;
+                       }
+                       else
+                       {
+                       return false;
+                       }
                } catch (IOException e) {
                        logger.debug(EELFLoggerDelegate.debugLogger, "isValidJSON failed", e);
                        return false;
@@@ -63,7 -63,6 +63,7 @@@ import org.onap.portalapp.portal.core.M
  import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
  import org.onap.portalapp.portal.domain.EPApp;
  import org.onap.portalapp.portal.domain.EPUser;
 +import org.onap.portalapp.portal.domain.EpAppType;
  import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
  import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
  import org.onap.portalapp.portal.framework.MockitoTestSuite;
@@@ -126,23 -125,23 +126,23 @@@ public class ExternalAccessRolesControl
                EPApp app = new EPApp();
                app.setName("Test");
                app.setImageUrl("test");
 -              app.setDescription("test");
 -              app.setNotes("test");
 -              app.setUrl("test");
 +              app.setAppDescription("test");
 +              app.setAppNotes("test");
 +              app.setLandingPage("test");
                app.setId((long) 1);
                app.setAppRestEndpoint("test");
 -              app.setAlternateUrl("test");
 +              app.setAlternateLandingPage("test");
                app.setName("test");
                app.setMlAppName("test");
                app.setMlAppAdminId("test");
 -              app.setUsername("test");
 -              app.setAppPassword("test");
 +              app.setAppBasicAuthUsername("test");
 +              app.setAppBasicAuthPassword("test");
                app.setOpen(false);
                app.setEnabled(false);
                app.setUebKey("test");
                app.setUebSecret("test");
                app.setUebTopicName("test");
 -              app.setAppType(1);
 +              app.setAppType(EpAppType.GUI);
                return app;
        }
  
                PrintWriter writer = new PrintWriter(sw);
                Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                List<EPApp> appList = new ArrayList<>();
                appList.add(app);
                Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
                String expectedCentralUser = "test";
                String loginId = "test";
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                List<EPApp> appList = new ArrayList<>();
                appList.add(app);
                Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
                String expectedCentralUser = null;
                String loginId = "test";
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                List<EPApp> appList = new ArrayList<>();
                appList.add(app);
                Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
                List<CentralV2Role> centralV2RoleList = new ArrayList<>();
                List<CentralRole> centralRoleList = new ArrayList<>();
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
                Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
                List<CentralV2Role> centralV2RoleList = new ArrayList<>();
                List<CentralRole> centralRoleList = new ArrayList<>();
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                ResponseEntity<String> response = null;
                Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
                List<EPApp> applicationList = new ArrayList<>();
                List<CentralV2Role> centralV2Role = new ArrayList<>();
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
                Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
                List<EPApp> applicationList = new ArrayList<>();
                List<CentralV2Role> centralV2Role = new ArrayList<>();
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                ResponseEntity<String> response = null;
                Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
                List<EPApp> applicationList = new ArrayList<>();
                List<CentralV2RoleFunction> centralV2RoleFunction = new ArrayList<>();
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
                Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
                List<EPApp> applicationList = new ArrayList<>();
                List<CentralV2RoleFunction> centralV2RoleFunction = new ArrayList<>();
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
                Mockito.when(externalAccessRolesService.getNameSpaceIfExists(applicationList.get(0))).thenReturn(response);
                long roleId = 1;
                CentralV2Role centralV2Role = new CentralV2Role.CentralV2RoleBuilder().createCentralV2Role();
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
                ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
                long roleId = 1;
                CentralV2Role centralV2Role = new CentralV2Role.CentralV2RoleBuilder().createCentralV2Role();
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
                ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
                CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
                centralV2RoleFunction.setCode("test");
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
                ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
                String code = "test";
                CentralV2RoleFunction centralV2RoleFunction = null;
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
                ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.FOUND);
        @Test
        public void getRoleFunctionTest() throws Exception {
                EPApp mockApp = mockApp();
 -              mockApp.setCentralAuth(true);
 +              mockApp.setRolesInAAF(true);
                List<EPApp> mockAppList = new ArrayList<>();
                mockAppList.add(mockApp);
                StringWriter sw = new StringWriter();
        public void getRoleFunctionXSSTest() throws Exception {
                String expected = getXSSKeyJson();
                EPApp mockApp = mockApp();
 -              mockApp.setCentralAuth(true);
 +              mockApp.setRolesInAAF(true);
                List<EPApp> mockAppList = new ArrayList<>();
                mockAppList.add(mockApp);
                StringWriter sw = new StringWriter();
        public void saveRoleFunctionExceptionTest() throws Exception {
                List<EPApp> applicationList = new ArrayList<>();
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
                PortalRestResponse<String> portalRestResponse = null;
                PortalRestResponse<String> expectedportalRestResponse = new PortalRestResponse<>();
-               expectedportalRestResponse.setMessage(null);
+               expectedportalRestResponse.setMessage("argument \"content\" is null");
                expectedportalRestResponse.setResponse("Failed");
                expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
                Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(uebKey);
                List<EPUser> userList = new ArrayList<>();
                userList.add(user);
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                JSONObject roleFunc = new JSONObject();
                roleFunc.put("type", "test_type");
                List<EPUser> userList = new ArrayList<>();
                userList.add(user);
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                JSONObject roleFunc = new JSONObject();
                roleFunc.put("type", "<script>alert(“XSS”)</script> ");
                List<EPUser> userList = new ArrayList<>();
                userList.add(user);
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                List<EPApp> appList = new ArrayList<>();
                appList.add(app);
                expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK);
                List<EPUser> userList = new ArrayList<>();
                userList.add(user);
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                List<EPApp> appList = new ArrayList<>();
                appList.add(app);
                String code = "<script>alert(‘XSS’)</script>";
        public void getActiveRolesValidationTest() throws Exception {
                List<CentralRole> expectedRolesList = null;
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                List<EPApp> appList = new ArrayList<>();
                appList.add(app);
                List<CentralV2Role> cenRoles = new ArrayList<>();
                Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
                List<EPApp> applicationList = new ArrayList<>();
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
                Mockito.when(externalAccessRolesService.getAllAppUsers(mockedRequest.getHeader(uebKey))).thenReturn(users);
                List<EPApp> applicationList = new ArrayList<>();
                EPApp app = mockApp();
                app.setUebKey("uebKey");
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
                ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
                List<EPApp> applicationList = new ArrayList<>();
                EPApp app = mockApp();
                app.setUebKey("uebKey");
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
                ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
        public void getEpUserExceptionTest() throws Exception {
                List<EPApp> applicationList = new ArrayList<>();
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
                StringWriter sw = new StringWriter();
                PrintWriter writer = new PrintWriter(sw);
                List<EPApp> applicationList = new ArrayList<>();
                EPApp app = mockApp();
                app.setUebKey("uebKey");
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
                ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
                List<EPApp> applicationList = new ArrayList<>();
                EPApp app = mockApp();
                app.setUebKey("uebKey");
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                applicationList.add(app);
                Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
                ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
        public void getEPRolesOfApplicationExceptionTest() throws Exception {
                List<EPApp> applicationList = new ArrayList<>();
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                Mockito.when(externalAccessRolesService.getApp(mockedRequest.getHeader(uebKey))).thenReturn(applicationList);
                StringWriter sw = new StringWriter();
                PrintWriter writer = new PrintWriter(sw);
                List<EPUser> userList = new ArrayList<>();
                userList.add(user);
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                List<EPApp> appList = new ArrayList<>();
                appList.add(app);
                expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK);
                List<EPUser> userList = new ArrayList<>();
                userList.add(user);
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                List<EPApp> appList = new ArrayList<>();
                appList.add(app);
                expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
                List<EPUser> userList = new ArrayList<>();
                userList.add(user);
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                List<EPApp> appList = new ArrayList<>();
                appList.add(app);
                expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
                List<EPUser> userList = new ArrayList<>();
                userList.add(user);
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                List<EPApp> appList = new ArrayList<>();
                appList.add(app);
                expectedportalRestResponse.setStatus(PortalRestStatusEnum.OK);
                List<EPUser> userList = new ArrayList<>();
                userList.add(user);
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                List<EPApp> appList = new ArrayList<>();
                appList.add(app);
                String code = "<img src=xss onerror=alert(1)>";
                List<EPUser> userList = new ArrayList<>();
                userList.add(user);
                EPApp app = mockApp();
 -              app.setCentralAuth(true);
 +              app.setRolesInAAF(true);
                List<EPApp> appList = new ArrayList<>();
                appList.add(app);
                expectedportalRestResponse.setStatus(PortalRestStatusEnum.ERROR);