現在、ログインページなしでWebを作成しています。春のセキュリティでヘッダーの情報を使ってユーザーを検証する方法
私は情報とヘッダを送信する別のウェブサイトを持っている:
user:John
userCode:1234567
だから私の現在のウェブサイトは、ヘッダの内容をチェックして、このような認証マネージャでユーザーを検証します:
まずI AuthenticationEntryPoint
を作成します。AuthenticationEntryPoint
私はトークンを作成してメインページにリダイレクトするので、メインページに行く前に、springはユーザーを認証し、有効なユーザーのトークンを与えますページ。
@Component
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {
if(authException.getClass().getSimpleName().equals("InsufficientAuthenticationException")) {
if (request.getHeader("user") != null) {
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(request.getHeader("user"), request.getHeader("userCode"));
SecurityContextHolder.getContext().setAuthentication(auth);
response.sendRedirect(request.getContextPath());
}
}
}
AuthenticationManager
でプロセスは通常通り行って、ユーザーが有効であればトークンを与えます:コードは次のようです。私が変える必要があるものか、春に使用できる別のアプローチがありますか?
ありがとうございます!
私はカスタムAuthenticationEntryPointを意味し、事前認証をこのように扱うべきか分かりません。 ref doc:[Http403ForbiddenEntryPoint](http://docs.spring.io/spring-security/site/docs/4.0.x/reference/html/preauth.html#http403forbiddenentrypoint) –