如何在Openshift Websockets和Tomcat7上执行Basic Auth

时间:2015-02-02 06:51:25

标签: tomcat authentication websocket openshift

在我的常规Openshift Tomcat7盒式磁带中,我有一个websocket端点启动并运行。客户端可以连接和交互(在Port 8000上)。 现在我想在websockets上做一些Basic Auth,这样只有经过身份验证的客户端才能连接到websocket。

但是当我添加相应的<web-resource-collection>(适用于其他URL)时,它不会影响websocket端点。

我的web.xml部分如下:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>auth</web-resource-name>
        <url-pattern>/autharea/*</url-pattern>
    </web-resource-collection>
    <web-resource-collection>
        <web-resource-name>wsauth</web-resource-name>
        <url-pattern>/ws/*</url-pattern> <!-- websockets are here-->
    </web-resource-collection>
    <auth-constraint>
        <role-name>user</role-name>
    </auth-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>Basic Authentication</realm-name>
</login-config>
<security-role>
    <role-name>user</role-name>
</security-role>

回显服务器的注释如下:

@ServerEndpoint(value = "/ws/echo")
public class EchoServer {
   ....
}

在本地,身份验证就像一个魅力(所以我猜测它是重新路由到端口8000,在这里击中我)。 有没有办法将Tomcat配置为在Openshift中对websockets进行基本身份验证?

0 个答案:

没有答案