2014-12-03 98 views
0

我正在尝试为我的Web应用程序(主要设置数据库)编写基于Web的安装程序。 但是因为我使用所有Servlets的DIGEST身份验证,所以我在那里遇到问题。 我希望能够让用户输入他的mysql密码,但他不能,因为他无法登录。由于用户在数据库中保存的,这并不在这一点上存在,就没有办法登录。改写Tomcat基本身份验证

<security-constraint> 
<web-resource-collection> 
    <web-resource-name>Wildcard means whole app requires authentication</web-resource-name> 
    <url-pattern>/*</url-pattern> 
    <http-method>GET</http-method> 
    <http-method>POST</http-method> 
</web-resource-collection> 
<auth-constraint> 
    <role-name>crm_user</role-name> 
</auth-constraint> 
<user-data-constraint> 
    <transport-guarantee>NONE</transport-guarantee> 
</user-data-constraint> 
</security-constraint> 
<login-config> 
<auth-method>DIGEST</auth-method> 
<realm-name>tomcat_realm</realm-name> 
</login-config> 

我可以覆盖一个单独的servlet登录配置,因此用户不必输入密码?

回答

0

请注意,您指定<url-pattern>/*</url-pattern>。您可以使用此模式将安全约束仅应用于您想要验证的URL。任何不符合此模式的网址都不会应用此安全限制。

您还可以添加第二个安全约束,其URL模式与您不希望保护的URL匹配。在这种情况下,完全忽略auth-constraint标签,这样每个人都可以访问这些URL。例如,看这other question

+0

我知道,但我的程序有超过一百个Servlets,我不喜欢将它们全部映射的想法。没有办法给规则添加一个异常? – Kendoha 2014-12-04 11:03:44

+0

@Kendoha我编辑了答案,以包含一个不需要通过链接指向示例来更改现有安全约束的选项。 – Rob 2014-12-04 15:23:19

+0

非常感谢你,我会尝试 – Kendoha 2014-12-05 06:49:57