-
Notifications
You must be signed in to change notification settings - Fork 68
Fix wrong using of certificates in ZAAS client #1514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
@@ -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) { | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.