0

我有一个使用第三方OpenID提供商登录的工作“依赖方”应用程序。但是,如果我尝试使用使用 的“本土”OpenID提供商登录,则不会在和org.openid4java.server.SampleServer之间维护会话。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");
}

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

4

1 回答 1

0

我能够在 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 类或文档没有提到这是可能的需求仍然让人感到神秘,这让我想知道我的设置是否以其他方式“错误”。向前...

于 2014-09-16T11:01:10.310 回答