Add AccessContext.asTenant and use where possible (#2838)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-11-27 16:27:56 +02:00
committed by GitHub
parent f6f62db0ad
commit 42384b7e31
17 changed files with 184 additions and 97 deletions

View File

@@ -9,7 +9,7 @@
*/
package org.eclipse.hawkbit.security.controller;
import static org.eclipse.hawkbit.context.AccessContext.asSystemAsTenant;
import static org.eclipse.hawkbit.context.AccessContext.asTenant;
import java.util.Collection;
import java.util.List;
@@ -47,9 +47,7 @@ public interface Authenticator {
abstract class AbstractAuthenticator implements Authenticator {
protected boolean isEnabled(final ControllerSecurityToken securityToken) {
return asSystemAsTenant(
securityToken.getTenant(),
() -> TenantConfigHelper.getAsSystem(getTenantConfigurationKey(), Boolean.class));
return asTenant(securityToken.getTenant(), () -> TenantConfigHelper.getAsSystem(getTenantConfigurationKey(), Boolean.class));
}
protected abstract String getTenantConfigurationKey();

View File

@@ -9,7 +9,7 @@
*/
package org.eclipse.hawkbit.security.controller;
import static org.eclipse.hawkbit.context.AccessContext.asSystemAsTenant;
import static org.eclipse.hawkbit.context.AccessContext.asTenant;
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_ENABLED;
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY;
@@ -51,14 +51,10 @@ public class GatewayTokenAuthenticator extends Authenticator.AbstractAuthenticat
final String presentedToken = authHeader.substring(OFFSET_GATEWAY_TOKEN);
// validate if the presented token is the same as the gateway token
return presentedToken.equals(asSystemAsTenant(
controllerSecurityToken.getTenant(),
() -> {
log.trace("retrieving configuration value for configuration key {}", AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY);
return TenantConfigHelper.getAsSystem(AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY, String.class);
}))
? authenticatedController(controllerSecurityToken.getTenant(), controllerSecurityToken.getControllerId())
: null;
return presentedToken.equals(asTenant(controllerSecurityToken.getTenant(), () -> {
log.trace("retrieving configuration value for configuration key {}", AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY);
return TenantConfigHelper.getAsSystem(AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY, String.class);
})) ? authenticatedController(controllerSecurityToken.getTenant(), controllerSecurityToken.getControllerId()) : null;
}
@Override

View File

@@ -9,7 +9,7 @@
*/
package org.eclipse.hawkbit.security.controller;
import static org.eclipse.hawkbit.context.AccessContext.asSystemAsTenant;
import static org.eclipse.hawkbit.context.AccessContext.asTenant;
import static org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey.AUTHENTICATION_HEADER_AUTHORITY_NAME;
import java.util.Arrays;
@@ -73,7 +73,7 @@ public class SecurityHeaderAuthenticator extends Authenticator.AbstractAuthentic
final String sslIssuerHashValue = getIssuerHashHeader(
controllerSecurityToken,
asSystemAsTenant(
asTenant(
controllerSecurityToken.getTenant(),
() -> TenantConfigHelper.getAsSystem(AUTHENTICATION_HEADER_AUTHORITY_NAME, String.class)));
if (sslIssuerHashValue == null) {