Fix AuthenticationSetupHelper to call update methods that evict cache (#2315)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-03-12 12:10:01 +02:00
committed by GitHub
parent 93aeae60e7
commit 3dc6eade98

View File

@@ -9,6 +9,7 @@
*/ */
package org.eclipse.hawkbit.sdk.mgmt; package org.eclipse.hawkbit.sdk.mgmt;
import java.io.Serializable;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.util.Base64; import java.util.Base64;
@@ -21,6 +22,7 @@ import feign.FeignException;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValueRequest;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget;
import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
@@ -68,14 +70,14 @@ public class AuthenticationSetupHelper {
if (!Boolean.TRUE.equals(Objects.requireNonNull(mgmtTenantManagementRestApi if (!Boolean.TRUE.equals(Objects.requireNonNull(mgmtTenantManagementRestApi
.getTenantConfigurationValue(AUTHENTICATION_MODE_HEADER_ENABLED) .getTenantConfigurationValue(AUTHENTICATION_MODE_HEADER_ENABLED)
.getBody()).getValue())) { .getBody()).getValue())) {
mgmtTenantManagementRestApi.updateTenantConfiguration(Map.of(AUTHENTICATION_MODE_HEADER_ENABLED, true)); updateConfigurationValue(AUTHENTICATION_MODE_HEADER_ENABLED, true, mgmtTenantManagementRestApi);
} }
final String fingerprint = ddiCA.getFingerprint(); final String fingerprint = ddiCA.getFingerprint();
if (!fingerprint.equals( if (!fingerprint.equals(
Objects.requireNonNull(mgmtTenantManagementRestApi Objects.requireNonNull(mgmtTenantManagementRestApi
.getTenantConfigurationValue(AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME) .getTenantConfigurationValue(AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME)
.getBody()).getValue())) { .getBody()).getValue())) {
mgmtTenantManagementRestApi.updateTenantConfiguration(Map.of(AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME, fingerprint)); updateConfigurationValue(AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME, fingerprint, mgmtTenantManagementRestApi);
} }
} }
@@ -85,7 +87,7 @@ public class AuthenticationSetupHelper {
if (!(Boolean.TRUE.equals(Objects.requireNonNull(mgmtTenantManagementRestApi if (!(Boolean.TRUE.equals(Objects.requireNonNull(mgmtTenantManagementRestApi
.getTenantConfigurationValue(AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED) .getTenantConfigurationValue(AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED)
.getBody()).getValue()))) { .getBody()).getValue()))) {
mgmtTenantManagementRestApi.updateTenantConfiguration(Map.of(AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED, true)); updateConfigurationValue(AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED, true, mgmtTenantManagementRestApi);
} }
} }
@@ -102,12 +104,12 @@ public class AuthenticationSetupHelper {
if (!(Boolean.TRUE.equals(Objects.requireNonNull(mgmtTenantManagementRestApi if (!(Boolean.TRUE.equals(Objects.requireNonNull(mgmtTenantManagementRestApi
.getTenantConfigurationValue(AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED) .getTenantConfigurationValue(AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED)
.getBody()).getValue()))) { .getBody()).getValue()))) {
mgmtTenantManagementRestApi.updateTenantConfiguration(Map.of(AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED, true)); updateConfigurationValue(AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED, true, mgmtTenantManagementRestApi);
} }
if (!gatewayToken.equals(Objects.requireNonNull(mgmtTenantManagementRestApi if (!gatewayToken.equals(Objects.requireNonNull(mgmtTenantManagementRestApi
.getTenantConfigurationValue(AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY) .getTenantConfigurationValue(AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY)
.getBody()).getValue())) { .getBody()).getValue())) {
mgmtTenantManagementRestApi.updateTenantConfiguration(Map.of(AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY, gatewayToken)); updateConfigurationValue(AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY, gatewayToken, mgmtTenantManagementRestApi);
} }
} }
@@ -152,4 +154,9 @@ public class AuthenticationSetupHelper {
return securityTargetToken; return securityTargetToken;
} }
private static void updateConfigurationValue(
final String key, final Serializable value, final MgmtTenantManagementRestApi mgmtTenantManagementRestApi) {
mgmtTenantManagementRestApi.updateTenantConfigurationValue(key, new MgmtSystemTenantConfigurationValueRequest().setValue(value));
}
} }