package org.springblade.auth.config;
|
|
import org.apache.logging.log4j.util.Strings;
|
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
|
import org.springframework.security.core.AuthenticationException;
|
import javax.servlet.ServletException;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.nio.charset.StandardCharsets;
|
|
public class CustomAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint {
|
|
public CustomAuthenticationEntryPoint(String loginFormUrl) {
|
super(loginFormUrl);
|
}
|
|
@Override
|
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
|
String queryString = request.getQueryString();
|
String query = !Strings.isBlank(queryString)?"?"+queryString:"";
|
String redirectUrl = getLoginFormUrl() + query;
|
response.sendRedirect(redirectUrl);
|
}
|
}
|