package org.springblade.auth.config; import org.apache.logging.log4j.util.Strings; import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Map; public class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandler { private String redirectUrl; public CustomAuthenticationSuccessHandler(String redirectUrl) { this.redirectUrl = redirectUrl; } @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { // String requestURI = request.getRequestURI(); Map parameterMap = request.getParameterMap(); StringBuilder builder = new StringBuilder(); if (parameterMap.size()>0){ builder.append("?"); } String client_id = request.getHeader("client_id"); String response_type = request.getHeader("response_type"); String redirect_uri = request.getHeader("redirect_uri"); // 拼接 if (!Strings.isBlank(client_id)){ builder.append("client_id=").append(client_id) .append("&") .append("response_type=").append(response_type) .append("&") .append("redirect_uri=").append(redirect_uri); } // 跳转 response.sendRedirect(redirectUrl + builder.toString()); } }