【问题标题】:spring security can't find metadata file on classpathspring security 在类路径中找不到元数据文件
【发布时间】:2015-01-24 02:23:59
【问题描述】:

我终于让 SAML SSO 在我的应用程序上运行,该应用程序用作 SP。它正在使用生成的元数据,但我想为生产添加预定义的元数据。

我正在尝试配置我的 ExtendedMetadataDelegate bean 以查看包含我的 SP 元数据的 xml 文件,但我不知道将文件放在哪里以便 spring 能够看到它。

spring 文档说:“将元数据文件存储为项目类路径的一部分,例如在 WEB-INF/classes/metadata/localhost_sp.xml 中。”我试着把它放在那个确切的位置,它找不到它。我尝试将它放在与我的密钥库相同的位置,它位于 WEB-INF 下。它似乎能够很好地找到密钥库,但也找不到那里的元数据。

有趣的是,当我使用如下配置的 FilesystemMetadataProvider 时,我的 windows 系统可以找到该文件,但我的 unix 服务器和 mac 上的同事不能。当应用程序在基于 unix 的系统上启动时,这是错误消息:org.opensaml.saml2.metadata.provider.MetadataProviderException: Metadata file '/WEB-INF/blah/filename.xml' 不存在 但应用程序继续运行良好,SSO 甚至可以正常工作。

/WEB-INF/blah/filename.xml

当我使用如下配置的 ResourceBackedMetadataProvider 时,我的系统甚至无法编译,因为它找不到文件。错误是:嵌套异常是 org.opensaml.util.resource.ResourceException:Classpath 资源不存在:filename.xml

我假设我需要更改类路径上的某些内容,但我不知道是更改构建类路径还是运行类路径。我尝试将 WEB-INF 添加到运行类路径中,但这似乎没有帮助。

在此先感谢您提供任何帮助。

【问题讨论】:

  • 您的配置示例没有成功,您可以将它们添加到您的问题中吗?

标签: spring spring-security saml


【解决方案1】:

文档确实声明:Store the metadata file as part of your project classpath, e.g. in WEB-INF/classes/metadata/localhost_sp.xml.

但是,像您一样,我在这样做时会遇到类路径错误。当我将其放入时,我发现该应用程序始终如一地选择它:src/main/resources/metadata/localhost_sp.xml

如果您使用 WEB-INF/classes/metadata/...

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.opensaml.util.resource.ClasspathResource#537c9fb7' defined in ServletContext resource [/WEB-INF/sec
urityContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.opensaml.util.resource.ClasspathResource]
: Constructor threw exception; nested exception is org.opensaml.util.resource.ResourceException: Classpath resource does not exist: /metadata/localhost_sp.xml

作为参考,这里是 WEB-INF/securityContext.xml 的相关部分,它正在加载此元数据 sp。

<bean class="org.springframework.security.saml.metadata.ExtendedMetadataDelegate">
        <constructor-arg>
            <bean class="org.opensaml.saml2.metadata.provider.ResourceBackedMetadataProvider">
                <constructor-arg>
                    <bean class="java.util.Timer"/>
                </constructor-arg>
                <constructor-arg>
                    <bean class="org.opensaml.util.resource.ClasspathResource">
                        <constructor-arg value="/metadata/localhost_sp.xml"/>
                    </bean>
                </constructor-arg>
                <property name="parserPool" ref="parserPool"/>
            </bean>
        </constructor-arg>

总的来说,我发现 Spring Security SAML 难以使用/集成/理解。

【讨论】:

  • 不是我能解决这个问题,但请考虑到有 IDP 元数据和 SP 元数据。如您所料,...sp.xml 用于 SP,idp.xml 用于 IDP。 SecurityContext 文件中 ID 为“元数据”的 bean 用于 IDP 而不是 SP。请发布您的完整 SecurityContext XML 文件。
【解决方案2】:

它们的键值是'/':

<bean class="org.opensaml.util.resource.ClasspathResource">
                        <constructor-arg value="/metadata/localhost_sp.xml"/>
                    </bean>

【讨论】:

    猜你喜欢
    • 2012-11-01
    • 2019-03-09
    • 2021-12-14
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    相关资源
    最近更新 更多