use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class PreAuthorizeAuthorizationManagerTests 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");
PreAuthorizeAuthorizationManager manager = new PreAuthorizeAuthorizationManager();
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 PreAuthorizeAuthorizationManagerTests method checkDoSomethingStringWhenArgIsNotGrantThenDeniedDecision.
@Test
public void checkDoSomethingStringWhenArgIsNotGrantThenDeniedDecision() throws Exception {
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "doSomethingString", new Class[] { String.class }, new Object[] { "deny" });
PreAuthorizeAuthorizationManager manager = new PreAuthorizeAuthorizationManager();
AuthorizationDecision decision = manager.check(TestAuthentication::authenticatedUser, methodInvocation);
assertThat(decision).isNotNull();
assertThat(decision.isGranted()).isFalse();
}
use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class Jsr250AuthorizationManagerTests method checkDenyAllWhenRoleAdminThenDeniedDecision.
@Test
public void checkDenyAllWhenRoleAdminThenDeniedDecision() throws Exception {
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "denyAll");
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
AuthorizationDecision decision = manager.check(TestAuthentication::authenticatedAdmin, methodInvocation);
assertThat(decision).isNotNull();
assertThat(decision.isGranted()).isFalse();
}
use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class Jsr250AuthorizationManagerTests method checkRolesAllowedUserOrAdminWhenRoleAnonymousThenDeniedDecision.
@Test
public void checkRolesAllowedUserOrAdminWhenRoleAnonymousThenDeniedDecision() throws Exception {
Supplier<Authentication> authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_ANONYMOUS");
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "rolesAllowedUserOrAdmin");
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
AuthorizationDecision decision = manager.check(authentication, methodInvocation);
assertThat(decision).isNotNull();
assertThat(decision.isGranted()).isFalse();
}
use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.
the class Jsr250AuthorizationManagerTests method checkRolesAllowedUserOrAdminWhenRoleUserThenGrantedDecision.
@Test
public void checkRolesAllowedUserOrAdminWhenRoleUserThenGrantedDecision() throws Exception {
MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "rolesAllowedUserOrAdmin");
Jsr250AuthorizationManager manager = new Jsr250AuthorizationManager();
AuthorizationDecision decision = manager.check(TestAuthentication::authenticatedUser, methodInvocation);
assertThat(decision).isNotNull();
assertThat(decision.isGranted()).isTrue();
}
Aggregations