Improved AccessContext (#3029)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -23,6 +23,7 @@ import org.eclipse.hawkbit.artifact.fs.FileArtifactStorage;
|
||||
import org.eclipse.hawkbit.artifact.urlresolver.PropertyBasedArtifactUrlResolver;
|
||||
import org.eclipse.hawkbit.artifact.urlresolver.PropertyBasedArtifactUrlResolverProperties;
|
||||
import org.eclipse.hawkbit.auth.Hierarchy;
|
||||
import org.eclipse.hawkbit.auth.SpRole;
|
||||
import org.eclipse.hawkbit.context.AccessContext;
|
||||
import org.eclipse.hawkbit.repository.RepositoryConfiguration;
|
||||
import org.eclipse.hawkbit.repository.RolloutApprovalStrategy;
|
||||
@@ -138,7 +139,7 @@ public class TestConfiguration implements AsyncConfigurer {
|
||||
|
||||
@Bean
|
||||
AuditorAware<String> auditorAware() {
|
||||
return () -> Optional.ofNullable(AccessContext.actor());
|
||||
return () -> Optional.ofNullable(SpRole.isController() ? "CONTROLLER_PLUG_AND_PLAY" : AccessContext.actor());
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -122,6 +122,7 @@ public abstract class AbstractIntegrationTest {
|
||||
protected static final Pageable PAGE = PageRequest.of(0, 500, Sort.by(Direction.ASC, "id"));
|
||||
protected static final Pageable UNPAGED = Pageable.unpaged();
|
||||
|
||||
protected static final String CONTROLLER_PLUG_AND_PLAY = "CONTROLLER_PLUG_AND_PLAY";
|
||||
protected static final URI LOCALHOST = URI.create("http://127.0.0.1");
|
||||
protected static final Random RND = TestdataFactory.RND;
|
||||
|
||||
|
||||
@@ -23,9 +23,8 @@ import java.util.function.Supplier;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.auth.SpRole;
|
||||
import org.eclipse.hawkbit.context.Principal;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAwareAuthenticationDetails;
|
||||
import org.eclipse.hawkbit.tenancy.TenantAwareUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -92,8 +91,8 @@ public class SecurityContextSwitch {
|
||||
});
|
||||
}
|
||||
|
||||
public static WithUser withController(final String principal, final String... authorities) {
|
||||
return withTenantAndUser(DEFAULT_TENANT, principal, authorities, true, true);
|
||||
public static WithUser withController(final String principal) { // authorized controller
|
||||
return withTenantAndUser(DEFAULT_TENANT, principal, new String[] { CONTROLLER_ROLE }, true, true);
|
||||
}
|
||||
|
||||
public static WithUser withUser(final String principal, final String... authorities) {
|
||||
@@ -146,12 +145,8 @@ public class SecurityContextSwitch {
|
||||
|
||||
@Override
|
||||
public Authentication getAuthentication() {
|
||||
final TestingAuthenticationToken testingAuthenticationToken = new TestingAuthenticationToken(
|
||||
new TenantAwareUser(annotation.principal(), "***", null, annotation.tenant()),
|
||||
annotation.credentials(), annotation.authorities());
|
||||
testingAuthenticationToken.setDetails(
|
||||
new TenantAwareAuthenticationDetails(annotation.tenant(), annotation.controller()));
|
||||
return testingAuthenticationToken;
|
||||
return new TestingAuthenticationToken(
|
||||
new Principal(annotation.tenant(), annotation.principal()), annotation.credentials(), annotation.authorities());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,6 +28,13 @@ import org.springframework.security.test.context.support.WithSecurityContextFact
|
||||
@Inherited
|
||||
public @interface WithUser {
|
||||
|
||||
/**
|
||||
* Gets the test actor.
|
||||
*
|
||||
* @return test actor
|
||||
*/
|
||||
String principal() default "TestActor";
|
||||
|
||||
/**
|
||||
* Gets the test tenant id.
|
||||
*
|
||||
@@ -35,13 +42,6 @@ public @interface WithUser {
|
||||
*/
|
||||
String tenant() default "DEFAULT";
|
||||
|
||||
/**
|
||||
* Gets the test principal.
|
||||
*
|
||||
* @return test principal
|
||||
*/
|
||||
String principal() default "TestPrincipal";
|
||||
|
||||
/**
|
||||
* Gets the test credentials.
|
||||
*
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
# Test utility properties for easier fault investigation - START
|
||||
## Logging - START
|
||||
logging.level.root=ERROR
|
||||
logging.level.root=WARN
|
||||
logging.level.org.eclipse.hawkbit.repository.test.matcher.EventVerifier=ERROR
|
||||
logging.level.org.eclipse.persistence=ERROR
|
||||
spring.jpa.properties.eclipselink.logging.level=FINE
|
||||
|
||||
Reference in New Issue
Block a user