Java 基于注释的安全限制不适用于web套接字触发的方法调用

Java 基于注释的安全限制不适用于web套接字触发的方法调用,java,security,websocket,annotations,shiro,Java,Security,Websocket,Annotations,Shiro,我对此做了一些研究,但没有找到解决办法 我有一节这样的课 @Stateless class ConfigBean { @RequiresRole("administrator") public void reloadConfiguration(){ ...... } } 我有一个JAX-RS(jersey)服务,如下所示 @Path("config") class ConfigService{ @EJB ConfigBean config; @Get

我对此做了一些研究,但没有找到解决办法

我有一节这样的课

@Stateless
class ConfigBean {
  @RequiresRole("administrator")
  public void reloadConfiguration(){
     ......
  }
}
我有一个JAX-RS(jersey)服务,如下所示

@Path("config")
class ConfigService{

  @EJB
  ConfigBean config;

  @Get
  @Path("reload")
  public void reload(){ 
     config.reloadConfiguration();
  }
}
这将在调用API
/Test/config/relad
时正常工作(即仅与管理员用户一起工作)

但是下面的代码没有按预期工作(即普通用户可以触发重新加载配置方法)


Shiro JAX-RS集成只拦截JAX-RS端点

对于更通用的注释方法,可以使用Guice、Spring或AspectJ集成


如果您使用的是CDI,您可以查看Shiro注释拦截器,它只是第一次通过,但它工作正常

我的问题是,当HTTP请求触发方法调用时,注释工作正常,但当web套接字消息触发时,注释不工作。
@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");
   }
}