【发布时间】:2016-06-29 13:22:39
【问题描述】:
我有一个外部 YML 文件,其中包含一些 grails 配置。在这个文件中,添加的配置之一是用于 grails spring security ldap 插件。我的配置如下:
---
grails:
plugin:
springsecurity:
ldap:
context:
managerDn: 'uid=admin,ou=system'
managerPassword: 'secret'
server: 'ldap://localhost:10389'
authorities:
groupSearchBase: 'ou=Groups,dc=c3cen,dc=com'
retreiveGroupRoles: true
retreiveDatabaseRoles: false
groupSearchFilter: 'member={0}'
search:
base: 'ou=Users,dc=c3cen,dc=com'
password:
algoritham: 'SHA-256'
interceptUrlMap: [
{pattern: '/', access: ['permitAll']},
{pattern: '/error', access: ['permitAll']},
{pattern: '/index', access: ['permitAll']},
{pattern: '/index.gsp', access: ['permitAll']},
{pattern: '/shutdown', access: ['permitAll']},
{pattern: '/assets/**', access: ['permitAll']},
{pattern: '/**/js/**', access: ['permitAll']},
{pattern: '/**/css/**', access: ['permitAll']},
{pattern: '/**/images/**', access: ['permitAll']},
{pattern: '/**/favicon.ico', access: ['permitAll']},
{pattern: '/login/**', access: ['permitAll']},
{pattern: '/logout/**', access: ['permitAll']}
]
---
我在常规(由 grails quick config 提供)应用程序 yml 文件中也有一些属性。该文件仅包含:
grails:
plugin:
springsecurity:
securityConfigType: 'InterceptUrlMap'
providerNames: ['ldapAuthProvider', 'anonymousAuthenticationProvider']
我通过覆盖 Application.groovy 类中的 setEnvironment 方法来加载 grails 中的外部配置。它看起来如下:
@Override
void setEnvironment(Environment environment) {
try {
String configPath = System.getenv("local.config.location")
def ymlConfig = new File(configPath)
Resource resourceConfig = new FileSystemResource(ymlConfig)
YamlPropertiesFactoryBean ypfb = new YamlPropertiesFactoryBean()
ypfb.setResources(resourceConfig)
ypfb.afterPropertiesSet()
Properties properties = ypfb.getObject()
environment.propertySources.addFirst(new PropertiesPropertySource("local.config.location", properties))
} catch (Exception e) {
log.error("unable to load the external configuration file", e)
}
}
当我在 grails 中发出 run-app 命令并部署到我的嵌入式 tocat 时,一切都按预期工作。当我手动部署到本地 tomcat 时,我在 Firefox 中收到“页面未正确重定向”错误。
注意:我已通过日志语句确认两个 tomcat 服务器正在读取外部文件。奇怪的是属性被注入,但它们被默认提供的字符串覆盖。例如: dc=example 显示在 search.base 中,但在我上面的代码中,您可以清楚地看到它在 'ou=Users,dc=c3cen,dc=com' 中。请注意,这两者都存在,但我猜默认会覆盖自定义属性。
我需要在本地(非嵌入式 grails)Tomcat 服务器上进行更改以允许外部属性工作吗?我尝试更改 application.yml(external one) 的位置,但无济于事。
【问题讨论】:
标签: tomcat grails spring-security spring-boot