在Config.groovy内部,我设置了一些环境变量:
def appName = grails.util.Metadata.current.getApplicationName()
def casUrl = "https://login.cas.server/cas"
environments {
development {
grails.logging.jul.usebridge = true
host.address = "12.34.56.78"
host.port = "8080"
}
test {
grails.logging.jul.usebridge = true
host.address = "http://staging.server.somewhere.com/"
host.port = ""
}
production {
grails.logging.jul.usebridge = false
host.address = "http://www.production.com"
host.port = ""
}
}
我正在尝试在同一配置文件(Config.groovy)中使用这些值,如下所示:
grails.plugin.springsecurity.cas.loginUri = '/login'
grails.plugin.springsecurity.cas.serviceUrl = "${host.address}:${host.port}/${appName}/j_spring_cas_security_check"
grails.plugin.springsecurity.cas.serverUrlPrefix = '${casUrl}'
grails.plugin.springsecurity.cas.proxyCallbackUrl = "/secure/receptor"
grails.plugin.springsecurity.logout.afterLogoutUrl = "${casUrl}/logout?url=${host.address}:${host.port}/${appName}/"
然而,唯一得到解决的是appName变量,其他一切都是null。这是可以做到的吗?看起来它在这篇帖子Grails: Spring Security CAS Working in 2.2.3中使用了,但我似乎无法让它们解决。
如果我做的话
def appName = grails.util.Metadata.current.getApplicationName()
def casUrl = "https://login.umt.edu/cas"
host.address = "MyAddress"
environments {
...
configSlurper解析了CAS配置中的host.address,为什么我不能访问环境变量?
答案 0 :(得分:0)
请参阅基本配置下的答案here。
但是,使用点表示法后无法嵌套。换句话说,这不起作用
// Won't work!
foo.bar {
hello = "world"
good = "bye"
}
所以尝试使用这样的嵌套
foo {
bar {
hello = "world"
good = "bye"
}
}
答案 1 :(得分:0)
在每个环境块中移动依赖于host.address和host.port的属性:
environments {
development {
grails.logging.jul.usebridge = true
host.address = "12.34.56.78"
host.port = "8080"
grails.plugin.springsecurity.cas.serviceUrl = "${host.address}:${host.port}/${appName}/j_spring_cas_security_check"
grails.plugin.springsecurity.logout.afterLogoutUrl = "${casUrl}/logout?url=${host.address}:${host.port}/${appName}/"
}
test {
grails.logging.jul.usebridge = true
host.address = "http://staging.server.somewhere.com/"
host.port = ""
grails.plugin.springsecurity.cas.serviceUrl = "${host.address}:${host.port}/${appName}/j_spring_cas_security_check"
grails.plugin.springsecurity.logout.afterLogoutUrl = "${casUrl}/logout?url=${host.address}:${host.port}/${appName}/"
}
production {
grails.logging.jul.usebridge = false
host.address = "http://www.production.com"
host.port = ""
grails.plugin.springsecurity.cas.serviceUrl = "${host.address}:${host.port}/${appName}/j_spring_cas_security_check"
grails.plugin.springsecurity.logout.afterLogoutUrl = "${casUrl}/logout?url=${host.address}:${host.port}/${appName}/"
}
}
您可以完全删除host.address和host.port变量:
environments {
development {
grails.logging.jul.usebridge = true
grails.plugin.springsecurity.cas.serviceUrl = "http://12.34.56.78:8080/${appName}/j_spring_cas_security_check"
grails.plugin.springsecurity.logout.afterLogoutUrl = "${casUrl}/logout?url=http://12.34.56.78:8080/${appName}/"
}
test {
grails.logging.jul.usebridge = true
grails.plugin.springsecurity.cas.serviceUrl = "http://staging.server.somewhere.com/${appName}/j_spring_cas_security_check"
grails.plugin.springsecurity.logout.afterLogoutUrl = "${casUrl}/logout?url=http://staging.server.somewhere.com/${appName}/"
}
production {
grails.logging.jul.usebridge = false
grails.plugin.springsecurity.cas.serviceUrl = "http://www.production.com/${appName}/j_spring_cas_security_check"
grails.plugin.springsecurity.logout.afterLogoutUrl = "${casUrl}/logout?url=http://www.production.com/${appName}/"
}
}