use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class PreFilterAuthorizationMethodInterceptorTests method findFilterTargetWhenNameNotProvidedAndNotSingleArgThenException.
@Test
public void findFilterTargetWhenNameNotProvidedAndNotSingleArgThenException() throws Exception {
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "doSomethingTwoArgsFilterTargetNotProvided", new Class[] { String.class, List.class }, new Object[] { "", new ArrayList<>() });
PreFilterAuthorizationMethodInterceptor advice = new PreFilterAuthorizationMethodInterceptor();
assertThatIllegalStateException().isThrownBy(() -> advice.invoke(methodInvocation)).withMessage("Unable to determine the method argument for filtering. Specify the filter target.");
}
use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class SecuredAuthorizationManagerTests 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");
SecuredAuthorizationManager manager = new SecuredAuthorizationManager();
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 SecuredAuthorizationManagerTests method checkRequiresUserWhenClassAnnotationsThenApplies.
@Test
public void checkRequiresUserWhenClassAnnotationsThenApplies() throws Exception {
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_USER");
MockMethodInvocation methodInvocation = new MockMethodInvocation(new ClassLevelAnnotations(), ClassLevelAnnotations.class, "securedUser");
SecuredAuthorizationManager manager = new SecuredAuthorizationManager();
AuthorizationDecision decision = manager.check(authentication, methodInvocation);
assertThat(decision.isGranted()).isTrue();
authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_ADMIN");
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 SecuredAuthorizationManagerTests method checkSecuredUserOrAdminWhenRoleAdminThenGrantedDecision.
@Test
public void checkSecuredUserOrAdminWhenRoleAdminThenGrantedDecision() throws Exception {
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "securedUserOrAdmin");
SecuredAuthorizationManager manager = new SecuredAuthorizationManager();
AuthorizationDecision decision = manager.check(TestAuthentication::authenticatedAdmin, 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 SecuredAuthorizationManagerTests 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");
SecuredAuthorizationManager manager = new SecuredAuthorizationManager();
assertThatExceptionOfType(AnnotationConfigurationException.class).isThrownBy(() -> manager.check(authentication, methodInvocation));
}
Aggregations