Skip to content

Commit

Permalink
fix new SonarCloud issues (#3723)
Browse files Browse the repository at this point in the history
Signed-off-by: nx673747 <[email protected]>
Co-authored-by: nx673747 <[email protected]>
  • Loading branch information
nxhafa and nx673747 authored Sep 2, 2024
1 parent 784ae83 commit 40b8545
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
import org.apache.hc.core5.http.config.Registry;
import org.apache.hc.core5.http.config.RegistryBuilder;
import org.apache.hc.core5.util.Timeout;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import org.zowe.apiml.security.*;
import org.zowe.apiml.security.ApimlPoolingHttpClientConnectionManager;
import org.zowe.apiml.security.HttpsConfig;
import org.zowe.apiml.security.HttpsConfigError;
import org.zowe.apiml.security.HttpsFactory;
import org.zowe.apiml.security.SecurityUtils;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
Expand Down Expand Up @@ -189,7 +192,6 @@ public void run() {
}

@Bean
@Qualifier("publicKeyCertificatesBase64")
public Set<String> publicKeyCertificatesBase64() {
return publicKeyCertificatesBase64;
}
Expand All @@ -202,7 +204,6 @@ public Set<String> publicKeyCertificatesBase64() {
*/
@Bean
@Primary
@Qualifier("restTemplateWithKeystore")
public RestTemplate restTemplateWithKeystore() {
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(secureHttpClient);
factory.setConnectionRequestTimeout(requestConnectionTimeout);
Expand All @@ -218,7 +219,6 @@ public RestTemplate restTemplateWithKeystore() {
* @return default RestTemplate, which doesn't use certificate from keystore
*/
@Bean
@Qualifier("restTemplateWithoutKeystore")
public RestTemplate restTemplateWithoutKeystore() {
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(secureHttpClientWithoutKeystore);
factory.setConnectionRequestTimeout(requestConnectionTimeout);
Expand All @@ -229,9 +229,8 @@ public RestTemplate restTemplateWithoutKeystore() {
/**
* @return HttpClient which use a certificate to authenticate
*/
@Bean
@Bean("secureHttpClientWithKeystore")
@Primary
@Qualifier("secureHttpClientWithKeystore")
public CloseableHttpClient secureHttpClient() {
return secureHttpClient;
}
Expand All @@ -240,7 +239,6 @@ public CloseableHttpClient secureHttpClient() {
* @return HttpClient, which doesn't use a certificate to authenticate
*/
@Bean
@Qualifier("secureHttpClientWithoutKeystore")
public CloseableHttpClient secureHttpClientWithoutKeystore() {
return secureHttpClientWithoutKeystore;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,23 @@ private void keyNotInCache() {
throw new StorageException(Messages.KEY_NOT_PROVIDED.getKey(), Messages.KEY_NOT_PROVIDED.getStatus());
}

private void invalidPayload(String keyValue, String message) {
throw new StorageException(Messages.INVALID_PAYLOAD.getKey(), Messages.INVALID_PAYLOAD.getStatus(),
private StorageException invalidPayloadException(String keyValue, String message) {
return new StorageException(Messages.INVALID_PAYLOAD.getKey(), Messages.INVALID_PAYLOAD.getStatus(),
keyValue, message);
}

private void checkForInvalidPayload(KeyValue keyValue) {
if (keyValue == null) {
invalidPayload(null, "No KeyValue provided in the payload");
throw invalidPayloadException(null, "No KeyValue provided in the payload");
}

if (keyValue.getValue() == null) {
invalidPayload(keyValue.toString(), "No value provided in the payload");
throw invalidPayloadException(keyValue.toString(), "No value provided in the payload");
}

String key = keyValue.getKey();
if (key == null) {
invalidPayload(keyValue.toString(), "No key provided in the payload");
throw invalidPayloadException(keyValue.toString(), "No key provided in the payload");
}
}

Expand Down

0 comments on commit 40b8545

Please sign in to comment.