gpt4 book ai didi

服务中的 Grails jms 和 Atmosphere 插件 null springSecurityService 注入(inject)

转载 作者:行者123 更新时间:2023-12-02 14:12:54 24 4
gpt4 key购买 nike

你好!

我正在使用 grails jms 和 Atmosphere 插件...

当尝试将 springSecurityService 注入(inject)
Jms-Atmosphere Service 类,principal/currentUser 为空,同时有对该对象的引用(springSecurityService 不为空)

//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 用作服务时,我遇到了同样的问题!在这种情况下, Atmosphere 服务也必须暴露于 jms 事件!
请给我一些想法来解决这个问题......解决方法也许......谢谢

最佳答案

我猜您的特定通话中没有设置 cookie。你在使用网络套接字吗?确保您拥有 Atmosphere 1.0.0 并启用了 session 支持!然后,您仍然需要从原始请求中获取身份验证:

if(resource.writer instanceof WebsocketResponseWriter) {
AtmosphereResource resource = resource.atmosphereResource
SecurityContext sessionContext = resource.session
.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY)
}

然后,您需要为当前 session 上下文提供来自您找到的 session 上下文的身份验证。确保在处理请求后重置身份验证。

这有帮助吗?

关于服务中的 Grails jms 和 Atmosphere 插件 null springSecurityService 注入(inject),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12144721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com