首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring-security 3.1单点登录LDAP

Spring-security 3.1单点登录LDAP
EN

Stack Overflow用户
提问于 2020-09-04 23:27:19
回答 1查看 58关注 0票数 0

我正在尝试将单点登录添加到不同域上的两个遗留系统。目前有正常的“常规”登录。我找到了这个https://stackoverflow.com/a/9925146,但我不确定步骤1,更具体地说,是“实现序列化功能,并将身份验证对象写入具有全局作用域的会话cookie”。如果我理解正确,我应该提取sessionID并将其添加到具有全局作用域的新cookie中。

我首先尝试提取sessionID,如下所示

代码语言:javascript
复制
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-security在浏览器中设置的sessionID进行比较。如果我理解正确的话,它们应该是匹配的。它们不匹配。我是否误解了答案中提出的解决方案?

EN

回答 1

Stack Overflow用户

发布于 2020-09-04 23:37:23

单点登录是一个很难解决的问题。我真的不建议您尝试实现它,除非您很好地掌握了问题以及如何解决它。如果可以,我强烈建议您尝试使用Oauth2,而不是自己实现它。

https://www.baeldung.com/sso-spring-security-oauth2可能会给你一个起点。

如果您使用的是诸如JBoss或WebSphere之类的应用服务器,则可以使用它们的单点登录选项。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63744020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档