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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user