use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class Jsr250AuthorizationManagerTests method checkRequiresAdminWhenClassAnnotationsThenMethodAnnotationsTakePrecedence.
@Test
public void checkRequiresAdminWhenClassAnnotationsThenMethodAnnotationsTakePrecedence() throws Exception {
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER");
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ClassLevelAnnotations(), ClassLevelAnnotations.class, "rolesAllowedAdmin");
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
AuthorizationDecision decision = manager.check(authentication, methodInvocation);
assertThat(decision.isGranted()).isFalse();
authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_ADMIN");
decision = manager.check(authentication, methodInvocation);
assertThat(decision.isGranted()).isTrue();
}
use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class Jsr250AuthorizationManagerTests method checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException.
@Test
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER");
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ClassLevelAnnotations(), ClassLevelAnnotations.class, "inheritedAnnotations");
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> manager.check(authentication, methodInvocation));
}
use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class Jsr250AuthorizationManagerTests method checkMultipleAnnotationsWhenInvokedThenAnnotationConfigurationException.
@Test
public void checkMultipleAnnotationsWhenInvokedThenAnnotationConfigurationException() throws Exception {
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_ANONYMOUS");
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "multipleAnnotations");
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> manager.check(authentication, methodInvocation));
}
use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class PostFilterAuthorizationMethodInterceptorTests method checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException.
@Test
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(), ConflictingAnnotations.class, "inheritedAnnotations");
PostFilterAuthorizationMethodInterceptor advice = new PostFilterAuthorizationMethodInterceptor();
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> advice.invoke(methodInvocation));
}
use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class PostAuthorizeAuthorizationManagerTests method checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException.
@Test
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER");
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "inheritedAnnotations");
MethodInvocationResult result = new MethodInvocationResult(methodInvocation, null);
PostAuthorizeAuthorizationManager manager = new PostAuthorizeAuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> manager.check(authentication, result));
}
Aggregations