[英]Create SAML Assertion and Sign the response
我有一个Java Web应用程序。 我想为我的应用程序实现SAML单点登录登录。 我有这个GitHub onelogin程序来发送请求并获得响应。 但它没有正常工作。 我在那里创建了一个帐户。 但我没有企业帐户。 当我运行应用程序时,它将进入onelogin登录页面。 我尝试登录,但它没有在响应中返回任何内容,表明我没有权限。 如果我也提供了错误的凭据,则它不会给出任何SAML响应。
所以我决定创建一个断言并签名。
谢谢
更新1
<?xml version="1.0" encoding="UTF-8"?>
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
ID="123" InResponseTo="abc" IssueInstant="2014-11-21T17:13:42.872Z"
Version="2.0">
<samlp:Status>
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>
</samlp:Status>
<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0">
<saml:Subject>
<saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress">
user@example.com
</saml:NameID>
</saml:Subject>
<saml:AuthnStatement AuthnInstant="2014-11-21T17:13:42.899Z">
<saml:AuthnContext>
<saml:AuthnContextClassRef>
urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
</saml:Assertion>
</samlp:Response>
您需要做的第一件事是阅读SAML协议。 我有两个可以推荐的博客。
接下来,您可以选择在应用程序中构建SAML集成,也可以使用第三方应用程序进行集成。 典型的第三方应用程序是Shibboleth和OpenAM 。
如果您决定将其构建到应用程序中,则可以使用OpenSAML。 OpenSAML是一个有助于处理SAML消息的库。 我有几个关于这个主题的博客和一本很好的书
关于你的问题。
您还可以使用Onelogin中的Java Saml使用其实用程序类(com.onelogin.saml2.util.Util)对响应进行签名:
// loads xml string into Document
Document document = Util.loadXML(saml);
// loads certificate and private key from string
X509Certificate cert = Util.loadCert(pubKeyBytes);
PrivateKey privateKey = Util.loadPrivateKey(privKeyBytes);
// signs the response
String signedResponse = Util.addSign(document, privateKey, cert, null);
您还可以使用另一个.addSign
方法,该方法将Node
作为第一个参数来签署SAML响应的断言。
他们的Maven依赖是:
<dependency>
<groupId>com.onelogin</groupId>
<artifactId>java-saml</artifactId>
<version>2.0.0</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.