Grails jms和atmosphere插件null springSecurityService在服务中的注入 你好
我正在使用GrailsJMS和atmosphere插件 尝试将springSecurityService注入到 Jms大气服务类,当存在对此对象的引用时,主体/currentUser为null springSecurityService不为nullGrails jms和atmosphere插件null springSecurityService在服务中的注入 你好,grails,dependency-injection,spring-security,jms,atmosphere,Grails,Dependency Injection,Spring Security,Jms,Atmosphere,我正在使用GrailsJMS和atmosphere插件 尝试将springSecurityService注入到 Jms大气服务类,当存在对此对象的引用时,主体/currentUser为null springSecurityService不为null //Grails Service class class UserMessageService { static transactional = true static exposes = ['jms']
//Grails Service class
class UserMessageService {
static transactional = true
static exposes = ['jms']
static destination = "queue.usermessage"
def jmsService
def springSecurityService
public def onMessage(msg) {
sleep(2000) // slow it down
log.info "sending jms mssage"
//User is null!!
User user = springSecurityService.currentUser
jmsService.send(topic:'msgevent', msg)
return null
}
}
所以我想知道。。。
这是一个插件问题,还是作为jms插件发布的事件侦听器来侦听事件的问题?
当使用Atmosphere插件将Atmosphere Hander用作服务时,我也有同样的问题!在这种情况下,大气服务也必须暴露于jms事件!
请给我一些想法来处理这个。。。解决办法也许。。。谢谢我想您的电话中没有设置cookie。你在使用websocket吗?确保您已经启用了Atmosphere 1.0.0并启用了会话支持!然后,您仍然需要从原始请求获取身份验证:
if(resource.writer instanceof WebsocketResponseWriter) {
AtmosphereResource resource = resource.atmosphereResource
SecurityContext sessionContext = resource.session
.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY)
}
然后,您需要提供当前会话上下文,并从您找到的会话上下文中进行身份验证。确保在处理请求后重置身份验证
这有帮助吗?我想在您的特定通话中没有设置cookie。你在使用websocket吗?确保您已经启用了Atmosphere 1.0.0并启用了会话支持!然后,您仍然需要从原始请求获取身份验证:
if(resource.writer instanceof WebsocketResponseWriter) {
AtmosphereResource resource = resource.atmosphereResource
SecurityContext sessionContext = resource.session
.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY)
}
然后,您需要提供当前会话上下文,并从您找到的会话上下文中进行身份验证。确保在处理请求后重置身份验证
这有用吗