【问题标题】:Dynamically configure LDAP server Properties using text file使用文本文件动态配置 LDAP 服务器属性
【发布时间】:2022-01-21 14:51:39
【问题描述】:
我目前正在使用带有 XML 配置的 Spring Security 使用 LDAP。我需要关于如何将 URL、端口、manager-dn 和密码等属性放入外部文件的建议。
<ldap-server id="ldapServer"
url="ldap://xxxxx:3268/dc=xxxxx,dc=com" port="3268"
manager-dn="xxxxx@xxxxx.com" manager-password="xxxxxx" />
我的意思是,我们需要将其放在外部,因为我们的其他团队(实施团队)需要更改这些属性值才能上线,而无需更改 war/binary 文件中的任何内容。谢谢
【问题讨论】:
标签:
spring
spring-security-ldap
【解决方案1】:
完成,感谢this 发帖
步骤:
- 创建属性文件并将其放入服务器
####### LDAP ##############
ldap.urls= ldap://xxxx:3268/dc=xxxxx,dc=com
ldap.manager-dn= xxxx@xxxxx.com
ldap.manager-password= xxxx
- 创建properyplaceholder bean
<beans:bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="location">
<beans:value>file:///opt/xxxx/xxxxx/application.properties</beans:value>
</beans:property>
</beans:bean>
- 从 XML bean 访问属性
<ldap-server id="ldapServer" url="${ldap.urls}" port="3268"
manager-dn="${ldap.manager-dn}"
manager-password="${ldap.manager-password}" />