java - Tomcat7安全样本如何调用login.jsp?

标签 java authentication tomcat tomcat7 sample

如果我打开示例 URL http://localhost:8080/examples/jsp/security/protected/index.jsp第一次,我将看到带有用户名密码字段的登录表单。这种形式的 HTML 代码位于 login.jsp 文件中,但我没有看到从 index.jsp 调用它的代码。这个调用是如何完成的?

最佳答案

在对应的web.xml中定义:

<!-- Default login configuration uses form-based authentication -->
<login-config>
  <auth-method>FORM</auth-method>
  <realm-name>Example Form-Based Authentication Area</realm-name>
  <form-login-config>
    <form-login-page>/jsp/security/protected/login.jsp</form-login-page>
    <form-error-page>/jsp/security/protected/error.jsp</form-error-page>
  </form-login-config>
</login-config>

您可以在 <tomcat>/webapps/examples/WEB-INF 中找到该文件。它利用内置的 Java EE 安全功能。上一篇security-constraint部分定义要保护的资源:

   <security-constraint>
      <display-name>Example Security Constraint</display-name>
      <web-resource-collection>
         <web-resource-name>Protected Area</web-resource-name>
         <!-- Define the context-relative URL(s) to be protected -->
         <url-pattern>/jsp/security/protected/*</url-pattern>
         <!-- If you list http methods, only those methods are protected -->
         <http-method>DELETE</http-method>
         <http-method>GET</http-method>
         <http-method>POST</http-method>
         <http-method>PUT</http-method>
      </web-resource-collection>
      <auth-constraint>
         <!-- Anyone with one of the listed roles may access this area -->
         <role-name>tomcat</role-name>
         <role-name>role1</role-name>
      </auth-constraint>
    </security-constraint>

关于java - Tomcat7安全样本如何调用login.jsp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9033013/

相关文章:

amazon-web-services - 将图像从 EC2 容器注册表部署到 Elastic Beanstalk 凭据?

asp.net-mvc - ASP.Net MVC 应用程序注销未完全注销

java - Paho MQTT客户端仅使用密码时是否支持加密

ubuntu - Ubuntu上Tomcat的反向安装

java - Tomcat 9/JNDI 数据源 - 无法为连接 URL '' 创建类 'null' 的 JDBC 驱动程序

java - for 循环中的 JTextField 数组将自身添加到布局中

java - 如何使用 jOOQ 抽象模式?

java:使用Raw类型作为方法参数会删除参数成员中的所有参数化类型信息

authentication - Tomcat 8 SPNEGO 单点登录不起作用

java - Apache 点燃: choose server node client node will connect to