Java 验证IDP启动的SAML2.0响应

Java 验证IDP启动的SAML2.0响应,java,jsp,tomcat6,saml-2.0,opensaml,Java,Jsp,Tomcat6,Saml 2.0,Opensaml,SAML专家请帮忙 我对SAML和JSP非常陌生。我想使用java(Environment linux,Tomcat6.0)中的Opensaml库验证IDP(identity provider)启动的SAML响应令牌,并检索发送的属性信息,如用户ID、用户名、电子邮件。SAML响应未加密,我的java密钥库中安装了IDP的信任证书。SAML令牌配置文件为“web浏览器SSO”“它使用HTTP-POST绑定。证书中有一个公钥。我是否需要私钥进行验证?成功验证需要执行哪些步骤?仅进行数字签名验证就足

SAML专家请帮忙

我对SAML和JSP非常陌生。我想使用java(Environment linux,Tomcat6.0)中的Opensaml库验证IDP(identity provider)启动的SAML响应令牌,并检索发送的属性信息,如用户ID、用户名、电子邮件。SAML响应未加密,我的java密钥库中安装了IDP的信任证书。SAML令牌配置文件为“web浏览器SSO”“它使用HTTP-POST绑定。证书中有一个公钥。我是否需要私钥进行验证?成功验证需要执行哪些步骤?仅进行数字签名验证就足以信任源?我应该进行配置文件验证还是其他什么?下面给出的是我将从IDP收到的SAML响应。 如果你需要更多的信息,请告诉我。如果我没有提供足够的信息,很抱歉。请帮助我…提前谢谢

<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" ID="XYZ" Version="2.0" IssueInstant="2013-07-10T16:43:54Z" Destination="http://www.testsp.com">
  <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">http://www.testidp.com:8080/opensso</saml:Issuer> 
- <samlp:Status xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
  <samlp:StatusCode xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" Value="urn:oasis:names:tc:SAML:2.0:status:Success" /> 
  </samlp:Status>
- <saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="xyz" IssueInstant="2013-07-10T16:43:51Z" Version="2.0">
  <saml:Issuer>http://www.testidp.com:8080/opensso</saml:Issuer> 
- <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
- <ds:SignedInfo>
  <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> 
  <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /> 
- <ds:Reference URI="#xyz">
- <ds:Transforms>
  <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /> 
  <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> 
  </ds:Transforms>
  <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /> 
  <ds:DigestValue>...hdfb3454jh545dfbj545423df....=</ds:DigestValue> 
  </ds:Reference>
  </ds:SignedInfo>
  <ds:SignatureValue>..................hsdgysgdyyusgfdfb98738e43hjrg874y474h7y8r............=</ds:SignatureValue> 
- <ds:KeyInfo>
- <ds:X509Data>
  <ds:X509Certificate>............./KPm0qLP8vCOhyI76AUE6jL NFeTlcAe3B6hOdfKCiu+EtHeZC2i/8jf1rHDNPey4TS1MQj/.......
</ds:X509Certificate> 
  </ds:X509Data>
  </ds:KeyInfo>
  </ds:Signature>
- <saml:Subject>
  <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient" NameQualifier="http://www.testidp.com:8080/opensso" SPNameQualifier="http://www.testsp.com">....Zeq8NhJKRKDXUwx67ytuynwj4n...</saml:NameID> 
- <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
  <saml:SubjectConfirmationData NotOnOrAfter="2013-07-10T16:53:51Z" Recipient="http://www.testsaml.com/tespsamlmodule" /> 
  </saml:SubjectConfirmation>
  </saml:Subject>
- <saml:Conditions NotBefore="2013-07-10T16:33:51Z" NotOnOrAfter="2013-07-10T16:53:51Z">
- <saml:AudienceRestriction>
  <saml:Audience>http://www.testsaml.com/tespsamlmodule</saml:Audience> 
  </saml:AudienceRestriction>
  </saml:Conditions>
- <saml:AuthnStatement AuthnInstant="2013-07-10T16:36:35Z" SessionIndex="......erer54t54y45y75666y65y65y....">
- <saml:AuthnContext>
  <saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef> 
  </saml:AuthnContext>
  </saml:AuthnStatement>
- <saml:AttributeStatement>
- <saml:Attribute Name="UID">
  <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">ab123</saml:AttributeValue> 
  </saml:Attribute>
- <saml:Attribute Name="uname">
  <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">robert</saml:AttributeValue> 
  </saml:Attribute>
- <saml:Attribute Name="EmailAddress">
  <saml:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string">robert@example.com</saml:AttributeValue> 
  </saml:Attribute>
  </saml:AttributeStatement>
  </saml:Assertion>
  </samlp:Response>

http://www.testidp.com:8080/opensso 
- 
- 
http://www.testidp.com:8080/opensso 
- 
- 
- 
- 
…HDFB3454JH545DFBJ5423DF….=
hsdgysgdyyusgfdfb98738e43hjrg874y474h7y8r
- 
- 
KPm0qLP8vCOhyI76AUE6jL NFeTlcAe3B6hOdfKCiu+EtHeZC2i/8jf1rHDNPey4TS1MQj/。。。。。。。
- 
…ZEQ8NHJKKDXUWX67YTUYNWJ4N。。。
- 
- 
- 
http://www.testsaml.com/tespsamlmodule 
- 
- 
urn:oasis:name:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
- 
- 
ab123
- 
罗伯特
- 
robert@example.com 

您需要根据SAML规范验证响应。OpenSAML中有一些功能可以实现这一点,但我认为最安全的方法是编写自己的验证代码。看

您还必须验证签名。与所有签名验证一样,您使用公钥。下面是我在博客上写的一些关于OpenSAML签名验证的文章


在我的书中,我有更多关于使用OpenSAML进行签名和加密的内容,

以下是我在我的WEB应用程序上为IDP启动的SAML响应实现单点登录功能所遵循的步骤

先决条件:

  • 为opensaml java库导入所有必需和依赖的jar文件
  • 将IDP的数字证书上载到java密钥库
  • 在服务器上创建负责SAML身份验证的JSP文件
  • 对收到的SAML消息执行不同类型的验证,以确保源(siganture验证)、消息完整性(引用验证)和断言验证(检查断言有效性时间)
  • 代码: 本博客提供了一个很好的示例,它将帮助您构建自己的SAML SP安装


    从他们的archieve下载所有必需的jar文件,这将为您节省大量时间来下载依赖版本的jar

    嘿,Stefan,你的博客太棒了!!!!现在我有了正在工作的SAML SP。根据我的客户要求,我正在进行签名验证、参考验证和响应条件验证,以允许访问webportal。有用的和相关的