zhongrijian
2024-06-01 f61e96c11098ad78cafb78d16f3f36cb8cefcf77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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);
    }
}