我编写了一个基于OIOSAML的带有 SP 启动 Web SSO 场景的简单系统。为了测试系统,我将它部署在远程主机上。
但是AssertionConsumerServiceURL
,在我指定 URL 的地方,Shibboleth idP(基于 Shibboleth 的 idP)应该返回的答案没有被调用。
SAMLAssertionConsumer
- 只是一个简单的 servlet,像这样:
@WebServlet("/saml/consumer")
public class SAMLAssertionConsumer extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println(new Date() + " incoming AuthResponse");
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Yes, it worked");
System.out.println(new Date() + " incoming AuthResponse");
}
}
首先,我只需要确保响应到来。
我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0"
metadata-complete="false"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
<display-name>OIOSAML-J</display-name>
<listener>
<listener-class>dk.itst.oiosaml.sp.service.session.SessionDestroyListener</listener-class>
</listener>
<servlet>
<servlet-name>SAMLDispatcherServlet</servlet-name>
<servlet-class>dk.itst.oiosaml.sp.service.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SAMLDispatcherServlet</servlet-name>
<url-pattern>/saml/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>dk.itst.oiosaml.sp.service.SPFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/sp/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
我的 oiosaml-sp.properties:
# Properties used by oiosaml-j
# Reference to the location of the certificate used for signing SAML documents with - relative to ${oiosaml.home}
oiosaml-sp.certificate.location=./certificate/keystore
# Opaque/encrypted password to the certificate used for signing SAML documents
oiosaml-sp.certificate.password=some_password
# Required authentication level. 2=password, 3=certificate
oiosaml-sp.assurancelevel=2
# Name of the meta data file for the current service provider - overrides setting in brs-common.properties
common.saml2.metadata.sp.filename=SPMetadata.xml
# URI References to the current service provider
oiosaml-sp.uri.home=
# Whether to validate server certificates. Set to false in production.
# Used for artifact resolution.
oiosaml-sp.resolve.ignorecert=true
# Artifact resolution username and password. Only used the artifact profile is active.
oiosaml-sp.resolve.username=rolf.trifork.com
oiosaml-sp.resolve.password=rolf.trifork.com
生成AuthnRequest
:
<?xml version="1.0" encoding="UTF-8"?>
<saml2p:AuthnRequest xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol"
AssertionConsumerServiceURL="http://ip-of-remote-system-here:8080/saml/consumer"
Destination="http://ip-of-identity-provider-here/idp/profile/SAML2/Redirect/SSO" ForceAuthn="false"
ID="_31e...341d322d1d" IsPassive="false"
IssueInstant="2014-07-11T10:24:43.852Z"
ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Version="2.0">
<saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">http://ip-of-remote-system-here:8080</saml2:Issuer>
</saml2p:AuthnRequest>
有一些 JSP 页面 private.jsp,我向它发出请求:
http://ip-of-remote-system-here:8080/sp/private.jsp
在此请求之后,我重定向到身份提供者的登录页面:
http://ip-of-identity-provider-here/idp/Authn/CommonLogin
输入几个登录名/密码,然后……什么都没有。打开带有一些常见错误描述的页面:
http://ip-of-identity-provider-here/idp/Authn/UsernamePasswordLogin
错误
处理请求时发生错误。
不工作,我的 servlet SAMLAssertionConsumer
,控制台很清楚。但是,如果我直接向我的 servlet 提出请求SAMLAssertionConsumer
:
http://ip-of-remote-system-here:8080/saml/consumer
然后它工作。当然。
我想知道如何正确配置断言消费者服务。那是 SP 元数据的一部分,我在其中指定了断言使用者。
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:esia="urn:esia:shibboleth:2.0:mdext" entityID="http://ip-of-remote-system-here:8080">
...
<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="http://ip-of-remote-system-here:8080/saml/consumer" ResponseLocation="http://ip-of-remote-system-here:8080/saml/consumer"/>
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="http://ip-of-remote-system-here:8080/saml/consumer" index="0" isDefault="true"/>