Update SDC with new 'security-util-lib' version 55/130755/1
authorvasraz <vasyl.razinkov@est.tech>
Tue, 6 Sep 2022 12:08:14 +0000 (13:08 +0100)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Tue, 6 Sep 2022 12:08:56 +0000 (12:08 +0000)
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: Iece4430f2ebceb8bfb1ea1a89c541335e2f35b11
Issue-ID: SDC-4165

catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DmaapClientFactory.java
catalog-be/src/main/java/org/openecomp/sdc/be/filters/ThreadLocalUtils.java
common-app-api/src/main/java/org/openecomp/sdc/common/http/config/BasicAuthorization.java
common-app-api/src/main/java/org/openecomp/sdc/common/http/config/ClientCertificate.java
common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpClientConfigImmutableTest.java
common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpClientFactoryTest.java
common-app-api/src/test/java/org/openecomp/sdc/common/http/client/api/HttpConnectionMngFactoryTest.java
pom.xml

index 0f4836e..6549b54 100644 (file)
@@ -70,7 +70,7 @@ public class DmaapClientFactory {
 
     private Properties buildProperties(DmaapConsumerConfiguration parameters) throws GeneralSecurityException, IOException {
         Properties props = new Properties();
-        Either<String, String> passkey = SecurityUtil.INSTANCE.decrypt(parameters.getCredential().getPassword());
+        Either<String, String> passkey = SecurityUtil.decrypt(parameters.getCredential().getPassword());
         if (passkey.isRight()) {
             throw new GeneralSecurityException("invalid password, cannot build properties");
         }
@@ -119,7 +119,7 @@ public class DmaapClientFactory {
     private Properties buildProducerProperties(DmaapProducerConfiguration parameters) throws GeneralSecurityException, IOException {
         logger.info("The DmaapProducerConfiguration is {} ", parameters);
         Properties props = new Properties();
-        Either<String, String> passkey = SecurityUtil.INSTANCE.decrypt(parameters.getCredential().getPassword());
+        Either<String, String> passkey = SecurityUtil.decrypt(parameters.getCredential().getPassword());
         if (passkey.isRight()) {
             throw new GeneralSecurityException("invalid password, cannot build properties");
         }
index 1cd84d0..42b0291 100644 (file)
@@ -21,6 +21,8 @@ package org.openecomp.sdc.be.filters;
 
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 import javax.servlet.http.HttpServletRequest;
 import org.onap.sdc.security.AuthenticationCookie;
@@ -52,18 +54,19 @@ public class ThreadLocalUtils implements IUsersThreadLocalHolder {
     }
 
     protected void setUserContext(HttpServletRequest httpRequest) {
-        String user_id = httpRequest.getHeader(Constants.USER_ID_HEADER);
-        if (user_id != null) {
-            String userRolesFromPortal = null;
+        final String userId = httpRequest.getHeader(Constants.USER_ID_HEADER);
+        if (userId != null) {
             Set<String> roles = null;
             try {
-                userRolesFromPortal = portalClient.fetchUserRolesFromPortal(user_id);
-                roles = new HashSet<>(Arrays.asList(userRolesFromPortal));
+                final Optional<String> userRolesFromPortalOptional = portalClient.fetchUserRolesFromPortal(userId);
+                if (userRolesFromPortalOptional.isPresent()){
+                    roles = new HashSet<>(List.of(userRolesFromPortalOptional.get()));
+                }
             } catch (RestrictionAccessFilterException e) {
-                log.debug("Failed to fetch user ID - {} from portal", user_id);
+                log.debug("Failed to fetch user ID - {} from portal", userId);
                 log.debug(e.getMessage());
             }
-            UserContext userContext = new UserContext(user_id, roles, null, null);
+            final UserContext userContext = new UserContext(userId, roles, null, null);
             ThreadLocalsHolder.setUserContext(userContext);
         } else {
             log.debug("user_id value in req header is null, userContext will not be initialized");
index c914771..4e0af9c 100644 (file)
@@ -56,7 +56,7 @@ public class BasicAuthorization {
     private void setPassword(String password, boolean isEncoded) {
         validate(password);
         if (isEncoded) {
-            Either<String, String> passkey = SecurityUtil.INSTANCE.decrypt(password);
+            Either<String, String> passkey = SecurityUtil.decrypt(password);
             if (passkey.isLeft()) {
                 this.password = passkey.left().value();
             } else {
index 510c0a2..93fc3b9 100644 (file)
@@ -41,7 +41,7 @@ public class ClientCertificate {
     private void setKeyStorePassword(String keyStorePassword, boolean isEncoded) {
         validate(keyStorePassword);
         if (isEncoded) {
-            Either<String, String> passkey = SecurityUtil.INSTANCE.decrypt(keyStorePassword);
+            Either<String, String> passkey = SecurityUtil.decrypt(keyStorePassword);
             if (passkey.isLeft()) {
                 this.keyStorePassword = passkey.left().value();
             } else {
index 2593a00..e3c5eca 100644 (file)
@@ -128,10 +128,10 @@ public class HttpClientConfigImmutableTest {
 
     private HttpClientConfig prepareTestClientConfig() {
         final String testUserName = "testUser";
-        final String testUserPassword = SecurityUtil.INSTANCE.encrypt("testPassword").left().value();
+        final String testUserPassword = SecurityUtil.encrypt("testPassword").left().value();
         final int timeouts = 10;
         final String testKeyStore = "testKeyStore";
-        final String testKeyStorePassword = SecurityUtil.INSTANCE.encrypt("testKeyStorePassword").left().value();
+        final String testKeyStorePassword = SecurityUtil.encrypt("testKeyStorePassword").left().value();
 
         testNumOfRetries = 10;
         testHeaders = Collections.emptyMap();
index c39bef0..4958202 100644 (file)
@@ -51,10 +51,10 @@ public class HttpClientFactoryTest {
 
     private HttpClientConfigImmutable prepareTestClientConfigImmutable() {
         final String testUserName = "testUser";
-        final String testUserPassword = SecurityUtil.INSTANCE.encrypt("testPassword").left().value();
+        final String testUserPassword = SecurityUtil.encrypt("testPassword").left().value();
         final int timeouts = 10;
         final String testKeyStore = "testKeyStore";
-        final String testKeyStorePassword = SecurityUtil.INSTANCE.encrypt("testKeyStorePassword").left().value();
+        final String testKeyStorePassword = SecurityUtil.encrypt("testKeyStorePassword").left().value();
 
         int testNumOfRetries = 10;
         ComparableHttpRequestRetryHandler testRetryHandler = Mockito.mock(ComparableHttpRequestRetryHandler.class);
index 2813d57..deca8a6 100644 (file)
@@ -32,7 +32,7 @@ public class HttpConnectionMngFactoryTest {
     @Test
     public void validateFactoryCreatesValidHttpClientConnectionManager() {
         final String testKeyStore = "testKeyStore ";
-        final String testKeyStorePassword = SecurityUtil.INSTANCE.encrypt("testKeyStorePassword").left().value();
+        final String testKeyStorePassword = SecurityUtil.encrypt("testKeyStorePassword").left().value();
 
         ClientCertificate clientCertificate = new ClientCertificate();
         clientCertificate.setKeyStore(testKeyStore);
diff --git a/pom.xml b/pom.xml
index 2cc4544..96678d4 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -175,7 +175,7 @@ Modifications copyright (c) 2018-2019 Nokia
         <joda.time.version>2.9.9</joda.time.version>
 
         <!--sdc-security-utils-->
-        <security.util.lib.version>1.6.0</security.util.lib.version>
+        <security.util.lib.version>1.7.0</security.util.lib.version>
         <!--jacoco-->
         <jacoco.version>0.8.7</jacoco.version>