Skip to content

Commit

Permalink
EPA-354 copy values from user config into runtime config
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Blechschmidt committed Dec 23, 2024
1 parent a139db2 commit 2af7535
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.jose4j.jwt.consumer.JwtConsumerBuilder;

import health.ere.ps.config.RuntimeConfig;
import health.ere.ps.model.config.UserConfigurations;
import health.ere.ps.service.config.UserConfigurationService;
import health.ere.ps.service.idp.BearerTokenService;
import jakarta.inject.Inject;
import jakarta.websocket.Session;
Expand All @@ -21,6 +23,9 @@ public class BearerTokenManageService {
@Inject
BearerTokenService bearerTokenService;

@Inject
UserConfigurationService userConfigurationService;

//In the future it should be managed automatically by the webclient, including its renewal
Map<RuntimeConfig, String> bearerToken = new HashMap<>();

Expand All @@ -39,6 +44,29 @@ public void requestNewAccessTokenIfNecessary() {
public void requestNewAccessTokenIfNecessary(RuntimeConfig runtimeConfig, Session replyTo, String replyToMessageId) {
if (StringUtils.isEmpty(getBearerToken(runtimeConfig)) || isExpired(bearerToken.get(runtimeConfig))) {
log.info("Request new bearer token.");
if(runtimeConfig != null && runtimeConfig.getConfigurations() != null) {
UserConfigurations configurations = runtimeConfig.getConfigurations();
UserConfigurations config = userConfigurationService.getConfig();
if(configurations.getBasicAuthUsername() == null && config.getBasicAuthUsername() != null) {
configurations.setBasicAuthUsername(config.getBasicAuthUsername());
configurations.setBasicAuthPassword(config.getBasicAuthPassword());
}
if(configurations.getClientCertificate() == null && config.getClientCertificate() != null) {
configurations.setClientCertificate(config.getClientCertificate());
configurations.setClientCertificatePassword(config.getClientCertificatePassword());
}
if(configurations.getMandantId() == null && config.getMandantId() != null) {
configurations.setMandantId(config.getMandantId());
}
if(configurations.getClientSystemId() == null && config.getClientSystemId() != null) {
configurations.setClientSystemId(config.getClientSystemId());
}
if(configurations.getWorkplaceId() == null && config.getWorkplaceId() != null) {
configurations.setWorkplaceId(config.getWorkplaceId());
}

}

String bearerTokenString = bearerTokenService.requestBearerToken(runtimeConfig, replyTo, replyToMessageId);
bearerToken.put(runtimeConfig, bearerTokenString);
}
Expand Down

0 comments on commit 2af7535

Please sign in to comment.