Java Spring security 3.1单点登录LDAP
我正在尝试将单点登录添加到不同域上的两个遗留系统。当前具有工作“常规”登录的。 我发现了这一点,但我不确定第1步,更具体地说是这一步 “实现将身份验证对象序列化并写入具有全局作用域的会话cookie的功能。” 如果我理解正确,我应该提取sessionID并将其添加到具有全局作用域的新cookie中 我开始试着提取sessionID,就像这样Java Spring security 3.1单点登录LDAP,java,spring-security,single-sign-on,Java,Spring Security,Single Sign On,我正在尝试将单点登录添加到不同域上的两个遗留系统。当前具有工作“常规”登录的。 我发现了这一点,但我不确定第1步,更具体地说是这一步 “实现将身份验证对象序列化并写入具有全局作用域的会话cookie的功能。” 如果我理解正确,我应该提取sessionID并将其添加到具有全局作用域的新cookie中 我开始试着提取sessionID,就像这样 import org.springframework.security.core.Authentication; import org.springfram
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
public class AuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response,
Authentication authentication) throws IOException,ServletException {
Cookie cookie = null;
UsernamePasswordAuthenticationToken auth = (UsernamePasswordAuthenticationToken) authentication;
if (authentication.getDetails() != null) {
WebAuthenticationDetails dets = (WebAuthenticationDetails) auth.getDetails();
System.out.println("sessionID: " + dets.getSessionId());
}
response.addCookie(cookie);
super.onAuthenticationSuccess(request,response,authentication);
}
}
为了验证我是否在正确的轨道上,我将sessionID打印到终端,并将其与spring安全性在浏览器中设置的sessionID进行比较。如果我理解正确,它们应该匹配。他们不匹配。我是否误解了答案中建议的解决方案?单点登录是一个很难解决的问题。我真的不建议尝试实现它,除非您对问题以及如何解决问题有很好的把握。如果可以,我强烈建议您尝试使用Oauth2,而不是自己实现它 可能会给你一个起点 如果您使用的是JBoss或WebSphere之类的应用程序服务器,则可以使用它们的SSO选项