赤赤元
有梦想的咸鱼

安全域概念:

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

 

posted on 2021-03-02 10:07  赤赤元  阅读(147)  评论(0编辑  收藏  举报