Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
*/
package org.zowe.apiml.zaasclient.config;

import lombok.Builder;
import lombok.Data;
import lombok.experimental.Tolerate;

@Data
@Builder
public class ConfigProperties {

private String apimlHost;
private String apimlPort;
private String apimlBaseUrl;
Expand All @@ -24,4 +28,23 @@ public class ConfigProperties {
private char[] trustStorePassword;
private boolean httpOnly;
private boolean nonStrictVerifySslCertificatesOfServices;

@Tolerate
public ConfigProperties() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider using NoArgs and AllArgs annotations instead of this experimental one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was my first attempt, but it doesn't work together with @builder. Just this annotation solved it.

// no args constructor
}

public ConfigProperties withoutKeyStore() {
return ConfigProperties.builder()
.apimlHost(apimlHost)
.apimlPort(apimlPort)
.apimlBaseUrl(apimlBaseUrl)
.trustStoreType(trustStoreType)
.trustStorePath(trustStorePath)
.trustStorePassword(trustStorePassword)
.httpOnly(httpOnly)
.nonStrictVerifySslCertificatesOfServices(nonStrictVerifySslCertificatesOfServices)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.zowe.apiml.zaasclient.config.ConfigProperties;
import org.zowe.apiml.zaasclient.exception.ZaasClientErrorCodes;
import org.zowe.apiml.zaasclient.exception.ZaasClientException;
import org.zowe.apiml.zaasclient.exception.ZaasConfigurationErrorCodes;
import org.zowe.apiml.zaasclient.exception.ZaasConfigurationException;
import org.zowe.apiml.zaasclient.service.ZaasClient;
import org.zowe.apiml.zaasclient.service.ZaasToken;
Expand All @@ -26,12 +27,17 @@ public class ZaasClientImpl implements ZaasClient {
private final PassTicketService passTickets;

public ZaasClientImpl(ConfigProperties configProperties) throws ZaasConfigurationException {
if (!configProperties.isHttpOnly() && (configProperties.getKeyStorePath() == null)) {
throw new ZaasConfigurationException(ZaasConfigurationErrorCodes.KEY_STORE_NOT_PROVIDED);
}

CloseableClientProvider httpClientProvider = getTokenProvider(configProperties);
CloseableClientProvider httpClientProviderWithoutCert = getTokenProviderWithoutCert(configProperties, httpClientProvider);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of HTTP , the same provider object is used, in case of HTTPS, there are 2 objects being created, is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is, in the case of HTTP there is no needed to make two instances. But the purpose is the question because HTTP is not possible to use (except the theoretical configuration). It should be just for ATTLS, but then it is too difficult (maybe impossible) to establish to respect URL and using a client certificate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should focus on the possibility, how to use ZAAS client with AT-TLS in the next issue. Thank you for finding that.


String baseUrl = String.format("%s://%s:%s%s", getScheme(configProperties.isHttpOnly()), configProperties.getApimlHost(), configProperties.getApimlPort(),
configProperties.getApimlBaseUrl());
tokens = new ZaasJwtService(httpClientProvider, baseUrl);
tokens = new ZaasJwtService(httpClientProviderWithoutCert, baseUrl);
passTickets = new PassTicketServiceImpl(httpClientProvider, baseUrl);

}

private CloseableClientProvider getTokenProvider(ConfigProperties configProperties) throws ZaasConfigurationException {
Expand All @@ -40,7 +46,16 @@ private CloseableClientProvider getTokenProvider(ConfigProperties configProperti
} else {
return new ZaasHttpsClientProvider(configProperties);
}
}

private CloseableClientProvider getTokenProviderWithoutCert (
ConfigProperties configProperties,
CloseableClientProvider defaultCloseableClientProvider) throws ZaasConfigurationException
{
if (configProperties.isHttpOnly()) {
return defaultCloseableClientProvider;
}
return getTokenProvider(configProperties.withoutKeyStore());
}

private Object getScheme(boolean httpOnly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ public void clearCookieStore() {

@Override
public synchronized CloseableHttpClient getHttpClient() throws ZaasConfigurationException {
if (keyStorePath == null) {
throw new ZaasConfigurationException(ZaasConfigurationErrorCodes.KEY_STORE_NOT_PROVIDED);
}
if (httpsClientWithKeyStoreAndTrustStore == null) {
if (kmf == null) {
if ((kmf == null) && (keyStorePath != null)) {
initializeKeyStoreManagerFactory();
}
httpsClientWithKeyStoreAndTrustStore = sharedHttpClientConfiguration(getSSLContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void testHttpOnlyZaasClientCanBeCreated() throws ZaasConfigurationException {
configProperties.setApimlPort("10010");
configProperties.setApimlBaseUrl("/api/v1/gateway/auth");
configProperties.setNonStrictVerifySslCertificatesOfServices(false);
configProperties.setKeyStorePath("keystorePath");
ZaasClient client = new ZaasClientImpl(configProperties);
assertNotNull(client);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.zowe.apiml.zaasclient.config.ConfigProperties;
import org.zowe.apiml.zaasclient.exception.ZaasClientErrorCodes;
import org.zowe.apiml.zaasclient.exception.ZaasClientException;
import org.zowe.apiml.zaasclient.exception.ZaasConfigurationException;
Expand Down Expand Up @@ -146,4 +147,15 @@ void givenValidToken_whenLogoutIsCalled_thenSuccessLogout() {
assertDoesNotThrow(() -> underTest.logout("apimlAuthenticationToken=" + VALID_TOKEN));
}

@Test
void givenNullKeyStorePath_whenTheClientIsConstructed_thenExceptionIsThrown() {
ConfigProperties config = new ConfigProperties();
config.setTrustStorePassword(VALID_PASSWORD.toCharArray());
config.setTrustStorePath("src/test/resources/localhost.truststore.p12");
config.setTrustStoreType("PKCS12");
ZaasConfigurationException zaasException = assertThrows(ZaasConfigurationException.class, () -> new ZaasClientImpl(config));

assertThat(zaasException.getErrorCode().getId(), is("ZWEAS501E"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,6 @@ void giveInvalidTrustStorePath_whenTheClientIsConstructed_thenExceptionsIsThrown
assertThat(zaasException.getErrorCode().getId(), is("ZWEAS503E"));
}

@Test
void givenNullKeyStorePath_whenTheClientIsConstructed_thenExceptionIsThrown() throws ZaasConfigurationException {
ConfigProperties config = new ConfigProperties();
config.setTrustStorePassword(PASSWORD);
config.setTrustStorePath("src/test/resources/localhost.truststore.p12");
config.setTrustStoreType("PKCS12");
ZaasHttpsClientProvider provider = new ZaasHttpsClientProvider(config);
ZaasConfigurationException zaasException = assertThrows(ZaasConfigurationException.class, provider::getHttpClient);

assertThat(zaasException.getErrorCode().getId(), is("ZWEAS501E"));
}

@Test
void givenInvalidKeyStorePath_whenTheClientIsConstructed_thenExceptionIsThrown() throws ZaasConfigurationException {
ConfigProperties config = new ConfigProperties();
Expand Down