@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())); }
@Override protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { if (!authenticate) { return AuthenticationResponse.abstain(); } Optional<String> username; try { username = atnTokenHandler.extractToken(providerRequest.env().headers()); } catch (Exception e) { if (optional) { return AuthenticationResponse.abstain(); } else { return AuthenticationResponse.failed("Header not available or in a wrong format", e); } } return username .map(Principal::create) .map(principal -> { if (subjectType == SubjectType.USER) { return AuthenticationResponse.success(principal); } else { return AuthenticationResponse.successService(principal); } }) .orElseGet(() -> { if (optional) { return AuthenticationResponse.abstain(); } else { return AuthenticationResponse.failed("Header not available or in a wrong format"); } } ); }
HeaderAtnProvider extends SynchronousProvider implements AuthenticationProvider, OutboundSecurityProvider { @Override protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { if (!authenticate) { return AuthenticationResponse.abstain(); } Optional<String> username; try { username = atnTokenHandler.extractToken(providerRequest.env().headers()); } catch (Exception e) { if (optional) { return AuthenticationResponse.abstain(); } else { return AuthenticationResponse.failed("Header not available or in a wrong format", e); } } return username .map(Principal::create) .map(principal -> { if (subjectType == SubjectType.USER) { return AuthenticationResponse.success(principal); } else { return AuthenticationResponse.successService(principal); } }) .orElseGet(() -> { if (optional) { return AuthenticationResponse.abstain(); } else { return AuthenticationResponse.failed("Header not available or in a wrong format"); } } ); } }
HeaderAtnProvider extends SynchronousProvider implements AuthenticationProvider, OutboundSecurityProvider { @Override protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { if (!authenticate) { return AuthenticationResponse.abstain(); } Optional<String> username; try { username = atnTokenHandler.extractToken(providerRequest.env().headers()); } catch (Exception e) { if (optional) { return AuthenticationResponse.abstain(); } else { return AuthenticationResponse.failed("Header not available or in a wrong format", e); } } return username .map(Principal::create) .map(principal -> { if (subjectType == SubjectType.USER) { return AuthenticationResponse.success(principal); } else { return AuthenticationResponse.successService(principal); } }) .orElseGet(() -> { if (optional) { return AuthenticationResponse.abstain(); } else { return AuthenticationResponse.failed("Header not available or in a wrong format"); } } ); } private  HeaderAtnProvider(Builder builder); }
HeaderAtnProvider extends SynchronousProvider implements AuthenticationProvider, OutboundSecurityProvider { @Override protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { if (!authenticate) { return AuthenticationResponse.abstain(); } Optional<String> username; try { username = atnTokenHandler.extractToken(providerRequest.env().headers()); } catch (Exception e) { if (optional) { return AuthenticationResponse.abstain(); } else { return AuthenticationResponse.failed("Header not available or in a wrong format", e); } } return username .map(Principal::create) .map(principal -> { if (subjectType == SubjectType.USER) { return AuthenticationResponse.success(principal); } else { return AuthenticationResponse.successService(principal); } }) .orElseGet(() -> { if (optional) { return AuthenticationResponse.abstain(); } else { return AuthenticationResponse.failed("Header not available or in a wrong format"); } } ); } private  HeaderAtnProvider(Builder builder); static HeaderAtnProvider create(Config config); static Builder builder(); @Override boolean isOutboundSupported(ProviderRequest providerRequest,
                                       SecurityEnvironment outboundEnv,
                                       EndpointConfig outboundConfig); }
HeaderAtnProvider extends SynchronousProvider implements AuthenticationProvider, OutboundSecurityProvider { @Override protected AuthenticationResponse syncAuthenticate(ProviderRequest providerRequest) { if (!authenticate) { return AuthenticationResponse.abstain(); } Optional<String> username; try { username = atnTokenHandler.extractToken(providerRequest.env().headers()); } catch (Exception e) { if (optional) { return AuthenticationResponse.abstain(); } else { return AuthenticationResponse.failed("Header not available or in a wrong format", e); } } return username .map(Principal::create) .map(principal -> { if (subjectType == SubjectType.USER) { return AuthenticationResponse.success(principal); } else { return AuthenticationResponse.successService(principal); } }) .orElseGet(() -> { if (optional) { return AuthenticationResponse.abstain(); } else { return AuthenticationResponse.failed("Header not available or in a wrong format"); } } ); } private  HeaderAtnProvider(Builder builder); static HeaderAtnProvider create(Config config); static Builder builder(); @Override boolean isOutboundSupported(ProviderRequest providerRequest,
                                       SecurityEnvironment outboundEnv,
                                       EndpointConfig outboundConfig);  }