package com.sdw.soft.common.auth.security.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;

/**
 * @author syd
 * @Date 2013年12月26日
 * @version 1.0.0
 * Copyright (c) 2013
 */
public class ExtAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
	
	private static final Logger logger = LoggerFactory.getLogger(ExtAuthenticationSuccessHandler.class);
	
	@Override
	public void onAuthenticationSuccess(HttpServletRequest request,
			HttpServletResponse response, Authentication authentication)
			throws ServletException, IOException {
		logger.info("login success ....");
		super.onAuthenticationSuccess(request, response, authentication);
	}
}

@@ -264,16 +264,75 @@
 actory;%0A
+import org.springframework.beans.factory.annotation.Value;%0A
 import o
@@ -481,16 +481,273 @@
 Handler;
+%0Aimport org.springframework.security.web.savedrequest.HttpSessionRequestCache;%0Aimport org.springframework.security.web.savedrequest.RequestCache;%0Aimport org.springframework.security.web.savedrequest.SavedRequest;%0Aimport org.springframework.util.StringUtils;
 %0A%0A/**%0A *
@@ -820,16 +820,79 @@
 c) 2013%0A
+ * %E8%87%AA%E5%AE%9A%E4%B9%89%E7%99%BB%E5%BD%95%E6%88%90%E5%8A%9F%E5%90%8E%E7%9A%84%E5%9B%9E%E8%B0%83%E5%9C%B0%E5%9D%80 %0A * http://cl315917525.iteye.com/blog/1768396%0A
  */%0Apubl
@@ -1091,16 +1091,85 @@
 .class);
+%0A%0A%09private RequestCache requestCache = new HttpSessionRequestCache();
 %0A%09%0A%09@Ove
@@ -1238,20 +1238,16 @@
 request,
-%0A%09%09%09
 HttpServ
@@ -1384,75 +1384,1156 @@
 ;%0A%09%09
-super.onAuthenticationSuccess(request, response, authentication);%0A%09%7D
+SavedRequest savedRequest = requestCache.getRequest(request, response);%0A%09%09 if (savedRequest == null) %7B%0A%09            super.onAuthenticationSuccess(request, response, authentication);%0A%0A%09            return;%0A%09        %7D%0A%09        String targetUrlParameter = getTargetUrlParameter();%0A%09        if (isAlwaysUseDefaultTargetUrl() %7C%7C (targetUrlParameter != null && StringUtils.hasText(request.getParameter(targetUrlParameter)))) %7B%0A%09            requestCache.removeRequest(request, response);%0A%09            super.onAuthenticationSuccess(request, response, authentication);%0A%0A%09            return;%0A%09        %7D%0A%0A%09        clearAuthenticationAttributes(request);%0A%0A%09        // Use the DefaultSavedRequest URL%0A%09        String targetUrl = savedRequest.getRedirectUrl();%0A%09        logger.debug(%22Redirecting to DefaultSavedRequest Url: %22 + targetUrl);%0A%09        String targeturl = this.determineTargetUrl(request, response);%0A%09        logger.info(%22$$$$$$$$$$$$$$$$$$$$$$$$%7B%7D%22,targeturl);%0A%09        getRedirectStrategy().sendRedirect(request, response, targeturl);%0A%09%7D%0A%09%0A%09public void setRequestCache(RequestCache requestCache) %7B  %0A        this.requestCache = requestCache;  %0A    %7D 
 %0A%7D%0A

修复自定义验证通过回调url 在服务器启动第一次验证成功后defaultTargetUrl='/index.jsp'的bug 暂时暴力解决待优化