Spring Security OAuth2经过负载均衡导致redirect_uri使用http而不是https报redirect_uri mismatch错误

解决办法:添加前置过滤器,强制将scheme配置为https,将serverPort配置为443

1
2
3
4
5
6
7
8
9
10
11
12
@Slf4j
public class MyPreFilter implements Filter {

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
MyRequestWrapper myRequestWrapper = new MyRequestWrapper(httpRequest);

filterChain.doFilter(myRequestWrapper, servletResponse);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Slf4j
public class MyRequestWrapper extends HttpServletRequestWrapper {

public MyRequestWrapper(HttpServletRequest request) {
super(request);
}

@Override
public String getScheme() {
return "https";
}

@Override
public int getServerPort() {
return 443;
}
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2021 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :