use of io.helidon.security.SecurityEnvironment in project helidon by oracle.
the class HeaderAtnProviderTest method testExtractionNoHeader.
@Test
public void testExtractionNoHeader() {
HeaderAtnProvider provider = getFullProvider();
SecurityEnvironment env = SecurityEnvironment.create();
ProviderRequest request = mock(ProviderRequest.class);
when(request.env()).thenReturn(env);
AuthenticationResponse response = provider.syncAuthenticate(request);
assertThat(response.status(), is(SecurityResponse.SecurityStatus.ABSTAIN));
assertThat(response.user(), is(Optional.empty()));
assertThat(response.service(), is(Optional.empty()));
}
use of io.helidon.security.SecurityEnvironment in project helidon by oracle.
the class HeaderAtnProviderTest method testNoAtn.
@Test
public void testNoAtn() {
String username = "username";
HeaderAtnProvider provider = getNoSecurityProvider();
SecurityEnvironment env = outboundEnv();
ProviderRequest request = mock(ProviderRequest.class);
when(request.env()).thenReturn(env);
AuthenticationResponse response = provider.syncAuthenticate(request);
assertThat(response.status(), is(SecurityResponse.SecurityStatus.ABSTAIN));
assertThat(response.user(), is(Optional.empty()));
assertThat(response.service(), is(Optional.empty()));
}
use of io.helidon.security.SecurityEnvironment in project helidon by oracle.
the class HeaderAtnProviderTest method testOutbound.
@Test
public void testOutbound() {
HeaderAtnProvider provider = getFullProvider();
SecurityEnvironment env = outboundEnv();
ProviderRequest request = mock(ProviderRequest.class);
when(request.env()).thenReturn(env);
SecurityContext sc = mock(SecurityContext.class);
when(sc.user()).thenReturn(Optional.of(Subject.builder().addPrincipal(Principal.create("username")).build()));
when(sc.service()).thenReturn(Optional.empty());
when(request.securityContext()).thenReturn(sc);
SecurityEnvironment outboundEnv = outboundEnv();
EndpointConfig outboundEp = EndpointConfig.create();
assertThat("Outbound should be supported", provider.isOutboundSupported(request, outboundEnv, outboundEp), is(true));
OutboundSecurityResponse response = provider.syncOutbound(request, outboundEnv, outboundEp);
List<String> custom = response.requestHeaders().get("Custom");
assertThat(custom, notNullValue());
assertThat(custom.size(), is(1));
String token = custom.get(0);
assertThat(token, is("bearer username"));
}
use of io.helidon.security.SecurityEnvironment in project helidon by oracle.
the class HeaderAtnProviderTest method testNoOutbound.
@Test
public void testNoOutbound() {
String username = "username";
HeaderAtnProvider provider = getNoSecurityProvider();
SecurityEnvironment env = SecurityEnvironment.create();
ProviderRequest request = mock(ProviderRequest.class);
when(request.env()).thenReturn(env);
SecurityContext sc = mock(SecurityContext.class);
when(sc.user()).thenReturn(Optional.of(Subject.builder().addPrincipal(Principal.create(username)).build()));
when(sc.service()).thenReturn(Optional.empty());
when(request.securityContext()).thenReturn(sc);
SecurityEnvironment outboundEnv = SecurityEnvironment.create();
EndpointConfig outboundEp = EndpointConfig.create();
assertThat("Outbound should not be supported", provider.isOutboundSupported(request, outboundEnv, outboundEp), is(false));
}
use of io.helidon.security.SecurityEnvironment in project helidon by oracle.
the class HeaderAtnProviderTest method testExtraction.
@Test
public void testExtraction() {
String username = "username";
HeaderAtnProvider provider = getFullProvider();
SecurityEnvironment env = SecurityEnvironment.builder().header("Authorization", "bearer " + username).build();
ProviderRequest request = mock(ProviderRequest.class);
when(request.env()).thenReturn(env);
AuthenticationResponse response = provider.syncAuthenticate(request);
assertThat(response.status(), is(SecurityResponse.SecurityStatus.SUCCESS));
assertThat(response.user(), is(not(Optional.empty())));
assertThat(response.service(), is(Optional.empty()));
response.user().map(Subject::principal).map(Principal::getName).ifPresent(name -> assertThat(name, is(username)));
}
Aggregations