Add @PreAuthorize enabled check for applications (#1503)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2023-12-07 22:23:40 +02:00
committed by GitHub
parent c0f8a8c848
commit aa1bad91e1
8 changed files with 173 additions and 12 deletions

View File

@@ -171,7 +171,7 @@ public class WithSpringAuthorityRule implements BeforeEachCallback, AfterEachCal
};
}
private static class SecurityContextWithUser implements SecurityContext {
static class SecurityContextWithUser implements SecurityContext {
private static final long serialVersionUID = 1L;
private final WithUser annotation;

View File

@@ -9,6 +9,10 @@
*/
package org.eclipse.hawkbit.repository.test.util;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.test.context.support.WithSecurityContext;
import org.springframework.security.test.context.support.WithSecurityContextFactory;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
@@ -21,6 +25,7 @@ import java.lang.annotation.Target;
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
@WithSecurityContext(factory = WithUser.WithUserPrincipalSecurityContextFactory.class)
@Inherited
public @interface WithUser {
@@ -74,4 +79,11 @@ public @interface WithUser {
String[] removeFromAllPermission() default {};
boolean controller() default false;
}
class WithUserPrincipalSecurityContextFactory implements WithSecurityContextFactory<WithUser> {
@Override
public SecurityContext createSecurityContext(final WithUser withUserPrincipal) {
return new WithSpringAuthorityRule.SecurityContextWithUser(withUserPrincipal);
}
}
}