【问题标题】:openid RP not maintaining session between calls to provideropenid RP 未在对提供者的调用之间维护会话
【发布时间】:2014-11-09 04:54:49
【问题描述】:

我有一个使用第三方OpenID 提供程序进行登录的“依赖方”应用程序。但是,如果我尝试使用使用org.openid4java.server.SampleServer 的“本土”OpenID 提供程序登录,则不会在beginConsumptionendConsumption 之间维护会话。

我可以看到成功的发现和关联,这在 springs OpenID4JavaConsumer 中实现:

DiscoveryInformation information = consumerManager.associate(discoveries);
req.getSession().setAttribute(DISCOVERY_INFO_KEY, information);

但是在我的 OP 进行身份验证并将 response.sendRedirect 返回到 RP 之后,在那里开始了一个新会话,并且我在 OpenID4JavaConsumer.endConsumption 失败了:

DiscoveryInformation discovered = 
    (DiscoveryInformation) request.getSession().getAttribute(DISCOVERY_INFO_KEY);

if (discovered == null) {
    throw new OpenIDConsumerException("DiscoveryInformation is not available. Possible causes are lost session or replay attack");
}

是什么导致了这个新会话被创建,我怎样才能保留我的旧会话?

【问题讨论】:

    标签: session openid session-state httpsession openid4java


    【解决方案1】:

    我可以在 OP 代码中使用这个来跳过这个:

    Cookie sessionCookie = getSessionCookie(request.getCookies());
    if (sessionCookie != null) {
        response.addCookie(sessionCookie);
    }
    String url = response.encodeRedirectURL(responseBody);
    response.sendRedirect(url);
    

    private Cookie getSessionCookie(Cookie[] cookies) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equalsIgnoreCase("JSESSIONID")) {
                return cookie;
            }
        }
        return null;
    }
    

    表面上这是有道理的,但 OpenId SampleServer 类或文档没有提到这是可能的需求,这让我想知道我的设置是否以其他方式“错误”。前进...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-10
      • 1970-01-01
      • 1970-01-01
      • 2019-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多