use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class Jsr250AuthorizationManagerTests method checkDeniedWhenClassAnnotationsThenMethodAnnotationsTakePrecedence.
@Test
public void checkDeniedWhenClassAnnotationsThenMethodAnnotationsTakePrecedence() throws Exception {
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER");
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ClassLevelAnnotations(), ClassLevelAnnotations.class, "denyAll");
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
AuthorizationDecision decision = manager.check(authentication, methodInvocation);
assertThat(decision.isGranted()).isFalse();
}
use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class Jsr250AuthorizationManagerTests method checkPermitAllWhenRoleUserThenGrantedDecision.
@Test
public void checkPermitAllWhenRoleUserThenGrantedDecision() throws Exception {
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "permitAll");
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
AuthorizationDecision decision = manager.check(TestAuthentication::authenticatedUser, methodInvocation);
assertThat(decision).isNotNull();
assertThat(decision.isGranted()).isTrue();
}
use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class PostFilterAuthorizationMethodInterceptorTests method checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException.
@Test
public void checkInheritedAnnotationsWhenDuplicatedThenAnnotationConfigurationException() throws Exception {
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.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 PostFilterAuthorizationMethodInterceptorTests method afterWhenArrayNotNullThenFilteredArray.
@Test
public void afterWhenArrayNotNullThenFilteredArray() throws Throwable {
String[] array = { "john", "bob" };
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "doSomethingArrayClassLevel", new Class[] { String[].class }, new Object[] { array }) {
@Override
public Object proceed() {
return array;
}
};
PostFilterAuthorizationMethodInterceptor advice = new PostFilterAuthorizationMethodInterceptor();
Object result = advice.invoke(methodInvocation);
assertThat(result).asInstanceOf(InstanceOfAssertFactories.array(String[].class)).containsOnly("john");
}
use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class PreFilterAuthorizationMethodInterceptorTests method checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException.
@Test
public void checkInheritedAnnotationsWhenConflictingThenAnnotationConfigurationException() throws Exception {
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ConflictingAnnotations(), ConflictingAnnotations.class, "inheritedAnnotations");
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> advice.invoke(methodInvocation));
}
Aggregations