OpenSAML / Spring 安全设置,因此在 Tomcat 上重新部署有效

     2023-02-27     113

关键词:

【中文标题】OpenSAML / Spring 安全设置,因此在 Tomcat 上重新部署有效【英文标题】:OpenSAML / Spring security setup so redeploy on Tomcat works 【发布时间】:2015-04-10 12:13:21 【问题描述】:

我们正在使用 Tomcat 6.0.35 在 OpenJDK IcedTea6 1.13.6 上运行 web 应用程序。对于 SSO,我们使用基于 OpenSAML 2.6.1 的 Spring 安全 SAML 扩展。

重新部署我们的应用程序(不重新启动 Tomcat)时,我得到一个 NoClassDefFoundError: org/bouncycastle/crypto/paddings/ISO10126d2Padding 很好地描述了here。从 Eclipse MAT 分析中,我收集到 BouncyCastleProvider 或 JCERSAPublicKey 正在阻止 WebappClassLoader 被 gc'ed。

如何配置 SAML 以便正确销毁所有(充气城堡)实例?我很难相信 SAML 的设计使得部署要求 Tomcat 重新启动。

我目前的配置: ...

<bean id="samlLogger" class="org.springframework.security.saml.log.SAMLDefaultLogger">
    <property name="logErrors" value="true"/>
    <property name="logMessages" value="true"/>
</bean>

<bean id="keyManager" class="org.springframework.security.saml.key.JKSKeyManager">
    <constructor-arg value="classpath:security/samlKeystore.jks"/>
    <constructor-arg type="java.lang.String" value="mypassword"/>
    <constructor-arg>
        <map>
            <entry key="tenzingfaces" value="keyphrase"/>
        </map>
    </constructor-arg>
    <constructor-arg type="java.lang.String" value="tenzingfaces"/>
</bean>

<bean id="samlEntryPoint" class="org.springframework.security.saml.SAMLEntryPoint">
    <property name="defaultProfileOptions">
        <bean class="org.springframework.security.saml.websso.WebSSOProfileOptions">
            <property name="binding" value="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"/>
            <property name="includeScoping" value="false"/>
        </bean>
    </property>
</bean>

<bean id="metadataDisplayFilter" class="org.springframework.security.saml.metadata.MetadataDisplayFilter"/>

<bean id="samlAuthenticationProvider" class="org.springframework.security.saml.SAMLAuthenticationProvider">
    <property name="userDetails" ref="samlUserDetailService" />
    <property name="forcePrincipalAsString" value="false" />
</bean>

<bean id="samlUserDetailService" class="ch.umbrella.springframework.security.SamlUserDetailsServiceImpl" />

<bean id="contextProvider" class="org.springframework.security.saml.context.SAMLContextProviderImpl"/>

<bean id="samlSuccessRedirectHandler" class="ch.umbrella.springframework.security.SsoAuthenticationSuccessHandler" >
    <property name="defaultTargetUrl" value="/main.html" />
    <property name="alwaysUseDefaultTargetUrl" value="false" />
    <property name="credentialsExpiredUrl" value="/credentialsexpired.html" />
</bean>
<bean id="samlWebSSOProcessingFilter" class="org.springframework.security.saml.SAMLProcessingFilter">
    <property name="authenticationManager" ref="authenticationManager"/>
    <property name="authenticationSuccessHandler" ref="samlSuccessRedirectHandler"/>
</bean>

<bean id="processor" class="org.springframework.security.saml.processor.SAMLProcessorImpl">
    <constructor-arg>
        <list>
            <ref bean="redirectBinding"/>
            <ref bean="postBinding"/>
        </list>
    </constructor-arg>
</bean>

<bean id="webSSOprofileConsumer" class="org.springframework.security.saml.websso.WebSSOProfileConsumerImpl"/>
<bean id="hokWebSSOprofileConsumer" class="org.springframework.security.saml.websso.WebSSOProfileConsumerHoKImpl"/>
<bean id="webSSOprofile" class="org.springframework.security.saml.websso.WebSSOProfileImpl"/>
<bean id="hokWebSSOProfile" class="org.springframework.security.saml.websso.WebSSOProfileConsumerHoKImpl"/>

<bean id="postBinding" class="org.springframework.security.saml.processor.HTTPPostBinding">
    <constructor-arg ref="parserPool"/>
    <constructor-arg ref="velocityEngine"/>
</bean>

<bean id="velocityEngine" class="org.springframework.security.saml.util.VelocityFactory" factory-method="getEngine"/>

<bean id="redirectBinding" class="org.springframework.security.saml.processor.HTTPRedirectDeflateBinding">
    <constructor-arg ref="parserPool"/>
</bean>

<bean class="org.springframework.security.saml.SAMLBootstrap"/>

<bean id="parserPool" class="org.opensaml.xml.parse.StaticBasicParserPool" scope="singleton" init-method="initialize"/>
<bean id="parserPoolHolder" class="org.springframework.security.saml.parser.ParserPoolHolder" scope="singleton"/>
...    

并且,在特定于暂存的文件中:

<bean id="metadata" class="org.springframework.security.saml.metadata.CachingMetadataManager">
    <constructor-arg>
        <list>
            <bean class="org.springframework.security.saml.metadata.ExtendedMetadataDelegate" destroy-method="destroy">
                <constructor-arg>
                    <bean class="org.opensaml.saml2.metadata.provider.ResourceBackedMetadataProvider" destroy-method="destroy">
                        <constructor-arg ref="timer1" />
                        <constructor-arg>
                            <bean class="org.opensaml.util.resource.ClasspathResource">
                                <constructor-arg value="/security/idp.xml"/>
                            </bean>
                        </constructor-arg>
                        <property name="parserPool" ref="parserPool"/>
                    </bean>
                </constructor-arg>
                <constructor-arg>
                    <bean class="org.springframework.security.saml.metadata.ExtendedMetadata">
                    </bean>
                </constructor-arg>
            </bean>
            <bean class="org.springframework.security.saml.metadata.ExtendedMetadataDelegate" destroy-method="destroy">
                <constructor-arg>
                    <bean class="org.opensaml.saml2.metadata.provider.ResourceBackedMetadataProvider" destroy-method="destroy">
                        <constructor-arg ref="timer2" />
                        <constructor-arg>
                            <bean class="org.opensaml.util.resource.ClasspathResource">
                                <constructor-arg value="/security/localhost_sp.xml"/>
                            </bean>
                        </constructor-arg>
                        <property name="parserPool" ref="parserPool"/>
                    </bean>
                </constructor-arg>
                <constructor-arg>
                    <bean class="org.springframework.security.saml.metadata.ExtendedMetadata">
                        <property name="local" value="true"/>
                        <property name="securityProfile" value="metaiop"/>
                        <property name="sslSecurityProfile" value="pkix"/>
                        <property name="signMetadata" value="true"/>
                        <property name="signingKey" value="tenzingfaces"/>
                        <property name="encryptionKey" value="tenzingfaces"/>
                        <property name="requireArtifactResolveSigned" value="false" />
                        <property name="requireLogoutRequestSigned" value="false" />
                        <property name="requireLogoutResponseSigned" value="false" />
                        <property name="idpDiscoveryEnabled" value="false" />
                    </bean>
                </constructor-arg>
            </bean>
        </list>
    </constructor-arg>
    <property name="hostedSPName" value="https://hurricane.umbrellanet.ch/uf-test/saml/metadata" />
</bean>

谢谢 西蒙

【问题讨论】:

【参考方案1】:

如果您在战争中捆绑 bouncycastle 罐子,请不要这样做。而是将这些罐子放在 tomcat/lib 中。希望这会解决它。

【讨论】:

opensaml

一、背景知识:     SAML即安全断言标记语言,英文全称是SecurityAssertionMarkupLanguage。它是一个基于XML的标准,用于在不同的安全域(securitydomain)之间交换认证和授权数据。在SAML标准定义了身份提供者(identityprovider... 查看详情

OpenSaml3 文档

】OpenSaml3文档【英文标题】:OpenSaml3Documentation【发布时间】:2016-07-0623:21:27【问题描述】:有谁知道任何地方是否有任何OpenSaml3的文档?付费还是其他?我知道曾经有一本15美元的书可用,但我相信它只涵盖OpenSaml2。我知道这可... 查看详情

创建 QName 异常时,Opensaml unmarshallMessage 给出的 opensaml 本地部分不能为“null”

】创建QName异常时,OpensamlunmarshallMessage给出的opensaml本地部分不能为“null”【英文标题】:OpensamlunmarshallMessagegivingopensamllocalpartcannotbe"null"whencreatingaQNameException【发布时间】:2021-07-3017:49:54【问题描述】:我正在使用Spring... 查看详情

Spring 安全 @PreAuthorize NullPointerException。为啥?

】Spring安全@PreAuthorizeNullPointerException。为啥?【英文标题】:Springsecurity@PreAuthorizeNullPointerException.Why?Spring安全@PreAuthorizeNullPointerException。为什么?【发布时间】:2020-07-0606:40:45【问题描述】:我正在尝试在控制器中检查用户的... 查看详情

Spring:如果 url 的安全性设置为无,则检查代码

】Spring:如果url的安全性设置为无,则检查代码【英文标题】:Spring:Checkincodeifurlhassecuritysettonone【发布时间】:2016-12-2503:01:15【问题描述】:可以检查SpringInterceptorpreHandle()方法是否请求的URL受SpringSecurity保护(已设置security="... 查看详情

Spring-SAML 的 SSL 配置问题

...部署WAR文件时出现以下异常:Initializationofmetadataproviderorg.opensaml.saml2.metad 查看详情

Spring Security Cloud:通过 ZUUL 网关安全设置的 UI 服务

】SpringSecurityCloud:通过ZUUL网关安全设置的UI服务【英文标题】:SpringSecurityCloud:UIservicethroughaZUULgatewaysecuritysetup【发布时间】:2017-11-2117:46:29【问题描述】:我在UI服务中正确设置身份验证和授权时遇到问题。我目前有以下设置... 查看详情

org.opensaml.common.SAMLRuntimeException:无法获取 SP 签名密钥

】org.opensaml.common.SAMLRuntimeException:无法获取SP签名密钥【英文标题】:org.opensaml.common.SAMLRuntimeException:Can\'tobtainSPsigningkey【发布时间】:2018-07-0915:34:15【问题描述】:无法通过领域发现阶段。虽然示例代码适用于IDPSSO圈。使用我... 查看详情

如何使用 opensaml v3?几乎没有文档,并且 v2 已停产

】如何使用opensamlv3?几乎没有文档,并且v2已停产【英文标题】:Howtouseopensamlv3?Thereislittletonodocumentationandv2isEOL【发布时间】:2017-03-2608:01:27【问题描述】:是否有使用OpenSAML库v3的端到端示例?我找不到任何文档,根据https://wiki... 查看详情

spring中的bean是线程安全的吗?

结论:不是线程安全的Spring容器中的Bean是否线程安全,容器本身并没有提供Bean的线程安全策略,因此可以说Spring容器中的Bean本身不具备线程安全的特性,但是具体还是要结合具体scope的Bean去研究。Spring的bean作用域(scope)类型... 查看详情

Spring安全注销处理

】Spring安全注销处理【英文标题】:Springsecuritylogouthandling【发布时间】:2015-06-1410:37:51【问题描述】:根据SpringSecurity4.0.0文档:4.2.4注销处理logout元素通过导航到特定的网址。默认注销URL为/logout,但您可以设置它使用logout-url属... 查看详情

samlencryptedassertion解密失败(代码片段)

...SP。当我尝试解密EncryptedAssertion时,我收到以下错误。org.opensaml.xml.encryption.DecryptionException:FailedtodecryptEncryptedDataatorg.opensaml.xml.encryption.Decrypter.decryptDataToDOM(Decrypter.java:546)atorg.opensaml.xml.encryption.Decrypter.decryptDataToList(Decrypter.java:453)... 查看详情

即使对于没有安全设置的端点,也总是调用 Spring Security 过滤器[重复]

】即使对于没有安全设置的端点,也总是调用SpringSecurity过滤器[重复]【英文标题】:SpringSecurityfilteralwaysbeinginvokedevenforendpointswithoutsecurityset[duplicate]【发布时间】:2018-08-0218:46:20【问题描述】:在添加一些自定义过滤器时,我在... 查看详情

使用 Spring 的线程安全、无状态设计

】使用Spring的线程安全、无状态设计【英文标题】:threadsafe,statelessdesignusingSpring【发布时间】:2012-06-2617:48:54【问题描述】:我假设如果实例变量由SpringIOC管理,并且是单例,那么设计可以称为无状态和线程安全。因此,这种... 查看详情

使用活动目录的 Spring 安全认证失败

】使用活动目录的Spring安全认证失败【英文标题】:Springsecurityauthenticationusingactivedirectoryfailed【发布时间】:2015-11-1622:51:42【问题描述】:我一直在我们公司从事一个SpringWeb应用程序项目。它曾经使用数据库对用户进行身份验证... 查看详情

spring框架中的bean是线程安全的吗?如果线程不安全,要如何处理?

Spring容器本身没有提供Bean的线程安全策略,因此,也可以说Spring容器中的bean不是线程安全的。​如何处理线程安全问题,分情况讨论:​Spring的作用域(scope):singleton:单例,默认作用域。prototype:原型,每次创建一个新对象。requ... 查看详情

org.opensaml.saml2.metadata.provider.FilterException:元数据条目的签名信任建立失败

】org.opensaml.saml2.metadata.provider.FilterException:元数据条目的签名信任建立失败【英文标题】:org.opensaml.saml2.metadata.provider.FilterException:Signaturetrustestablishmentfailedformetadataentry【发布时间】:2014-12-0117:25:53【问题描述】:在securityCo 查看详情

使用 OpenSAML 在 Java 中使用 SAML 2.0 解密加密断言

】使用OpenSAML在Java中使用SAML2.0解密加密断言【英文标题】:DecryptingencryptedassertionusingSAML2.0injavausingOpenSAML【发布时间】:2012-03-1410:03:07【问题描述】:我在尝试使用SAML2.0解密加密断言时遇到问题。我使用的库是OpenSAMLJava库2.5.2。... 查看详情