use of io.helidon.security.ProviderRequest in project helidon by oracle.
the class AtnProviderSyncTest method testFailure.
@Test
public void testFailure() {
Config config = Config.create(ConfigSources.create(Map.of("atn-object.size", String.valueOf(SIZE))));
SecurityContext context = mock(SecurityContext.class);
when(context.user()).thenReturn(Optional.empty());
when(context.service()).thenReturn(Optional.empty());
SecurityEnvironment se = SecurityEnvironment.create();
EndpointConfig ep = EndpointConfig.builder().config("atn-object", config).build();
ProviderRequest request = mock(ProviderRequest.class);
when(request.securityContext()).thenReturn(context);
when(request.env()).thenReturn(se);
when(request.endpointConfig()).thenReturn(ep);
AtnProviderSync provider = new AtnProviderSync();
AuthenticationResponse response = provider.syncAuthenticate(request);
assertThat(response.status(), is(SecurityResponse.SecurityStatus.FAILURE));
}
use of io.helidon.security.ProviderRequest in project helidon by oracle.
the class AtnProviderSyncTest method testConfigSuccess.
@Test
public void testConfigSuccess() {
Config config = Config.create(ConfigSources.create(Map.of("value", VALUE, "size", String.valueOf(SIZE))));
SecurityContext context = mock(SecurityContext.class);
when(context.user()).thenReturn(Optional.empty());
when(context.service()).thenReturn(Optional.empty());
SecurityEnvironment se = SecurityEnvironment.create();
EndpointConfig ep = EndpointConfig.builder().config("atn-object", config).build();
ProviderRequest request = mock(ProviderRequest.class);
when(request.securityContext()).thenReturn(context);
when(request.env()).thenReturn(se);
when(request.endpointConfig()).thenReturn(ep);
testSuccess(request);
}
use of io.helidon.security.ProviderRequest in project helidon by oracle.
the class AtzProviderSyncTest method testPermitted.
@Test
public void testPermitted() {
SecurityContext context = mock(SecurityContext.class);
when(context.isAuthenticated()).thenReturn(true);
SecurityEnvironment se = SecurityEnvironment.builder().path("/private/some/path").build();
EndpointConfig ep = EndpointConfig.create();
ProviderRequest request = mock(ProviderRequest.class);
when(request.securityContext()).thenReturn(context);
when(request.env()).thenReturn(se);
when(request.endpointConfig()).thenReturn(ep);
AtzProviderSync provider = new AtzProviderSync();
AuthorizationResponse response = provider.syncAuthorize(request);
assertThat(response.status(), is(SecurityResponse.SecurityStatus.SUCCESS));
}
use of io.helidon.security.ProviderRequest in project helidon by oracle.
the class AtzProviderSyncTest method testAbstain.
@Test
public void testAbstain() {
SecurityEnvironment se = SecurityEnvironment.create();
EndpointConfig ep = EndpointConfig.create();
ProviderRequest request = mock(ProviderRequest.class);
when(request.env()).thenReturn(se);
when(request.endpointConfig()).thenReturn(ep);
AtzProviderSync provider = new AtzProviderSync();
AuthorizationResponse response = provider.syncAuthorize(request);
assertThat(response.status(), is(SecurityResponse.SecurityStatus.ABSTAIN));
}
use of io.helidon.security.ProviderRequest in project helidon by oracle.
the class OutboundProviderSyncTest method testSuccess.
@Test
public void testSuccess() {
String username = "aUser";
Subject subject = Subject.create(Principal.create(username));
SecurityContext context = mock(SecurityContext.class);
when(context.user()).thenReturn(Optional.of(subject));
when(context.service()).thenReturn(Optional.empty());
SecurityEnvironment se = SecurityEnvironment.create();
ProviderRequest request = mock(ProviderRequest.class);
when(request.securityContext()).thenReturn(context);
when(request.env()).thenReturn(se);
OutboundProviderSync ops = new OutboundProviderSync();
OutboundSecurityResponse response = ops.syncOutbound(request, SecurityEnvironment.create(), EndpointConfig.create());
assertThat(response.status(), is(SecurityResponse.SecurityStatus.SUCCESS));
assertThat(response.requestHeaders().get("X-AUTH-USER"), is(List.of(username)));
}
Aggregations