use of io.helidon.security.AuthenticationResponse in project helidon by oracle.
the class GoogleTokenProviderTest method testInboundMissingToken.
@Test
public void testInboundMissingToken() throws ExecutionException, InterruptedException {
ProviderRequest inboundRequest = createInboundRequest("OtherHeader", "tearer " + TOKEN_VALUE);
AuthenticationResponse response = provider.authenticate(inboundRequest).toCompletableFuture().get();
assertThat(response.status(), is(SecurityResponse.SecurityStatus.FAILURE));
assertThat(response.statusCode().orElse(200), is(401));
assertThat(response.responseHeaders().get("WWW-Authenticate"), notNullValue());
}
use of io.helidon.security.AuthenticationResponse in project helidon by oracle.
the class GoogleTokenProviderTest method testInbound.
@Test
public void testInbound() {
ProviderRequest inboundRequest = createInboundRequest("Authorization", "bearer " + TOKEN_VALUE);
AuthenticationResponse response = provider.syncAuthenticate(inboundRequest);
assertThat(response.user(), is(not(Optional.empty())));
response.user().ifPresent(subject -> {
Principal principal = subject.principal();
assertThat(principal.getName(), is(name));
assertThat(principal.id(), is(userId));
});
}
use of io.helidon.security.AuthenticationResponse in project helidon by oracle.
the class HeaderAtnProviderConfigTest method testProviderService.
@Test
public void testProviderService() {
String username = "username";
Security security = Security.create(config.get("security"));
SecurityContext context = security.contextBuilder("unit-test").env(SecurityEnvironment.builder().header("Authorization", "bearer " + username).build()).build();
AuthenticationResponse response = context.atnClientBuilder().buildAndGet();
assertThat(response.status(), is(SecurityResponse.SecurityStatus.SUCCESS));
assertThat(response.user(), is(not(Optional.empty())));
response.user().map(Subject::principal).map(Principal::getName).ifPresent(user -> {
assertThat(user, is(username));
});
assertThat(response.service(), is(Optional.empty()));
}
use of io.helidon.security.AuthenticationResponse 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.AuthenticationResponse 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()));
}
Aggregations