小编Tob*_*ers的帖子

如何保证在Java EE的一个端点的WebSocket?

我按照本教程使用Java EE设置websocket端点:

https://technology.amis.nl/2013/06/22/java-ee-7-ejb-publishing-cdi-events-that-are-pushed-over-websocket-to-browser-client/

由于显而易见的原因有一些关于安全性(需要做更多的工作,例如,无SSL和访问限制/认证)。

所以我的目标是通过改善的WebSocket安全

  • 使用SSL(wss://而不是ws://)-完成
  • 设置用户认证(web.xml中) - 完成
  • 强制执行SSL通信(web.xml中) - 完成
  • 确保与令牌(有限寿命)的WebSocket连接

我的问题:如何验证在ServerEndpoint在LoginBean中创建的令牌?

奖励问题:我是否错过了在Java EE中保护Websocket的一些重要部分?

这是我到目前为止的内容:

服务器端点

import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/user/endpoint/{token}")
public class ThisIsTheSecuredEndpoint {

    @OnOpen
    public void onOpen(@PathParam("token") String incomingToken, 
    Session session) throws IOException {

        //How can i check if the token is valid?

    }      
}
Run Code Online (Sandbox Code Playgroud)

LoginBean

@ManagedBean
@SessionScoped
public class LoginBean {

public String login() {

    FacesContext facesContext = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest)facesContext.getExternalContext().getRequest();

    try {
        request.login("userID", "password");

        HttpSession session = request.getSession();

        // here …
Run Code Online (Sandbox Code Playgroud)

java security java-ee websocket

2
推荐指数
1
解决办法
3662
查看次数

标签 统计

java ×1

java-ee ×1

security ×1

websocket ×1