Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: Iece4430f2ebceb8bfb1ea1a89c541335e2f35b11
Issue-ID: SDC-4165
private Properties buildProperties(DmaapConsumerConfiguration parameters) throws GeneralSecurityException, IOException {
Properties props = new Properties();
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");
}
if (passkey.isRight()) {
throw new GeneralSecurityException("invalid password, cannot build properties");
}
private Properties buildProducerProperties(DmaapProducerConfiguration parameters) throws GeneralSecurityException, IOException {
logger.info("The DmaapProducerConfiguration is {} ", parameters);
Properties props = new Properties();
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");
}
if (passkey.isRight()) {
throw new GeneralSecurityException("invalid password, cannot build properties");
}
import java.util.Arrays;
import java.util.HashSet;
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;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.onap.sdc.security.AuthenticationCookie;
}
protected void setUserContext(HttpServletRequest httpRequest) {
}
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 {
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) {
} 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());
}
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");
ThreadLocalsHolder.setUserContext(userContext);
} else {
log.debug("user_id value in req header is null, userContext will not be initialized");
private void setPassword(String password, boolean isEncoded) {
validate(password);
if (isEncoded) {
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 {
if (passkey.isLeft()) {
this.password = passkey.left().value();
} else {
private void setKeyStorePassword(String keyStorePassword, boolean isEncoded) {
validate(keyStorePassword);
if (isEncoded) {
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 {
if (passkey.isLeft()) {
this.keyStorePassword = passkey.left().value();
} else {
private HttpClientConfig prepareTestClientConfig() {
final String testUserName = "testUser";
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 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();
testNumOfRetries = 10;
testHeaders = Collections.emptyMap();
private HttpClientConfigImmutable prepareTestClientConfigImmutable() {
final String testUserName = "testUser";
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 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);
int testNumOfRetries = 10;
ComparableHttpRequestRetryHandler testRetryHandler = Mockito.mock(ComparableHttpRequestRetryHandler.class);
@Test
public void validateFactoryCreatesValidHttpClientConnectionManager() {
final String testKeyStore = "testKeyStore ";
@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);
ClientCertificate clientCertificate = new ClientCertificate();
clientCertificate.setKeyStore(testKeyStore);
<joda.time.version>2.9.9</joda.time.version>
<!--sdc-security-utils-->
<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>
<!--jacoco-->
<jacoco.version>0.8.7</jacoco.version>