2

こんにちは!

私はgrails jmsと大気プラグインを使用しています...

springSecurityService を Jms-Atmosphere Service クラスに注入しようとすると、このオブジェクトへの参照がある間、プリンシパル/currentUser が null になります (springSecurityService は null ではありません)。

//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 Handler をサービスとして使用すると、同じ問題が発生します。この場合、雰囲気サービスも JMS イベントに公開する必要があります。これに対処するためのアイデアを教えてください...おそらく回避策...ありがとう

4

1 に答える 1

0

特定の呼び出しに Cookie が設定されていないと思います。ウェブソケットを使用していますか?Atmosphere 1.0.0 がインストールされており、セッション サポートが有効になっていることを確認してください。その後、元のリクエストから認証を取得する必要があります。

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

次に、現在のセッション コンテキストに、見つけたセッション コンテキストからの認証を提供する必要があります。リクエストが処理されたら、必ず認証をリセットしてください。

これは役に立ちますか?

于 2012-09-14T08:03:16.780 に答える