操作步骤
1、创建动态的Web项目
2、导入Spring 和 Shiro 的 jar 包
3、配置web.xml 、 applicationContext.xml 、 springmvc.xml
web.xml配置文件:
①配置Spring的ContextLoaderListener
②配置springmvc的DispatcherServlet
③配置字符编码过滤器
springmvc.xml配置文件:
①两个标准的配置
②配置视图解析器
③配置要扫描的包
applicationContext.xml配置文件:
完成以上配置,再去检验一下spring是否配置正确,在根目录下面创建.jsp文件:发布到tomcat服务器上面;看看是否能够显示;若通过,接下来配置shiro
web.xml 配置文件 添加配置:
①配置shiro的 shiroFilter
applicationContext.xml配置文件 添加配置:
①配置 securityManager
②配置cacheManager
③配置Realm
④配置LifecycleBeanPostProcessor
⑤启用IOC 容器中使用shiro的注解
⑥配置shiroFilter
截图说明(重要的截图)




认证——小例子





注意:applicationContext.xml配置文件里面要做出相应修改的地方
例子路径:E:\student\FFCS\shiro-2
认证的流程:
身份认证流程:
•1、首先调用 Subject.login(token) 进行登录,其会自动委托给SecurityManager
•2、 SecurityManager 负责真正的身份验证逻辑;它会委托给Authenticator 进行身份验证;
•3、 Authenticator 才是真正的身份验证者,Shiro API 中核心的身份认证入口点,此处可以自定义插入自己的实现;
•4、 Authenticator 可能会委托给相应的 AuthenticationStrategy 进行多 Realm 身份验证,默认 ModularRealmAuthenticator 会调用AuthenticationStrategy 进行多 Realm 身份验证;
•5、 Authenticator 会把相应的 token 传入 Realm,从 Realm 获取身份验证信息,如果没有返回/抛出异常表示身份验证失败了。此处可以配置多个Realm,将按照相应的顺序及策略进行访问。
•Realm:Shiro 从 Realm 获取安全数据(如用户、角色、权限),即 SecurityManager 要验证用户身份,那么它需要从 Realm 获取相应的用户进行比较以确定用户身份是否合法;也需要从Realm得到用户相应的角色/权限进行验证用户是否能进行操作
项目路径:E:\student\FFCS\shiro-2
网友评论