如何在 GWT 中使页面不安全

How to make a page non secure in GWT

我有一个名为客户注册页面的页面,无需 authenticating/logging-in(不安全)即可访问该页面。通常我可以定义特定于 JSP 或 HTML 页面的安全约束。但是在我的 GWT 应用程序中,我使用 Composite class 和 ui.xml 作为模板。

这就是 link 的样子 http://127.0.0.1:8888/MyProject.html?gwt.codesvr=localhost:9997#Customer%20Signup

这是我的web.xml

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Secure section</web-resource-name>
        <description />
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <description />
        <role-name>ROLE_ADMIN</role-name>
    </auth-constraint>
</security-constraint>

您可以使用宽松的 <auth-constraint>(或 none)设置添加另一个安全约束。 URL 模式必须比保护模式更具体。

所以,这应该有效:

<security-constraint>
<web-resource-collection>
    <web-resource-name>Secure section</web-resource-name>
    <description />
    <url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
    <description />
    <role-name>ROLE_ADMIN</role-name>
</auth-constraint>
</security-constraint>

<security-constraint>
<web-resource-collection>
    <web-resource-name>Secure section</web-resource-name>
    <description />
    <url-pattern>/signup.jsp</url-pattern>
</web-resource-collection>
</security-constraint>

第二个约束推翻 signup.jsp 页面上的第一个约束,因为它更具体。我从未尝试将 url 模式扩展到位置定义,即在 # 符号之后,但我想这不会起作用,因为请求参数在前面。所以,你应该为注册创建一个新页面。

J2EE 文档在此处指定了部分,据说 URL 模式与请求 URI 匹配,后者又是 hostname/port 之后的部分 - 因此它应该包括片段。鉴于此,匹配路径 中的锚点应该 最终起作用。 http://docs.oracle.com/cd/E19798-01/821-1841/bncbk/index.html and https://www.rfc-editor.org/rfc/rfc7230#page-17

更新:也许我对您有一个想法:如果我没听错,您需要一个作为应用程序一部分的登录页面。这里的问题是,您对整个应用程序具有相同的 URI。但是您可以使用 url 模式保护您的后端服务,这样您就无法在没有设置凭据的情况下使用后端。

在这种情况下,您的登录页面已加载并且应用程序调用服务器进行初始数据加载。数据加载将失败,因为您尚未登录。onFailure 代码必须识别特殊故障(无凭据)并显示登录视图。 登录视图将调用未受保护(或排除)的后端 servlet 进行登录,并在会话中准备用户凭据。

然后您 return 到您在应用程序中的初始位置,现在在会话中有一个合适的用户,您的后端调用将成功。

这应该可以解决问题。