具有Spring安全性的SSO
我有一个应用程序,其中用户由SSO预授权并登录到我的页面,现在我需要调用另一个rest api来获取一些数据,这些数据正在另一台服务器上运行,但将使用相同的身份验证。所以我只是想知道,如何提供身份验证过程?我是否需要设置从传入请求中获取的cookie。当请求到达您的页面时,它应该在http授权标头中有一个令牌或密钥,该令牌或密钥应该与筛选器一起使用 公共类AuthFilter扩展了OncePerRequestFilter{具有Spring安全性的SSO,spring,spring-security,single-sign-on,Spring,Spring Security,Single Sign On,我有一个应用程序,其中用户由SSO预授权并登录到我的页面,现在我需要调用另一个rest api来获取一些数据,这些数据正在另一台服务器上运行,但将使用相同的身份验证。所以我只是想知道,如何提供身份验证过程?我是否需要设置从传入请求中获取的cookie。当请求到达您的页面时,它应该在http授权标头中有一个令牌或密钥,该令牌或密钥应该与筛选器一起使用 公共类AuthFilter扩展了OncePerRequestFilter{ private String failureUrl; private
private String failureUrl;
private SimpleUrlAuthenticationFailureHandler failureHandler = new SimpleUrlAuthenticationFailureHandler();
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException {
try {
// check your SSO token here
chain.doFilter(request, response);
} catch (OnlineDriverEnquiryException ode) {
failureHandler.setDefaultFailureUrl(failureUrl);
failureHandler.onAuthenticationFailure(request, response, new BadCredentialsException("Captcha invalid!"));
}
}
public String getFailureUrl() {
return failureUrl;
}
public void setFailureUrl(String failureUrl) {
this.failureUrl = failureUrl;
}
}
还可以阅读这篇关于如何设置自动配置的文章