フォームのログイン


フォームのログイン


DefaultLoginPageGeneratingFilter


処理
  • GET/login
  • で提供されるフィルタ
  • は、個別のログインページを設定する必要はありません.
  • は、デフォルトのログインフォーム
  • を提供する.
  • OAuth 2/OpenID/saml 2ログイン.
  • UsernamePasswordAuthenticationFilter


  • POST/loginを処理します.ProcessingUrlを変更すると、アドレスを変更できます.

  • form認証の処理に使用されるフィルタは、Spring Securityで最もよく使用されます.

  • キー設定について
  • FilterProcessing Url:ログイン処理用URL(POST)
  • usernameパラメータ:username値をPOSTに渡すパラメータ名
  • passwordパラメータ:password値をPOSTのパラメータ名
  • に渡す
  • ログイン成功時の処理方法
  • defaultSuccessUrl:alwaysUseオプション設定が重要
  • successHandler
  • ログイン失敗時の処理方法
  • failureUrl
  • failureHandler
  • authenticationDetailSource:authenticationオブジェクトの詳細.
  • @Override
    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
    		throws AuthenticationException {
    	if (this.postOnly && !request.getMethod().equals("POST")) {
    		throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
    	}
    	String username = obtainUsername(request);
    	username = (username != null) ? username : "";
    	username = username.trim();
    	String password = obtainPassword(request);
    	password = (password != null) ? password : "";
    	UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
    	// Allow subclasses to set the "details" property
    	setDetails(request, authRequest);
    	return this.getAuthenticationManager().authenticate(authRequest);
    }

    DefaultLogoutPageGeneratingFilter


    処理
  • GET/logout
  • は、POST/logoutを要求可能なユーザインタフェース
  • を提供する.
    この機能は、
  • D e f a u l t R o ginPageGenerationFilterを使用する場合に提供されます.
  • LogoutFilter


  • POST/logoutを処理します.processiongUrlは変更できます.

  • ログアウトの処理
    削除処理
  • セッション、SecurityContext、csrf、Cookie、remember-me Cookieなど.
  • (デフォルト)ログインページ
  • にリダイレクト
    private void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
    		throws IOException, ServletException {
    	if (requiresLogout(request, response)) {
    		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    		if (this.logger.isDebugEnabled()) {
    			this.logger.debug(LogMessage.format("Logging out [%s]", auth));
    		}
    		this.handler.logout(request, response, auth);
    		this.logoutSuccessHandler.onLogoutSuccess(request, response, auth);
    		return;
    	}
    	chain.doFilter(request, response);
    }

  • LogoutHandler
  • void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication);
  • SecurityContextLogoutHandler:セッションとSecurityContextをクリアします.
  • CookieClearingLogoutHandler:clearターゲットとなるCookieを削除します.
  • CSrfLogoutHandler:csrfTokenRepositoryでcsrfトークンをクリアします.
  • HeaderWriterLogoutHandler
  • RememberMeServices:rememore-me Cookieを削除します.
  • LogoutSuccessEvent発行LogoutHandler:ログアウトに成功した場合、イベントが発行されます.

  • LogoutSuccessHandler
  • void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
    throws IOException, ServletException;
  • SimpleUrlLogoutSuccessHandler