我按照本教程使用Java EE设置websocket端点:
由于显而易见的原因有一些关于安全性(需要做更多的工作,例如,无SSL和访问限制/认证)。
所以我的目标是通过改善的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)