在SAML LogoutRequest实例中设置会话索引

时间:2018-09-12 09:08:43

标签: single-sign-on saml-2.0 opensaml

我正尝试通过LogoutRequest类使用opensaml库创建单个注销请求。在请求对象中没有设置会话索引的方法。如何构造LogoutRequest? 我用来构造请求对象的代码段如下:

SAMLObjectBuilder<LogoutRequest> builder = (SAMLObjectBuilder<LogoutRequest>) builderFactory.getBuilder(LogoutRequest.DEFAULT_ELEMENT_NAME);

LogoutRequest request = builder.buildObject();
request.setID(generateID());
request.setVersion(SAMLVersion.VERSION_20);
request.setIssueInstant(new DateTime());
request.setDestination(bindingService.getLocation());

SAMLObjectBuilder<Issuer> issuerBuilder = (SAMLObjectBuilder<Issuer>) builderFactory.getBuilder(Issuer.DEFAULT_ELEMENT_NAME);
Issuer issuer = issuerBuilder.buildObject();
issuer.setValue(metadata.getHostedSPName());
request.setIssuer(issuer);

SAMLObjectBuilder<NameID> namdIDBuilder = (SAMLObjectBuilder<NameID>) builderFactory.getBuilder(NameID.DEFAULT_ELEMENT_NAME);
NameID nameid = namdIDBuilder.buildObject();
nameid.setFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:transient");
request.setNameID(nameid);

SAMLObjectBuilder<SessionIndex> sessionIndexBuilder = (SAMLObjectBuilder<SessionIndex>) builderFactory.getBuilder(SessionIndex.DEFAULT_ELEMENT_NAME);
SessionIndex sessionindex = sessionIndexBuilder.buildObject();
sessionindex.setSessionIndex(sessionIndex);

如上所述,构建SessionIndex之后,无法在LogoutRequest对象中进行设置。

有人可以向我展示一些示例或链接以使其正确吗?

1 个答案:

答案 0 :(得分:0)

我设法通过以下方式做到这一点:

SessionIndex sessionIndex_ = (SessionIndex) Configuration.getBuilderFactory()
                                            .getBuilder(SessionIndex.DEFAULT_ELEMENT_NAME)
                                            .buildObject(SessionIndex.DEFAULT_ELEMENT_NAME);                
sessionIndex_.setSessionIndex("test");
request.getSessionIndexes()
       .add(sessionIndex_);