一、使用

1.搭建基础环境

(1)导入 Spring 和 Shiro 的 Jar 包

  • 正常导入 spring jar包
  • 导入日志包
  1. log4j-1.2.15.jar
  2. slf4j-api-1.6.1.jar
  3. slf4j-log4j12-1.6.1.jar
  • 导入 shiro 包
  1. shiro-core-1.2.2.jar
  2. shiro-ehcache-1.2.2.jar
  3. shiro-spring-1.2.2.jar
  4. shiro-web-1.2.2.jar

(2)配置文件

  • web.xml
  1. 读取所有配置文件
  2. springmvc 的 DispatcherServlet 配置
  3. shiroFilter 的配置(该配置参考的是:shiro-root-1.2.2\samples\spring\src\main\webapp\WEB-INF\web.xml)
  4. 见文章末的两个 web.xml
  • spring-shiro.xml
  1. 该配置参考:shiro-root-1.2.2\samples\spring\src\main\webapp\WEB-INF\applicationContext.xml
  2. 此次实验在 shiro.xml 文件中采用的缓存管理器是 ehcache 。需要额外导入ehcache jar包和配置文件。
  3. ehcache 使用的 Hibernate 下的。
  4. ehcache-core-2.4.3.jar(hibernate-release-4.2.4.Final\lib\optional\ehcache\) 和 ehcache.xml(hibernate-release-4.2.4.Final\project\etc\)
  5. 见文章末的两个 spring-shiro.xml
  6. 注意:(1)缓存的配置(2)自定义Realm
  • spring.xml 正常配置即可。
  • springmvc.xml 正常配置即可。

(3)检测

  • 添加自定义 Realm,需要继承自 AuthorizingRealm(即包含认证,也包含授权的 Realm)
  • 添加了一个空的自定义的 Realm ,没有添加认证和授权逻辑。
  • 启动项目,检测能否正常启动,检测配置是否正确。

2.登录

(1)添加登录页面

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <h4>
        Login Page
    </h4>

    <form action="shiro-login" method="post">
        <input name="userName" type="text"/>
        <input name="password" type="password"/>
        <input type="submit" value="submit">
    </form>
</body>
</html>
login.jsp

相关文章:

  • 2021-08-24
  • 2022-12-23
  • 2021-10-07
  • 2021-10-24
  • 2021-11-28
  • 2021-12-18
  • 2021-05-28
猜你喜欢
  • 2022-02-01
  • 2021-04-15
  • 2021-07-15
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
相关资源
相似解决方案