Как добавить Cook ie с AuthenticationProvider - PullRequest
0 голосов
/ 05 августа 2020

Я создаю приложение с Java и SpringFramework, и я использую AuthenticationProvider.

После аутентификации я хотел бы добавить кулинарию, но я не уверен, где это сделать.

Это то, что я пробовал, но я все еще не вижу повара ie:

// CustomAuthenticationProvider.java
public class CustomAuthenticationProvider implements AuthenticationProvider {
  @Override
  public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String name = authentication.getName();
    String password = authentication.getCredentials().toString();
    UserAuthenticationRequest loginRequest = new UserAuthenticationRequest(name, password);
    Client client = ClientBuilder.newBuilder()
      .register(JacksonConfig.class)
      .register(JacksonFeature.class)
      .build();

    Invocation.Builder request = client.target(apiBaseUrl)
      .path("login")
      .request(MediaType.APPLICATION_JSON);
    
    Cookie cookie = new Cookie("Secure", "Secure");
    request.cookie(cookie);

    Response response = request.post(Entity.json(loginRequest));
    
    if (response.getStatus() == 200) {
      return new UsernamePasswordAuthenticationToken(name, password, new ArrayList<>());
    } else {
      ExceptionResponse errorResponse = response.readEntity(ExceptionResponse.class);
      return null;          
    }
  }
}

Но когда я вхожу в систему, я все еще не вижу Secure в моих файлах cookie.

Как правильно его добавить?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...