public Optional<UserDto> authenticate(HttpRequest request) {
    return extractCredentialsFromHeader(request)
      .flatMap(credentials -> Optional.ofNullable(authenticate(credentials, request)));
  }
@Test
  public void does_not_authenticate_from_user_token_when_token_is_invalid() {
    when(userTokenAuthentication.authenticate(request)).thenReturn(Optional.empty());
    when(request.getHeader(AUTHORIZATION_HEADER)).thenReturn("Basic " + toBase64("token:"));

    assertThatThrownBy(() -> underTest.authenticate(request))
      .hasMessage("User doesn't exist")
      .isInstanceOf(AuthenticationException.class)
      .hasFieldOrPropertyWithValue("source", Source.local(SONARQUBE_TOKEN));

    verifyNoInteractions(authenticationEvent);
    verify(request, times(0)).setAttribute(anyString(), anyString());
  }