如何弹出身份验证

时间:2013-03-14 05:26:32

标签: java tomcat servlets

我有一个非常简单的疑问,我知道大多数人可能会对这个问题进行投票。但由于我对Web应用程序很陌生,我不知道它是如何出现的。

问题:每当我登录某个Web应用程序时,都会弹出一个请求进行身份验证的弹出窗口。有些事情与此相似,

  

警告:此服务器请求以不安全的方式发送您的用户名和密码(没有安全连接的基本身份验证)。

为此设置的位置在哪里?我试图为我的Hello World应用程序做类似的事情。请帮帮我。

1 个答案:

答案 0 :(得分:2)

这是Servlet技术支持的基本身份验证。这是您在web.xml中为Web资源定义基本身份验证的方法。

<login-config>
      <auth-method>BASIC</auth-method>
      <realm-name>default</realm-name>
</login-config>

请在此处找到完整的示例:

<?xml version='1.0' encoding='UTF-8'?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<web-app>
      <welcome-file-list>
           <welcome-file>welcome.jsp</welcome-file>
      </welcome-file-list>

      <security-constraint>
            <web-resource-collection>
                  <web-resource-name>Success</web-resource-name>
                  <url-pattern>/secured/*</url-pattern>
                 <http-method>GET</http-method>
                 <http-method>POST</http-method>
            </web-resource-collection>
            <auth-constraint>
                <role-name>secured</role-name> 
            </auth-constraint>
      </security-constraint>

      <login-config>
          <auth-method>BASIC</auth-method>
          <realm-name>default</realm-name>
      </login-config>

       <security-role>
           <role-name>secured</role-name>
       </security-role>
</web-app>

请阅读以下链接,以了解有关Servlet技术支持的多种身份验证机制的更多信息:

Standard form authentification Java servlets

相关问题