use of com.vaadin.flow.server.auth.AccessAnnotationChecker in project flow by vaadin.
the class EndpointControllerTest method should_CallMethodAnonymously_When_AnonymousOverridesRoles.
@Test
public void should_CallMethodAnonymously_When_AnonymousOverridesRoles() {
EndpointController vaadinController = createVaadinController(TEST_ENDPOINT, new EndpointAccessChecker(new AccessAnnotationChecker()));
ResponseEntity<String> response = vaadinController.serveEndpoint(TEST_ENDPOINT_NAME, "anonymousOverrides", createRequestParameters("{}"), requestMock);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals("\"Hello, no user!\"", response.getBody());
}
use of com.vaadin.flow.server.auth.AccessAnnotationChecker in project flow by vaadin.
the class EndpointControllerTest method should_bePossibeToGetPrincipalInEndpoint.
@Test
public void should_bePossibeToGetPrincipalInEndpoint() {
when(principal.getName()).thenReturn("foo");
EndpointController vaadinController = createVaadinController(TEST_ENDPOINT, new EndpointAccessChecker(new AccessAnnotationChecker()));
ResponseEntity<String> response = vaadinController.serveEndpoint(TEST_ENDPOINT_NAME, "getUserName", createRequestParameters("{}"), requestMock);
assertEquals("\"foo\"", response.getBody());
}
use of com.vaadin.flow.server.auth.AccessAnnotationChecker in project flow by vaadin.
the class EndpointControllerTest method should_CallMethodAnonymously_When_UserPrincipalIsInRole.
@Test
public void should_CallMethodAnonymously_When_UserPrincipalIsInRole() {
when(requestMock.isUserInRole("FOO_ROLE")).thenReturn(true);
EndpointController vaadinController = createVaadinController(TEST_ENDPOINT, new EndpointAccessChecker(new AccessAnnotationChecker()));
ResponseEntity<String> response = vaadinController.serveEndpoint(TEST_ENDPOINT_NAME, "testRoleAllowed", createRequestParameters("{}"), requestMock);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals("\"Hello, user in role!\"", response.getBody());
}
use of com.vaadin.flow.server.auth.AccessAnnotationChecker in project flow by vaadin.
the class EndpointControllerTest method should_clearVaadinRequestInsntace_after_EndpointCall.
@Test
public void should_clearVaadinRequestInsntace_after_EndpointCall() {
EndpointController vaadinController = createVaadinController(TEST_ENDPOINT, new EndpointAccessChecker(new AccessAnnotationChecker()));
vaadinController.serveEndpoint(TEST_ENDPOINT_NAME, "getUserName", createRequestParameters("{}"), requestMock);
Assert.assertNull(CurrentInstance.get(VaadinRequest.class));
Assert.assertNull(VaadinRequest.getCurrent());
}
use of com.vaadin.flow.server.auth.AccessAnnotationChecker in project flow by vaadin.
the class EndpointControllerTest method should_NotCallMethodAnonymously_When_UserPrincipalIsNotInRole.
@Test
public void should_NotCallMethodAnonymously_When_UserPrincipalIsNotInRole() {
EndpointController vaadinController = createVaadinController(TEST_ENDPOINT, new EndpointAccessChecker(new AccessAnnotationChecker()));
ResponseEntity<String> response = vaadinController.serveEndpoint(TEST_ENDPOINT_NAME, "testRoleAllowed", createRequestParameters("{}"), requestMock);
assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode());
assertTrue(response.getBody().contains(EndpointAccessChecker.ACCESS_DENIED_MSG));
}
Aggregations