From 2bd47b537ff4fa78ae8f38758900022df6344cdb Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E2=80=9CKruthi?= Date: Thu, 4 Jun 2020 19:34:07 +0530 Subject: [PATCH] Resubmitting KeyProperty code change since tests failed Change-Id: I14c0f9b59229e32de45b1652e64c01dd6c1d39e3 Issue-ID: PORTAL-914 Signed-off-by: krutbhat@att.com --- .../interceptor/PortalResourceInterceptor.java | 6 +++-- .../service/ApplicationsRestClientServiceImpl.java | 6 +++-- .../service/BasicAuthAccountServiceImpl.java | 6 +++-- .../portal/service/EPAppCommonServiceImpl.java | 6 +++-- .../service/MicroserviceProxyServiceImpl.java | 4 +++- .../portal/service/MicroserviceServiceImpl.java | 6 +++-- .../portalapp/portal/utils/EcompPortalUtils.java | 4 +++- .../service/sessionmgt/SessionCommunication.java | 4 +++- .../service/BasicAuthAccountServiceImplTest.java | 14 +++++++---- .../service/MicroserviceServiceImplTest.java | 20 +++++++++------- .../service/RemoteWebServiceCallServiceImpl.java | 9 ++++---- .../org/onap/portalapp/util/SessionCookieUtil.java | 7 +++--- .../RemoteWebServiceCallServiceImplTest.java | 27 ++++++++++++---------- 13 files changed, 73 insertions(+), 46 deletions(-) diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java index 5a57e094..e96485d8 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java @@ -72,6 +72,8 @@ import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler; import org.onap.portalsdk.core.onboarding.util.AuthUtil; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; import org.onap.portalsdk.core.util.SystemProperties; @@ -370,7 +372,7 @@ public class PortalResourceInterceptor extends ResourceInterceptor { String result = ""; if (encrypted != null && encrypted.length() > 0) { try { - result = CipherUtil.decryptPKC(encrypted, SystemProperties.getProperty(SystemProperties.Decryption_Key)); + result = CipherUtil.decryptPKC(encrypted, KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "decryptedPassword failed", e); throw e; @@ -384,7 +386,7 @@ public class PortalResourceInterceptor extends ResourceInterceptor { if (decryptedPwd != null && decryptedPwd.length() > 0) { try { result = CipherUtil.encryptPKC(decryptedPwd, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "encryptedPassword() failed", e); throw e; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java index 959e392f..ab504fba 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java @@ -67,6 +67,8 @@ import org.onap.portalapp.util.SystemType; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.exception.CipherUtilException; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.util.SystemProperties; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; @@ -194,7 +196,7 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient if(!encriptedPwd.isEmpty() || encriptedPwd != null || StringUtils.isEmpty(encriptedPwd)){ try { decreptedAppPwd = CipherUtil.decryptPKC(encriptedPwd, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "createClientFor failed to decrypt", e); } @@ -215,7 +217,7 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient String decreptedexternalAppPwd = StringUtils.EMPTY; try { decreptedexternalAppPwd = CipherUtil.decryptPKC(password, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (CipherUtilException e) { logger.error(EELFLoggerDelegate.errorLogger, "failed to decreptedexternalAppPwd when external app pwd is null", e); } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImpl.java index 98b0f127..151430d3 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImpl.java @@ -52,6 +52,8 @@ import org.onap.portalapp.portal.utils.EPCommonSystemProperties; import org.onap.portalapp.validation.DataValidator; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.beans.factory.annotation.Autowired; @@ -229,7 +231,7 @@ public class BasicAuthAccountServiceImpl implements BasicAuthAccountService{ if (encryptedPwd != null && encryptedPwd.length() > 0) { try { result = CipherUtil.decryptPKC(encryptedPwd, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "decryptedPassword() failed", e); throw e; @@ -243,7 +245,7 @@ public class BasicAuthAccountServiceImpl implements BasicAuthAccountService{ if (decryptedPwd != null && decryptedPwd.length() > 0) { try { result = CipherUtil.encryptPKC(decryptedPwd, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "encryptedPassword() failed", e); throw e; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java index 539ada26..0e8bdeee 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java @@ -94,6 +94,8 @@ import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.ueb.Helper; import org.onap.portalsdk.core.onboarding.ueb.TopicManager; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; import org.onap.portalsdk.core.service.DataAccessService; @@ -1630,7 +1632,7 @@ public class EPAppCommonServiceImpl implements EPAppService { if (encryptedAppPwd != null && !encryptedAppPwd.isEmpty()) { try { result = CipherUtil.decryptPKC(encryptedAppPwd, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "decryptedPassword failed for app " + app.getName(), e); } @@ -1643,7 +1645,7 @@ public class EPAppCommonServiceImpl implements EPAppService { if (decryptedAppPwd != null && !decryptedAppPwd.isEmpty()) { try { result = CipherUtil.encryptPKC(decryptedAppPwd, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "encryptedPassword failed for app " + app.getName(), e); } diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceProxyServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceProxyServiceImpl.java index 31cb8a45..df8b59d8 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceProxyServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceProxyServiceImpl.java @@ -50,6 +50,8 @@ import org.onap.portalapp.portal.logging.aop.EPMetricsLog; import org.onap.portalapp.portal.utils.EcompPortalUtils; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.EnableAspectJAutoProxy; @@ -177,7 +179,7 @@ public class MicroserviceProxyServiceImpl implements MicroserviceProxyService { if (encryptedPwd != null && encryptedPwd.length() > 0) { try { result = CipherUtil.decryptPKC(encryptedPwd, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "decryptedPassword failed", e); throw e; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceServiceImpl.java index 451500d6..9d9fde3a 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceServiceImpl.java @@ -52,6 +52,8 @@ import org.onap.portalapp.portal.logging.aop.EPMetricsLog; import org.onap.portalapp.portal.utils.EPCommonSystemProperties; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.beans.factory.annotation.Autowired; @@ -197,7 +199,7 @@ public class MicroserviceServiceImpl implements MicroserviceService { if (encryptedPwd != null && !encryptedPwd.isEmpty()) { try { result = CipherUtil.decryptPKC(encryptedPwd, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "decryptedPassword failed", e); throw e; @@ -211,7 +213,7 @@ public class MicroserviceServiceImpl implements MicroserviceService { if (decryptedPwd != null && !decryptedPwd.isEmpty()) { try { result = CipherUtil.encryptPKC(decryptedPwd, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "encryptedPassword failed", e); throw e; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java index e5543a36..3fc8c393 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/EcompPortalUtils.java @@ -61,6 +61,8 @@ import org.onap.portalapp.portal.logging.format.EPAppMessagesEnum; import org.onap.portalapp.portal.logging.logic.EPLogUtil; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.util.SystemProperties; import org.slf4j.MDC; import org.springframework.http.HttpHeaders; @@ -435,7 +437,7 @@ public class EcompPortalUtils { if (encrypted != null && encrypted.length() > 0) { try { result = CipherUtil.decryptPKC(encrypted, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "decryptedPassword failed", e); throw e; diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/service/sessionmgt/SessionCommunication.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/service/sessionmgt/SessionCommunication.java index 441e99a7..f65199c7 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/service/sessionmgt/SessionCommunication.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/service/sessionmgt/SessionCommunication.java @@ -61,6 +61,8 @@ import org.onap.portalsdk.core.exception.UrlAccessRestrictedException; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.exception.CipherUtilException; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.util.SystemProperties; import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; @@ -344,7 +346,7 @@ public class SessionCommunication { String decreptedexternalAppPwd = StringUtils.EMPTY; try { decreptedexternalAppPwd = CipherUtil.decryptPKC(password, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } catch (CipherUtilException e) { logger.error(EELFLoggerDelegate.errorLogger, "failed to decreptedexternalAppPwd when external app pwd is null", e); } diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImplTest.java index 6382bef4..a905ca81 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImplTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/BasicAuthAccountServiceImplTest.java @@ -42,6 +42,8 @@ import org.onap.portalapp.portal.domain.EPEndpoint; import org.onap.portalapp.portal.domain.EPEndpointAccount; import org.onap.portalapp.portal.framework.MockitoTestSuite; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.service.DataAccessServiceImpl; import org.onap.portalsdk.core.util.SystemProperties; @@ -51,7 +53,7 @@ import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) -@PrepareForTest({ CipherUtil.class , SystemProperties.class}) +@PrepareForTest({ CipherUtil.class , SystemProperties.class, KeyProperties.class, KeyConstants.class}) public class BasicAuthAccountServiceImplTest { @Mock DataAccessService dataAccessService = new DataAccessServiceImpl(); @@ -92,11 +94,12 @@ public class BasicAuthAccountServiceImplTest { @Test public void saveBasicAuthAccountTest_password() throws Exception{ PowerMockito.mockStatic(CipherUtil.class); - PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); BasicAuthCredentials credentials = new BasicAuthCredentials(); credentials.setPassword("password"); String result = null; - Mockito.when(CipherUtil.encryptPKC("password", SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenReturn(result); + Mockito.when(CipherUtil.encryptPKC("password", KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY))).thenReturn(result); basicAuthAccountServiceImpl.saveBasicAuthAccount(credentials); } @@ -163,7 +166,8 @@ public class BasicAuthAccountServiceImplTest { @Test public void getAccountDataTest_password() throws Exception { PowerMockito.mockStatic(CipherUtil.class); - PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); List list = new ArrayList<>(); BasicAuthCredentials basicAuthCredentials = new BasicAuthCredentials(); basicAuthCredentials.setPassword("password"); @@ -171,7 +175,7 @@ public class BasicAuthAccountServiceImplTest { Mockito.when((List) dataAccessService.getList(BasicAuthCredentials.class, null)) .thenReturn(list); String result = null; - Mockito.when(CipherUtil.decryptPKC("password", SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenReturn(result); + Mockito.when(CipherUtil.decryptPKC("password", KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY))).thenReturn(result); } diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/MicroserviceServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/MicroserviceServiceImplTest.java index ae813152..bc8d4548 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/MicroserviceServiceImplTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/MicroserviceServiceImplTest.java @@ -58,6 +58,8 @@ import org.onap.portalapp.portal.domain.MicroserviceData; import org.onap.portalapp.portal.domain.MicroserviceParameter; import org.onap.portalapp.portal.utils.EPCommonSystemProperties; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.service.DataAccessServiceImpl; import org.onap.portalsdk.core.util.SystemProperties; @@ -66,7 +68,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) -@PrepareForTest({Criterion.class, Restrictions.class, CipherUtil.class, EPCommonSystemProperties.class, SystemProperties.class, Restrictions.class}) +@PrepareForTest({Criterion.class, Restrictions.class, CipherUtil.class, EPCommonSystemProperties.class, SystemProperties.class, KeyProperties.class, KeyConstants.class}) public class MicroserviceServiceImplTest { private static final String TEST="test"; @@ -150,6 +152,8 @@ public class MicroserviceServiceImplTest { PowerMockito.mockStatic(CipherUtil.class); PowerMockito.mockStatic(Restrictions.class); PowerMockito.mockStatic(Criterion.class); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); List microserviceParameters = new ArrayList<>(); MicroserviceData microserviceData = new MicroserviceData(); MicroserviceParameter microserviceParameter = new MicroserviceParameter(); @@ -168,8 +172,7 @@ public class MicroserviceServiceImplTest { Criterion serviceIdCriterion = Restrictions.eq("serviceId", 1l); restrictionsList2.add(serviceIdCriterion); Mockito.when((List) dataAccessService.getList(MicroserviceParameter.class, null, restrictionsList2, null)).thenReturn(microserviceParameters); - Mockito.when(CipherUtil.decryptPKC("xyz", - SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenReturn("abc"); + Mockito.when(CipherUtil.decryptPKC("xyz",KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY))).thenReturn("abc"); List actual = microserviceServiceImpl.getMicroserviceData(); assertNotNull(actual); } @@ -181,6 +184,8 @@ public class MicroserviceServiceImplTest { PowerMockito.mockStatic(CipherUtil.class); PowerMockito.mockStatic(Restrictions.class); PowerMockito.mockStatic(Criterion.class); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); List microserviceParameters = new ArrayList<>(); MicroserviceData microserviceData = new MicroserviceData(); MicroserviceParameter microserviceParameter = new MicroserviceParameter(); @@ -199,8 +204,7 @@ public class MicroserviceServiceImplTest { Criterion serviceIdCriterion = Restrictions.eq("serviceId", 1l); restrictionsList2.add(serviceIdCriterion); Mockito.when((List) dataAccessService.getList(MicroserviceParameter.class, null, restrictionsList2, null)).thenReturn(microserviceParameters); - Mockito.when(CipherUtil.decryptPKC("xyz", - SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenThrow(BadPaddingException.class); + Mockito.when(CipherUtil.decryptPKC("xyz",KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY))).thenThrow(BadPaddingException.class); List actual = microserviceServiceImpl.getMicroserviceData(); assertNotNull(actual); } @@ -220,10 +224,10 @@ public class MicroserviceServiceImplTest { PowerMockito.mockStatic(CipherUtil.class); Criterion serviceIdCriterion = Restrictions.eq("serviceId", 1l); restrictionsList.add(serviceIdCriterion); - PowerMockito.mockStatic(SystemProperties.class); - Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(TEST); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); + Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(TEST); Mockito.when(CipherUtil.encryptPKC(TEST, TEST)).thenReturn(TEST); - Mockito.when((List) dataAccessService.getList(MicroserviceParameter.class, null, restrictionsList, null)).thenReturn(microserviceParameters); microserviceServiceImpl.updateMicroservice(1l, buildData()); diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/service/RemoteWebServiceCallServiceImpl.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/service/RemoteWebServiceCallServiceImpl.java index 8b92b58c..59c4f7a4 100644 --- a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/service/RemoteWebServiceCallServiceImpl.java +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/service/RemoteWebServiceCallServiceImpl.java @@ -38,13 +38,13 @@ package org.onap.portalapp.service; import java.util.List; - import org.onap.portalapp.portal.domain.EPApp; import org.onap.portalapp.service.RemoteWebServiceCallService; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.service.WebServiceCallServiceImpl; -import org.onap.portalsdk.core.util.SystemProperties; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -68,11 +68,10 @@ public class RemoteWebServiceCallServiceImpl extends WebServiceCallServiceImpl i logger.warn(EELFLoggerDelegate.errorLogger, "Failed to find application with UEB key " + requestUebKey); return false; } - + String encryptedPwdDB = appRecord.getAppBasicAuthPassword(); String appUserName = appRecord.getAppBasicAuthUsername(); - String decryptedPwd = CipherUtil.decryptPKC(encryptedPwdDB, - secretKey == null ? SystemProperties.getProperty(SystemProperties.Decryption_Key) : secretKey); + String decryptedPwd = CipherUtil.decryptPKC(encryptedPwdDB,secretKey == null ? KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY) : secretKey); if (decryptedPwd.equals(requestPassword) && appUserName.equals(requestAppName)) return true; else diff --git a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/util/SessionCookieUtil.java b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/util/SessionCookieUtil.java index 1a347e07..05765021 100644 --- a/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/util/SessionCookieUtil.java +++ b/ecomp-portal-BE-os/src/main/java/org/onap/portalapp/util/SessionCookieUtil.java @@ -43,7 +43,8 @@ import javax.servlet.http.HttpServletResponse; import org.onap.portalapp.portal.utils.EPCommonSystemProperties; import org.onap.portalsdk.core.onboarding.util.CipherUtil; -import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; public class SessionCookieUtil extends CommonSessionCookieUtil{ @@ -72,7 +73,7 @@ public class SessionCookieUtil extends CommonSessionCookieUtil{ HttpServletResponse response,String userId) throws Exception { logger.info("************** session cookie util set up UserId cookie begins"); userId = CipherUtil.encrypt(userId, - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); Cookie cookie1 = new Cookie(USER_ID, userId); cookie1.setSecure(true); cookie1.setMaxAge(cookieMaxAge); @@ -93,7 +94,7 @@ public class SessionCookieUtil extends CommonSessionCookieUtil{ userIdcookie = cookie; if(userIdcookie!=null){ userId = CipherUtil.decrypt(userIdcookie.getValue(), - SystemProperties.getProperty(SystemProperties.Decryption_Key)); + KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)); } logger.info("************** session cookie util set up EP cookie completed"); diff --git a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java index 5b7f7d45..1f346459 100644 --- a/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java +++ b/ecomp-portal-BE-os/src/test/java/org/onap/portalapp/portal/service/RemoteWebServiceCallServiceImplTest.java @@ -57,6 +57,8 @@ import org.onap.portalapp.portal.domain.EPApp; import org.onap.portalapp.portal.framework.MockitoTestSuite; import org.onap.portalapp.service.RemoteWebServiceCallServiceImpl; import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.KeyConstants; +import org.onap.portalsdk.core.onboarding.util.KeyProperties; import org.onap.portalsdk.core.service.DataAccessService; import org.onap.portalsdk.core.util.SystemProperties; import org.powermock.api.mockito.PowerMockito; @@ -64,7 +66,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) -@PrepareForTest({ CipherUtil.class , SystemProperties.class}) +@PrepareForTest({ CipherUtil.class , SystemProperties.class, KeyProperties.class, KeyConstants.class}) public class RemoteWebServiceCallServiceImplTest { @@ -93,7 +95,8 @@ public class RemoteWebServiceCallServiceImplTest { public void verifyRESTCredentialTest() throws Exception { PowerMockito.mockStatic(CipherUtil.class); - PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); String criteria= " where ueb_key = 'requestUebKey'"; List appList = new ArrayList<>(); EPApp app = new EPApp(); @@ -101,9 +104,8 @@ public class RemoteWebServiceCallServiceImplTest { appList.add(app); Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList); String secretKey = null; - Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey); - Mockito.when(CipherUtil.decryptPKC("password", - secretKey == null ? null : secretKey)).thenReturn("pwd"); + Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(secretKey); + Mockito.when(CipherUtil.decryptPKC("password",secretKey == null ? null : secretKey)).thenReturn("pwd"); assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","requestPassword")); } @@ -111,7 +113,8 @@ public class RemoteWebServiceCallServiceImplTest { public void verifyRESTCredentialExceptionTest() throws Exception { PowerMockito.mockStatic(CipherUtil.class); - PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); String criteria= " where ueb_key = 'requestUebKey'"; List appList = new ArrayList<>(); EPApp app = new EPApp(); @@ -120,9 +123,8 @@ public class RemoteWebServiceCallServiceImplTest { appList.add(app); Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(appList); String secretKey = null; - Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey); - Mockito.when(CipherUtil.decryptPKC("password", - secretKey == null ? null : secretKey)).thenReturn("pwd"); + Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(secretKey); + Mockito.when(CipherUtil.decryptPKC("password",secretKey == null ? null : secretKey)).thenReturn("pwd"); assertTrue(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd")); } @@ -131,6 +133,8 @@ public class RemoteWebServiceCallServiceImplTest { { PowerMockito.mockStatic(CipherUtil.class); PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(KeyProperties.class); + PowerMockito.mockStatic(KeyConstants.class); String criteria= " where ueb_key = 'requestUebKey'"; List appList = new ArrayList<>(); EPApp app = new EPApp(); @@ -139,9 +143,8 @@ public class RemoteWebServiceCallServiceImplTest { appList.add(app); Mockito.when(dataAccessService.getList(EPApp.class, criteria.toString(), null, null)).thenReturn(null); String secretKey = null; - Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey); - Mockito.when(CipherUtil.decryptPKC("password", - secretKey == null ? null : secretKey)).thenReturn("pwd"); + Mockito.when(KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY)).thenReturn(secretKey); + Mockito.when(CipherUtil.decryptPKC("password",secretKey == null ? null : secretKey)).thenReturn("pwd"); assertFalse(remoteWebServiceCallServiceImpl.verifyRESTCredential(secretKey,"requestUebKey","requestAppName","pwd")); } -- 2.16.6