2016-12-24 3 views
8

これについていくつかの調査を行いましたが、解決策を見つけることができませんでした。Webソケットでトリガされたメソッド呼び出しのアノテーションベースのセキュリティ制限が機能しません

私はこの

@Stateless 
class ConfigBean { 
    @RequiresRole("administrator") 
    public void reloadConfiguration(){ 
    ...... 
    } 
} 

ようなクラスを持っていると私は以下のようにJAX-RS(ジャージー)サービスがあります。

@Path("config") 
class ConfigService{ 

    @EJB 
    ConfigBean config; 

    @Get 
    @Path("reload") 
    public void reload(){ 
    config.reloadConfiguration(); 
    } 
} 

これはAPI /Test/config/relaod(管理者ユーザとのすなわち作業のみ)を呼び出すことで正常に動作します。

しかし、以下のコードが期待通りに動作しない(すなわち通常のユーザーはリロードの設定方法をトリガすることができます)、

@ServerEndpoint("/socket") 
public class EchoServer { 
/** 
* @OnOpen allows us to intercept the creation of a new session. 
* The session class allows us to send data to the user. 
* In the method onOpen, we'll let the user know that the handshake was 
* successful. 
*/ 

@EJB 
ConfigBean config; 

@OnOpen 
public void onOpen(Session session){ 
    System.out.println(session.getId() + " has opened a connection"); 
    try { 
     session.getBasicRemote().sendText("Connection Established"); 
    } catch (IOException ex) { 
     ex.printStackTrace(); 
    } 
} 

/** 
* When a user sends a message to the server, this method will intercept the message 
* and allow us to react to it. For now the message is read as a String. 
*/ 
@OnMessage 
public void onMessage(String message, Session session){ 
    System.out.println("Message from " + session.getId() + ": " + message); 
    try { 
     if(message.equalsIgnoreCase("reloadConfig")){ 
      config.reloadConfiguration(); 
     } 
    } catch (IOException ex) { 
     ex.printStackTrace(); 
    } 
} 

/** 
* The user closes the connection. 
* 
* Note: you can't send messages to the client from this method 
*/ 
@OnClose 
public void onClose(Session session){ 
    System.out.println("Session " +session.getId()+" has ended"); 
    } 
} 

答えて

0

史郎JAX-RSの統合のみJAX-RSのエンドポイントをインターセプトします。

アノテーションへのより一般的なアプローチとして、Guice、Spring、またはAspectJの統合を使用できます。あなたがCDIを使用している場合

、あなたはそれそれだけで最初のパスで、史郎注釈インターセプタのためthis branchを見てみることができますが、それは

+0

私の質問には注釈が正常に動作しているで働いていたとき、メソッド呼び出しHTTP要求によってトリガされますが、Webソケットメッセージによってトリガされたときには動作しません。 –

関連する問題