zoukankan      html  css  js  c++  java
  • Shiro配置

    pom.xml 添加配置:

    <!--
    Apache Shiro所需的jar包--> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-web</artifactId> <version>1.2.2</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>1.2.2</version> </dependency>

    web.xml添加:

    <!-- Shiro配置 --> 
    <filter> 
        <filter-name>shiroFilter</filter-name> 
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
    </filter> 
    <filter-mapping> 
        <filter-name>shiroFilter</filter-name> 
        <url-pattern>/*</url-pattern> 
    </filter-mapping>

    Shiro对象:
    Subject:主体,代表了当前“用户”,这个用户不一定是一个具体的人,与当前应用交互的任何东西都是Subject,如网络爬虫,机器人等;即一个抽象概念;所有Subject都绑定到SecurityManager,与Subject的所有交互都会委托给SecurityManager;可以把Subject认为是一个门面;SecurityManager才是实际的执行者;

    SecurityManager:安全管理器;即所有与安全有关的操作都会与SecurityManager交互;且它管理着所有Subject;可以看出它是Shiro的核心,它负责与后边介绍的其他组件进行交互,如果学习过SpringMVC,你可以把它看成DispatcherServlet前端控制器;

    Realm:域,Shiro从从Realm获取安全数据(如用户、角色、权限),就是说SecurityManager要验证用户身份,那么它需要从Realm获取相应的用户进行比较以确定用户身份是否合法;也需要从Realm得到用户相应的角色/权限进行验证用户是否能进行操作;可以把Realm看成DataSource,即安全数据源。

    也就是说对于我们而言,最简单的一个Shiro应用:
    1、应用代码通过Subject来进行认证和授权,而Subject又委托给SecurityManager;
    2、我们需要给Shiro的SecurityManager注入Realm,从而让SecurityManager能得到合法的用户及其权限进行判断。

  • 相关阅读:
    PHP-redis命令之 列表(lists)
    PHP-redis命令之 散列(hashes)
    PHP-redis命令之 字符串 (strings)
    CentOS 7.0:搭建SVN服务器
    Redis 数据类型分析 字符串 哈希 列表 集合 有序集合 优缺点 分析 注意事项 存储结构
    CentOS 7安装配置Redis数据库
    封装微信分享到朋友/朋友圈js
    PHP 微信分享(及二次分享)
    Ajax登陆,使用Spring Security缓存跳转到登陆前的链接
    IDEA thymeleaf ${xxx.xxx}表达式报错,红色波浪线
  • 原文地址:https://www.cnblogs.com/ifindu-san/p/8616661.html
Copyright © 2011-2022 走看看