简体   繁体   English

覆盖Tomcat基本身份验证

[英]Override Tomcat basic authentication

I'm trying to write a Web-based Setup for my Webapplication (Mainly setting up the database). 我正在尝试为我的Web应用程序编写基于Web的安装程序(主要是设置数据库)。 But because i am using DIGEST authentication for all Servlets i'm having a problem there. 但是因为我对所有Servlet使用DIGEST身份验证,所以我在这里遇到了问题。 I want to be able to ask the user to enter his mysql password, but he can't because he can't login. 我希望能够要求用户输入他的mysql密码,但是他不能,因为他无法登录。 Since the users are Saved in the Database, that doesnt exist at that point, there is no way to log in. 由于用户已保存在数据库中,因此当时还不存在,因此无法登录。

<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>

Can I override the login config for a single Servlet, so the user doesn't have to enter a password? 我是否可以覆盖单个Servlet的登录配置,所以用户不必输入密码?

Notice that you specify <url-pattern>/*</url-pattern> . 请注意,您指定了<url-pattern>/*</url-pattern> You can use this pattern to apply the security constraint to only those URLs that you want to require authentication. 您可以使用此模式将安全性约束仅应用于您想要进行身份验证的URL。 Any URL that does not match this pattern will not have this security constraint applied. 与该模式不匹配的任何URL都不会应用此安全性约束。

You can also add a second security-constraint with a url-pattern that matches the URLs that you don't want secured. 您还可以添加第二个安全约束,其URL模式与您不想保护的URL相匹配。 In this case, leave out the auth-constraint tag entirely so everyone is allowed to access those URLs. 在这种情况下,请完全省略auth-constraint标记,以便所有人都可以访问这些URL。 Look at this other question for an example. 请看另一个问题作为示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM