我使用Grails 2.4.3和Grails中,應用程序/ conf目錄/春/ resources.groovy,Grails的springSecurityService在resources.groovy給空當前用戶
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
。
爲什麼在定製豆空?如何正確檢索它?
編輯:
我使用http://multi-tenant.github.io/grails-multi-tenant-single-db/docs/v0.8.3/guide/4.%20Scripts.html#4.2.%20mt-spring-securitygrails mt-spring-security
,
,並在這個類中使用springSecurityService豆,
/**
* 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?它是否在網絡請求期間被調用?如果沒有,那麼就不會有一個通過身份驗證的用戶。 –