resources.groovy中的Grails springSecurityService为当前用户提供空值
我使用的是Grails2.4.3和Grails app/conf/spring/resources.groovyresources.groovy中的Grails springSecurityService为当前用户提供空值,grails,spring-security,spring-bean,Grails,Spring Security,Spring Bean,我使用的是Grails2.4.3和Grails app/conf/spring/resources.groovy beans = { someBean(com.domain.SomeBeanImpl) { springSecurityService = ref('springSecurityService') } } 但是在SomeBeanImpl类中 class SomeBeanImpl { def springSecurityService
beans = {
someBean(com.domain.SomeBeanImpl) {
springSecurityService = ref('springSecurityService')
}
}
但是在SomeBeanImpl
类中
class SomeBeanImpl {
def springSecurityService
def method() {
def user = springSecurityService.currentUser //null, even after successful log-in
}
}
在我的控制器和服务中,我通常可以检索springSecurityService.currentUser
为什么自定义bean上的null?如何正确地检索它
编辑:
我使用了来自
在这个类中使用springSecurityService bean
/**
* Spring Security Tenant Resolver
* Extracts the tenantId
* @see http://multi-tenant.github.com/grails-multi-tenant-single-db/
*/
@Log4j
class SpringSecurityTenantResolver implements TenantResolver {
def springSecurityService
Integer resolve(HttpServletRequest request) throws TenantResolveException {
def user = springSecurityService.currentUser
/*
if (!user) {
throw new TenantResolveException('Tenant could not be resolved using SpringSecurity')
}
*/
log.debug "${request.requestURL} : ${user?.username} : ${user?.tenantId}"
return user?.tenantId
}
}
尝试将
bean.autowire='byName'
添加到bean定义中这个bean是如何使用的?它是否在web请求期间被调用?如果没有,就不会有经过身份验证的用户。bean被正确注入,但它从方法调用返回null。autowire与此无关。