Fix overdue timestamp calculation permission (#1235)

* fixed overdue timestamp calculation permission error

Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch.io>

* changed method visibility

Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch.io>
This commit is contained in:
Bondar Bogdan
2022-03-25 16:00:18 +01:00
committed by GitHub
parent c9eafbbc26
commit 527f7de6a8
5 changed files with 13 additions and 6 deletions

View File

@@ -11,7 +11,9 @@ package org.eclipse.hawkbit.repository;
import java.time.Duration;
import java.time.Instant;
import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder;
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
@@ -48,10 +50,15 @@ public final class TimestampCalculator {
}
private static String getRawStringForKey(final String key) {
return getTenantConfigurationManagement().getConfigurationValue(key, String.class).getValue();
return getSystemSecurityContext().runAsSystem(
() -> getTenantConfigurationManagement().getConfigurationValue(key, String.class).getValue());
}
public static TenantConfigurationManagement getTenantConfigurationManagement() {
private static SystemSecurityContext getSystemSecurityContext() {
return SystemSecurityContextHolder.getInstance().getSystemSecurityContext();
}
private static TenantConfigurationManagement getTenantConfigurationManagement() {
return TenantConfigurationManagementHolder.getInstance().getTenantConfigurationManagement();
}
}

View File

@@ -0,0 +1,41 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.model.helper;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
/**
* A singleton bean which holds {@link SystemSecurityContext} service and makes
* it accessible to beans which are not managed by spring, e.g. JPA entities.
*/
public final class SystemSecurityContextHolder {
private static final SystemSecurityContextHolder INSTANCE = new SystemSecurityContextHolder();
@Autowired
private SystemSecurityContext systemSecurityContext;
private SystemSecurityContextHolder() {
}
/**
* @return the singleton {@link SystemSecurityContextHolder} instance
*/
public static SystemSecurityContextHolder getInstance() {
return INSTANCE;
}
/**
* @return the {@link SystemSecurityContext} service
*/
public SystemSecurityContext getSystemSecurityContext() {
return systemSecurityContext;
}
}