8
我对此做了一些研究,但找不到解决方案。基于注释的安全限制不适用于网络套接字触发的方法调用
我有这样
@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");
}
}
我的问题是注释工作正常时调用的方法由HTTP请求触发,但当它由web套接字消息触发时它不起作用。 –