将证书传递给CORS上的SockJs + Stompjs

时间:2014-11-12 03:24:09

标签: sockjs spring-websocket

我已将应用程序连接到websocket服务器

我正在使用通过弹簧安全保护的弹簧腹架

e.g "http://192.168.3.88:8080/api/websocket"
  

api / **由spring security

保护

那么如何将登录信息传递给SockJS? 因为sockJs将其视为授权网址

socket.client = new SockJS("http://192.168.3.88:8080/api/websocket")
socket.stomp = Stomp.over(socket.client) // this is unauthorized
socket.stomp.connect {}, startListener

这里我的春天可以配置:

  

String origin = request.getHeader(ORIGIN);

    response.setHeader("Access-Control-Allow-Origin", origin);

    response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");

    response.setHeader("Access-Control-Max-Age", "3600");

    response.setHeader("Access-Control-Allow-Headers", "origin, content-type, accept, authorization, x-requested-with");

    response.setHeader("Access-Control-Allow-Credentials", "true");

    if (request.getMethod().equals("OPTIONS")) {
        try {
            response.getWriter().print("OK");
            response.getWriter().flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        chain.doFilter(req, res);
    }

0 个答案:

没有答案