Skip to content

Commit

Permalink
fix: update keyring config (#2828)
Browse files Browse the repository at this point in the history
* update keyring config where missing

Signed-off-by: achmelo <[email protected]>

---------

Signed-off-by: achmelo <[email protected]>
  • Loading branch information
achmelo authored Mar 10, 2023
1 parent b8207ab commit c1e1cc9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,24 @@ public JwtSecurity(Providers providers, String keyAlias, String keyStore, char[]
@InjectApimlLogger
private ApimlLogger apimlLog = ApimlLogger.empty();

void updateStorePaths() {
if (SecurityUtils.isKeyring(keyStore)) {
keyStore = SecurityUtils.formatKeyringUrl(keyStore);
if (keyStorePassword == null) keyStorePassword = "password".toCharArray();
}
}

/**
* When the class is constructed and fully set, understand the zOSMF configuration and/or API ML configuration to
* load the key used to sign the JWT token.
*
* <p>
* In case the configuration is altogether invalid, stop the Gateway Service with the appropriate ERROR. This could
* take a while as we are waiting in certain scenarios for the zOSMF to properly start.
*/
@PostConstruct
public void loadAppropriateJwtKeyOrFail() {
updateStorePaths();
JwtProducer used = actualJwtProducer();

loadJwtSecret();
switch (used) {
case ZOSMF:
Expand Down Expand Up @@ -282,7 +289,7 @@ private ZosmfListener(ApimlDiscoveryClient discoveryClient) {
private final EurekaEventListener zosmfRegisteredListener = new EurekaEventListener() {
@Override
public void onEvent(EurekaEvent event) {
if (!(event instanceof CacheRefreshedEvent)) {
if (!(event instanceof CacheRefreshedEvent)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.zowe.apiml.exception.ServiceDefinitionException;
import org.zowe.apiml.security.HttpsConfig;
import org.zowe.apiml.security.HttpsFactory;
import org.zowe.apiml.security.SecurityUtils;


/**
Expand Down Expand Up @@ -65,9 +66,9 @@ public ApiMediationClientImpl(
}

public ApiMediationClientImpl(
EurekaClientProvider eurekaClientProvider,
EurekaClientConfigProvider eurekaClientConfigProvider,
EurekaInstanceConfigCreator instanceConfigCreator
EurekaClientProvider eurekaClientProvider,
EurekaClientConfigProvider eurekaClientConfigProvider,
EurekaInstanceConfigCreator instanceConfigCreator
) {
this(eurekaClientProvider, eurekaClientConfigProvider, instanceConfigCreator, new DefaultCustomMetadataHelper());
}
Expand Down Expand Up @@ -131,6 +132,7 @@ private EurekaClient initializeEurekaClient(

HttpsConfig.HttpsConfigBuilder builder = HttpsConfig.builder();
if (sslConfig != null) {
updateStorePaths(sslConfig);
builder.protocol(sslConfig.getProtocol());
if (Boolean.TRUE.equals(sslConfig.getEnabled())) {
builder.keyAlias(sslConfig.getKeyAlias())
Expand All @@ -152,6 +154,7 @@ private EurekaClient initializeEurekaClient(
HttpsConfig httpsConfig = builder.build();

HttpsFactory factory = new HttpsFactory(httpsConfig);

EurekaJerseyClient eurekaJerseyClient = factory.createEurekaJerseyClientBuilder(
config.getDiscoveryServiceUrls().get(0), config.getServiceId()).build();

Expand All @@ -161,6 +164,17 @@ private EurekaClient initializeEurekaClient(
return this.eurekaClientProvider.client(applicationInfoManager, clientConfig, args);
}

void updateStorePaths(Ssl config) {
if (SecurityUtils.isKeyring(config.getKeyStore())) {
config.setKeyStore(SecurityUtils.formatKeyringUrl(config.getKeyStore()));
if (config.getKeyStorePassword() == null) config.setKeyStorePassword("password".toCharArray());
}
if (SecurityUtils.isKeyring(config.getTrustStore())) {
config.setTrustStore(SecurityUtils.formatKeyringUrl(config.getTrustStore()));
if (config.getTrustStorePassword() == null) config.setTrustStorePassword("password".toCharArray());
}
}

private ApplicationInfoManager initializeApplicationInfoManager(ApiMediationServiceConfig config) throws ServiceDefinitionException {
EurekaInstanceConfig eurekaInstanceConfig = eurekaInstanceConfigCreator.createEurekaInstanceConfig(config);
InstanceInfo instanceInformation = new EurekaConfigBasedInstanceInfoProvider(eurekaInstanceConfig).get();
Expand Down

0 comments on commit c1e1cc9

Please sign in to comment.