Search in sources :

Example 16 with AuthorizationResponse

use of io.helidon.security.AuthorizationResponse in project helidon by oracle.

the class SecurityFilterTest method testAtzAbortWith.

@Test
void testAtzAbortWith() {
    SecurityFeature feature = SecurityFeature.builder(security).build();
    SecurityContext securityContext = security.createContext("testAbortWith");
    SecurityFilter sf = new SecurityFilter(feature.featureConfig(), security, serverConfig, securityContext);
    ContainerRequest request = mock(ContainerRequest.class);
    SecurityFilter.FilterContext filterContext = new SecurityFilter.FilterContext();
    filterContext.setJerseyRequest(request);
    SecurityClientBuilder<AuthorizationResponse> clientBuilder = mock(SecurityClientBuilder.class);
    when(clientBuilder.buildAndGet()).thenReturn(AuthorizationResponse.builder().description("Unit-test").status(SecurityResponse.SecurityStatus.FAILURE).build());
    sf.processAuthorization(filterContext, clientBuilder);
    assertThat(filterContext.isShouldFinish(), is(true));
    verify(request).abortWith(argThat(response -> response.getStatus() == 403));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Security(io.helidon.security.Security) ServerConfig(org.glassfish.jersey.server.ServerConfig) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Set(java.util.Set) SecurityContext(io.helidon.security.SecurityContext) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) Mockito.when(org.mockito.Mockito.when) AuthenticationResponse(io.helidon.security.AuthenticationResponse) WebApplicationException(jakarta.ws.rs.WebApplicationException) Mockito.verify(org.mockito.Mockito.verify) SecurityResponse(io.helidon.security.SecurityResponse) Test(org.junit.jupiter.api.Test) Response(jakarta.ws.rs.core.Response) SecurityClientBuilder(io.helidon.security.SecurityClientBuilder) BeforeAll(org.junit.jupiter.api.BeforeAll) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Assertions(org.junit.jupiter.api.Assertions) Application(jakarta.ws.rs.core.Application) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SecurityTracing(io.helidon.security.integration.common.SecurityTracing) AuthorizationResponse(io.helidon.security.AuthorizationResponse) Mockito.mock(org.mockito.Mockito.mock) SecurityContext(io.helidon.security.SecurityContext) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) AuthorizationResponse(io.helidon.security.AuthorizationResponse) Test(org.junit.jupiter.api.Test)

Aggregations

AuthorizationResponse (io.helidon.security.AuthorizationResponse)16 Test (org.junit.jupiter.api.Test)12 EndpointConfig (io.helidon.security.EndpointConfig)9 ProviderRequest (io.helidon.security.ProviderRequest)9 SecurityContext (io.helidon.security.SecurityContext)7 SecurityEnvironment (io.helidon.security.SecurityEnvironment)5 SecurityLevel (io.helidon.security.SecurityLevel)5 SecurityResponse (io.helidon.security.SecurityResponse)4 Security (io.helidon.security.Security)3 AuthenticationResponse (io.helidon.security.AuthenticationResponse)2 RolesAllowed (jakarta.annotation.security.RolesAllowed)2 WebApplicationException (jakarta.ws.rs.WebApplicationException)2 Response (jakarta.ws.rs.core.Response)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 ContainerRequest (org.glassfish.jersey.server.ContainerRequest)2 CoreMatchers.is (org.hamcrest.CoreMatchers.is)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Errors (io.helidon.common.Errors)1