java - Spring SAML 无法从属性文件中读取属性
问题描述
所以这个难倒我。多年来我一直在使用属性文件,但我从未见过这种情况。
我正在使用带有 SAML 身份验证的 Spring MVC。我的上下文 xml 中有这个:
<context:property-placeholder location="file:/opt/saml.properties" />
<bean id="keyManager" class="org.springframework.security.saml.key.JKSKeyManager">
<constructor-arg value="file:/opt/mySamlKeystore.jks"/>
<constructor-arg type="java.lang.String" value="${keystore.password}"/>
<constructor-arg>
<map>
<entry key="${privateKey.alias}" value="${key.password}"/>
</map>
</constructor-arg>
<constructor-arg type="java.lang.String" value="${privateKey.alias}"/>
</bean>
我收到此错误:
java.security.UnrecoverableKeyException: Cannot recover key
我做了一些 SO 研究,他们基本上都说我的密码错误,我确定我没有。因此,为了测试它是否读取了正确的文件,我去替换所有属性 %{} 并对它们进行硬编码。然后一切正常。
当我注意到该文件中的一些其他属性正在工作时,我试图弄清楚这一点!事实上,我什至可以这样做:
<bean id="keyManager" class="org.springframework.security.saml.key.JKSKeyManager">
<constructor-arg value="file:/opt/myKeystore.jks"/>
<constructor-arg type="java.lang.String" value="${keystore.password}"/>
<constructor-arg>
<map>
<entry key="${privateKey.alias}" value="password"/>
</map>
</constructor-arg>
<constructor-arg type="java.lang.String" value="${privateKey.alias}"/>
</bean>
所以 spring 从属性文件中获取 ${keystore.password} 和 ${privateKey.alias} (以及其他需要的,如 entityID、metadataProvider 等),但不是 ${key.password} !!!
这是 saml.properties
#keystore stuff
keystore.password=password
key.password=password
privateKey.alias=mysaml
#SP stuff (aka, my side of things)
entity.id=mycompany:me:me:me1
entity.base.url=https://mycompany.com
#IDP stuff (aka, the SAML server)
metadata.provider=https://saml.mycompany.com/FederationMetadata/2007-06/FederationMetadata.xml
当我硬编码密钥密码时,这一切都有效,但当我使用 ${key.password} 属性时,这一切都有效。这里发生了什么?
解决方案
文件后还有两个斜杠
例如
<bean id="keyManager" class="org.springframework.security.saml.key.JKSKeyManager">
<constructor-arg value="file:///opt/myKeystore.jks"/>
<constructor-arg type="java.lang.String" value="${keystore.password}"/>
<constructor-arg>
<map>
<entry key="${privateKey.alias}" value="password"/>
</map>
</constructor-arg>
<constructor-arg type="java.lang.String" value="${privateKey.alias}"/>
</bean>
推荐阅读
- ios - Mapbox iOS 在顶部获得注释?
- lisp - Common lisp 中的插入排序
- c++ - boost::asio::async_read_until 不要截断输入消息
- regex - 正则表达式:如果接下来的 5 个字符包含 3 次出现而不是字符 k,则匹配一个字符串
- python - 使用 pandas(Python)打开 .dat 文件后不需要的合并列
- hexo - Hexo g -d 不起作用,无法检测到版本
- postgresql - 指向 Postgres 的 LAMBDA current_timestamp
- python - 如何使用solve_ivp用谱法求解偏微分方程?
- kubectl - 如何在一个 Google Cloud 帐户中管理多个 GKE 项目
- node.js - Chrome net::ERR_HTTP2_PROTOCOL_ERROR 200 重新连接后