• Tomcat安全域


    安全域概念:

      是tomcat的内置功能,,org.apache.catalina.Realm接口声明了将一组用户名、密码以及所关联的角色集成到Tomcat的方法。

    提供了以下8种安全域类型:

        1.内存域(MemoryRealm):访问以一组对象的形式存放在内存中的安全认证信息。服务启动时,会从XML(conf/tomcat-users.xml)中读取安全认证信息并初始化。

        2.用户数据库域(UserDatabaseRealm):访问JNDL资源中用户数据库的安全认证信息。通常以xml文件的形式存放。

       3.JDBC域:通过JDBC驱动程序访问存放在数据库中的安全验证信息。

       4.数据源域、JNDL域、JAAS域、混合域、LoclOut域。

    二、安全域的基本配置

       首先,在web.xml配置文件中为web资源设置安全约束,需配置<security-constraint>和<login-config>

    然后在server.xml或context.xml中配置<Realm><Engine>所有虚拟主机共享</><Host>本虚拟主机所有web共享</><Context>本web应用共享

    案例:

    <security-constraint>
    <display-name>Test Security</display-name>
    <web-resource-collection>
         <web-resorce-name>Protected</web-resource-name>
         <url-pattern>/protected/*</url-pattern>
         <http-method>GET</http-method>
         <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
          <role-name>admin</role-name>
    </auth-constraint>
    </security-constraint>
    
    <login-config>
       <auth-method>FROM</auth-method>(三种验证,basic基本验证,DIGEST摘要验证)
       <realm-name>登录表单验证</realm-name>
       <form-login-config>
          <form-login-page>/login.jsp</form-login-page>
          <form-error-page>/error.jsp</form-error-page>
       </form-login-config>
    </login-config>
  • 相关阅读:
    Spring Boot 的各种start
    Lombok介绍、使用方法和总结
    JS字符串与二进制的相互转化
    java字符串与二进制的相互转化
    DevExpress WPF v18.2新版亮点(六)
    用MyEclipse开发REST Web Service
    .NET界面控件DevExpress发布v18.2.4|附下载
    DevExpress WPF v18.2新版亮点(五)
    「版本升级」MyEclipse CI 2018.12.0正式发布
    MyEclipse使用教程:在Web项目中使用Web片段
  • 原文地址:https://www.cnblogs.com/HYV587/p/14467508.html
Copyright © 2020-2023  润新知