当前位置: 首页 > 知识库问答 >
问题:

通过集成Spring SAML(作为SP)和SimpleSAML(作为IdP)来转发错误

秦禄
2023-03-14

为了在我的webapp中支持SSO和SLO,我使用Spring Security SAML扩展实现了一个服务提供商。

代码在GitHub上可用:vdenotaris/spring-boot-saml。

通过使用ssocycle作为身份提供者,一切都很好。

现在,我正在尝试链接另一个基于简单SAML的IdP,在这种情况下,SSO失败了。

通过分析我的应用程序服务器(Apache Tomcat 7.0.54)上的日志,我发现了以下错误:

root@pr01tom01:/opt/apache-tomcat-7.0.54/logs# tail -n 10000 localhost.2014-07-14.log | grep SEVERE
    SEVERE: Servlet.service() for servlet dispatcherServlet threw exception
    SEVERE: Servlet.service() for servlet dispatcherServlet threw exception
    SEVERE: Servlet.service() for servlet dispatcherServlet threw exception
    SEVERE: Servlet.service() for servlet dispatcherServlet threw exception
    SEVERE: Servlet.service() for servlet dispatcherServlet threw exception
    SEVERE: Servlet.service() for servlet dispatcherServlet threw exception
    SEVERE: Servlet.service() for servlet dispatcherServlet threw exception
    SEVERE: Servlet.service() for servlet dispatcherServlet threw exception
    SEVERE: Servlet.service() for servlet dispatcherServlet threw exception
root@pr01tom01:/opt/apache-tomcat-7.0.54/logs# tail -n 10000 localhost.2014-07-14.log | grep java.lang.IllegalStateException
    java.lang.IllegalStateException: Cannot forward after response has been committed
    java.lang.IllegalStateException: Cannot forward after response has been committed
    java.lang.IllegalStateException: Cannot forward after response has been committed
    java.lang.IllegalStateException: Cannot forward after response has been committed
    java.lang.IllegalStateException: Cannot forward after response has been committed
    java.lang.IllegalStateException: Cannot forward after response has been committed
    java.lang.IllegalStateException: Cannot forward after response has been committed

有没有办法解决此问题?

问候,V。

Spring调试日志:

[2014-07-15 18:20:57.314] boot - 1092 DEBUG [http-bio-443-exec-6] --- SAMLContextProviderImpl: Using user specified IDP https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php from request
[2014-07-15 18:20:57.314] boot - 1092 DEBUG [http-bio-443-exec-6] --- ChainingMetadataProvider: Checking child metadata provider for entity descriptor with entity ID: https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php
[2014-07-15 18:20:57.314] boot - 1092 DEBUG [http-bio-443-exec-6] --- AbstractMetadataProvider: Searching for entity descriptor with an entity ID of https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php
[2014-07-15 18:20:57.315] boot - 1092 DEBUG [http-bio-443-exec-6] --- AbstractMetadataProvider: Metadata document did not contain a descriptor for entity https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php
[2014-07-15 18:20:57.315] boot - 1092 DEBUG [http-bio-443-exec-6] --- AbstractMetadataProvider: Metadata document did not contain any role descriptors of type {urn:oasis:names:tc:SAML:2.0:metadata}IDPSSODescriptor for entity https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php
[2014-07-15 18:20:57.315] boot - 1092 DEBUG [http-bio-443-exec-6] --- AbstractMetadataProvider: Metadata document does not contain a role of type {urn:oasis:names:tc:SAML:2.0:metadata}IDPSSODescriptor supporting protocol urn:oasis:names:tc:SAML:2.0:protocol for entity https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php
[2014-07-15 18:20:57.315] boot - 1092 DEBUG [http-bio-443-exec-6] --- ChainingMetadataProvider: Checking child metadata provider for entity descriptor with entity ID: https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php
[2014-07-15 18:20:57.316] boot - 1092 DEBUG [http-bio-443-exec-6] --- AbstractMetadataProvider: Searching for entity descriptor with an entity ID of https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php
[2014-07-15 18:20:57.316] boot - 1092 DEBUG [http-bio-443-exec-6] --- AbstractMetadataProvider: Metadata document did not contain a descriptor for entity https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php
[2014-07-15 18:20:57.316] boot - 1092 DEBUG [http-bio-443-exec-6] --- AbstractMetadataProvider: Metadata document did not contain any role descriptors of type {urn:oasis:names:tc:SAML:2.0:metadata}IDPSSODescriptor for entity https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php
[2014-07-15 18:20:57.316] boot - 1092 DEBUG [http-bio-443-exec-6] --- AbstractMetadataProvider: Metadata document does not contain a role of type {urn:oasis:names:tc:SAML:2.0:metadata}IDPSSODescriptor supporting protocol urn:oasis:names:tc:SAML:2.0:protocol for entity https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php
[2014-07-15 18:20:57.317] boot - 1092 DEBUG [http-bio-443-exec-6] --- ChainingMetadataProvider: Checking child metadata provider for entity descriptor with entity ID: https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php
[2014-07-15 18:20:57.317] boot - 1092 DEBUG [http-bio-443-exec-6] --- AbstractMetadataProvider: Searching for entity descriptor with an entity ID of https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/metadata.php
[2014-07-15 18:20:57.317] boot - 1092 DEBUG [http-bio-443-exec-6] --- SAMLUtil: Index for AssertionConsumerService not specified, returning default
[2014-07-15 18:20:57.317] boot - 1092 DEBUG [http-bio-443-exec-6] --- SAML2MetadataHelper: Selecting default IndexedEndpoint
[2014-07-15 18:20:57.318] boot - 1092 DEBUG [http-bio-443-exec-6] --- SAML2MetadataHelper: Selected IndexedEndpoint with explicit isDefault of true
[2014-07-15 18:20:57.318] boot - 1092 DEBUG [http-bio-443-exec-6] --- SAMLEntryPoint: Processing SSO using WebSSO profile
[2014-07-15 18:20:57.318] boot - 1092 DEBUG [http-bio-443-exec-6] --- SAML2MetadataHelper: Selecting default IndexedEndpoint
[2014-07-15 18:20:57.318] boot - 1092 DEBUG [http-bio-443-exec-6] --- SAML2MetadataHelper: Selected IndexedEndpoint with explicit isDefault of true
[2014-07-15 18:20:57.318] boot - 1092 DEBUG [http-bio-443-exec-6] --- SAML2MetadataHelper: Selecting default IndexedEndpoint
[2014-07-15 18:20:57.318] boot - 1092 DEBUG [http-bio-443-exec-6] --- SAML2MetadataHelper: Selected IndexedEndpoint with explicit isDefault of true
[2014-07-15 18:20:57.319] boot - 1092 DEBUG [http-bio-443-exec-6] --- SAML2MetadataHelper: Selecting default IndexedEndpoint
[2014-07-15 18:20:57.319] boot - 1092 DEBUG [http-bio-443-exec-6] --- SAML2MetadataHelper: Selected IndexedEndpoint with explicit isDefault of true
[2014-07-15 18:20:57.319] boot - 1092 DEBUG [http-bio-443-exec-6] --- WebSSOProfileImpl: Using default consumer service with binding urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact
[2014-07-15 18:20:57.319] boot - 1092 DEBUG [http-bio-443-exec-6] --- BaseMessageEncoder: Beginning encode message to outbound transport of type: org.opensaml.ws.transport.http.HttpServletResponseAdapter
[2014-07-15 18:20:57.320] boot - 1092 DEBUG [http-bio-443-exec-6] --- HTTPRedirectDeflateEncoder: Deflating and Base64 encoding SAML message
[2014-07-15 18:20:57.320] boot - 1092 DEBUG [http-bio-443-exec-6] --- BaseMessageEncoder: Marshalling message
[2014-07-15 18:20:57.323] boot - 1092 DEBUG [http-bio-443-exec-6] --- HTTPRedirectDeflateEncoder: Building URL to redirect client to
[2014-07-15 18:20:57.323] boot - 1092 DEBUG [http-bio-443-exec-6] --- HTTPRedirectDeflateEncoder: Generating signature with key type 'RSA', algorithm URI 'http://www.w3.org/2000/09/xmldsig#rsa-sha1' over query string 'SAMLRequest=fVLBbuMgFPwVxN1gbKdpUZzK3W61lhptFCettJcVsXFNhMHLg6j79%2Bs4iba99PjEvJl5Myzu33uNjtKBsibHjMQYSVPbRpm3HO%2B2T9Etvl8uQPQ6GXgRfGc28k%2BQ4NG4aICfX3IcnOFWgAJuRC%2BB%2B5pXxeqZJyTmg7Pe1lZjVABI50epb9ZA6KWrpDuqWu42zznuvB%2BAUzo4Bb2AgdTahoY4Oei%2FRAaeZSldlbvN7%2FWmrFZFlBAWvX5%2F2JX0ZIJW1U8qtBJAG9mKoH1xGjB6HM0qI%2Fx04GeNSDVXlb0gyrSGKE9B9YOWE%2Bd0HR1RJ%2FaLVzJ0A0ZP1tVyyiPHrdAgMSofcyyyVBz27K1Juzi7m6Us7W4Oop7v2aFlsh1BsBYA6ij%2FrwEEWRrwwvgcJzHLongesdmW3fAk5rM5SdndL4zWlxQflDm381Xk%2BzMI%2BI%2Ftdh0VY%2BatqD1GL9emRxC%2B9MonB%2B5joV%2BTi2uLeHmCKc97FRw%2FZ7qgH0mXl%2FHz31n%2BAw%3D%3D&SigAlg=http%3A%2F%2Fwww.w3.org%2F2000%2F09%2Fxmldsig%23rsa-sha1'
[2014-07-15 18:20:57.324] boot - 1092 DEBUG [http-bio-443-exec-6] --- SigningUtil: Computing signature over input using private key of type RSA and JCA algorithm ID SHA1withRSA
[2014-07-15 18:20:57.350] boot - 1092 DEBUG [http-bio-443-exec-6] --- SigningUtil: Computed signature: 821f8f391e4aab64ce8c79374d5840c052b2a169432d835977057d0a33bd72dc40a8b9594a48ab70c4d58af36eff3ab9eb8a61c2f3766b59071781b984ba3255acf53f56e028442ef2f372a29edbbe8cd791df32588b9043cbc7aa9e7ab15ffbe47337f78ebd5d1a929fd2b3077ed32c364383746455fd24c7b2ce7cc1dd09eda1b2099dd09fc38801cdeeb7262437a04782dad45ac15fd1f053fff925bd77f5e9b7e5a3f1464d4f08a07c0d453d479803aaf75256ea074eff00a8a5575233cf997649abe0687d9a732ea03c32659990b8f00784a8bb38be9240085db96affa030c39fe7173a85f100d28547da5141faa6b062f31ea69deabe61bea78f809561
[2014-07-15 18:20:57.350] boot - 1092 DEBUG [http-bio-443-exec-6] --- HTTPRedirectDeflateEncoder: Generated digital signature value (base64-encoded) gh+POR5Kq2TOjHk3TVhAwFKyoWlDLYNZdwV9CjO9ctxAqLlZSkircMTVivNu/zq564phwvN2a1kHF4G5hLoyVaz1P1bgKEQu8vNyop7bvozXkd8yWIuQQ8vHqp56sV/75HM39469XRqSn9KzB37TLDZDg3RkVf0kx7LOfMHdCe2hsgmd0J/DiAHN7rcmJDegR4La1FrBX9HwU//5Jb139em35aPxRk1PCKB8DUU9R5gDqvdSVuoHTv8AqKVXUjPPmXZJq+BofZpzLqA8MmWZkLjwB4Souzi+kkAIXblq/6Aww5/nFzqF8QDShUfaUUH6prBi8x6mneq+Yb6nj4CVYQ==
[2014-07-15 18:20:57.353] boot - 1092 DEBUG [http-bio-443-exec-6] --- PROTOCOL_MESSAGE:
<?xml version="1.0" encoding="UTF-8"?><saml2p:AuthnRequest xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" AssertionConsumerServiceURL="https://prismasp.cloud.reply.eu:443/MIUR_PRISMA-2.1-WEBUI/saml/SSO/alias/defaultAlias" Destination="https://prisma-idp.cloud.ba.infn.it/simplesaml/saml2/idp/SSOService.php" ForceAuthn="false" ID="a43ajb1gd3h0495313h6jac7b1jf1ef" IsPassive="false" IssueInstant="2014-07-15T16:20:57.319Z" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact" Version="2.0">
   <saml2:Issuer xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">urn:it:miur:prisma</saml2:Issuer>
</saml2p:AuthnRequest>

[2014-07-15 18:20:57.354] boot - 1092 DEBUG [http-bio-443-exec-6] --- BaseMessageEncoder: Successfully encoded message.
[2014-07-15 18:20:57.354] boot - 1092  INFO [http-bio-443-exec-6] --- SAMLDefaultLogger: AuthNRequest;SUCCESS;10.7.4.185

Tomcat服务器。xml

<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <!--Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /-->
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->

    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the BIO implementation that requires the JSSE
         style configuration. When using the APR/native implementation, the
         OpenSSL style configuration is required as described in the APR/native
         documentation -->

        <Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol"
            maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
            clientAuth="false" sslProtocol="TLS"
            keystoreFile="/root/.keystore"
            keystorePass="mystore"
            keyAlias="appalias"
            keyPass="mycert"              />


    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

共有1个答案

陶淳
2023-03-14

在我的环境中运行您的代码时,我必须首先禁用CSRF令牌签入WebSecurityConfig#config(HttpSecurity),因为它阻止了Prisma IDP接受SAML响应。我这样做是使用:

http.csrf().disable();

单点登录开始工作后,响应消息被接受,但是您的demo.components.SAMLUserDetailsServiceImpl拒绝了它,因为如果(userID. compareTo("jdoe@samplemail.com ") ! = 0)在那里指定,则用户ID与您的条件不匹配。(

您引发的SSOUserAccountNotExistsException异常将用户发送回入口点(这可能会导致一个永久循环)。

一旦我消除了if条件,我就能够成功地完成单点登录过程

我相信你上面发布的日志仍然不完整。我必须通过创建文件src/main/resources/logback来启用日志记录。xml,包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="org.springframework.security" level="DEBUG"/>
    <logger name="org.springframework.security.saml" level="DEBUG"/>
    <logger name="org.opensaml" level="DEBUG"/>
    <logger name="PROTOCOL_MESSAGE" level="DEBUG"/>
</configuration>

 类似资料:
  • 因此,我的任务是为客户端的Oracle Hyperion应用程序启用SSO。我使用的方法是基于自定义标头变量的SSO。 平联邦目前作为许多应用程序的SSO身份验证服务器存在,计划是在它(平馈SP)从Okta IDP检索属性/身份验证用户时使用它作为目标应用程序的SP。 我对这个过程相对较新,因为您可能已经猜到了,并且正在寻找有关如何配置的澄清: > SP 从 Pingfed 启动 SSO,并从 O

  • 我是KeyClope的新手,正在尝试将其配置为SalesForce客户端的SAML IDP。IDP启动的SSO流工作正常。我被引导到Salesforce主页正确地进行身份验证。然而,SP启动的SSO给了我一个JSON输出,而不是KeyClope登录页面。 这是SalesForce重定向到的URL(屏蔽IP):http://10.99.xxx.xxx:8080/auth/realms/test?SA

  • 我试图让HoK配置文件与Spring SAML作为SP和SimpleSAMLphp作为IdP一起工作。 SP获取客户端证书,然后向IdP发送以下身份验证请求,无问题: 作为响应,IdP在TLS握手期间请求客户端证书,然后获取他的用户名/密码并成功验证他。它发送以下响应: 看起来一切正常,但是Spring SAML抛出了以下异常: Spring SAML调试日志在此处: 错误为:HoK Subjec

  • 我的要求是,对于销售人员,应该允许用户在使用Okta作为身份提供者的my产品中进行SSO(单点登录)。 然而,问题在于,在这种情况下,我们希望使用salesforce作为身份提供者,使用my product作为服务提供者。 我知道我会通过联合身份通过SAML断言来做到这一点。我正在浏览各种参考资料,并努力找到实现这个案例所需遵循的确切步骤。 我可以举很多例子将Okta中的salesforce添加为

  • 我已经在端口8180上使用以下命令启动了dockerze密钥斗篷: 作为管理员,我创建了两个领域(在同一个keyclock实例中): 租户1 银 在Tenant1中,我定义了一个连接到Angular应用程序(它可以工作)和GITHUB身份提供者(它也可以工作)的客户端(public) 在Silver Realm中,我将客户端“silverBroker”定义为机密...连接到 Angular 应用程

  • 重新启动时,Mosquitto不可靠地转发排队消息(持久化不起作用) 运行蚊子版本:1.4.15 这是最后测试的配置: