zoukankan      html  css  js  c++  java
  • shiro安全框架

    安全问题

    1. 如何登录(登录验证)
    2. 权限管理(请求地址过滤)
    3. 页面内容的权限过滤(标签库)

    Shiro简介

    Apache shiro是一个强大且易用的JAVA安全框架通过shiro提供的api可以非常容易的程序中的认证登录验证),授权根据不同的用户配置不同的权限,加密(MD5不可逆的加密),和session管理等功能。

    包括小型移动应用,大型WEB应用、企业级应用(OAERP)。

    Shiro的工作原理

    在过滤器基础上进行封装,通过配置文件,注解和标签(类似jstl)实现了一套功能非常强大的权限管理框架

    核心概念(核心组件)

      Subject主体 —— session中的User对象 

      SecurityManger 安全管理——保安队长

      SessionManager 管理session  

      AuthorizingRealm 授权领域 (负责认证和授权)

      CacheManager 缓存

      RememberMeManager 记住密码的功能(不推荐使用)

    Shiro的使用

    1. 使用shiro.ini 管理用户、角色、权限

    标签库(<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>

    <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
    <%--
      Created by IntelliJ IDEA.
      User: DELL
      Date: 2019/8/28
      Time: 16:04
      To change this template use File | Settings | File Templates.
    --%>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    <%--                     property="userName"--%>
    <div>你好! <shiro:principal></shiro:principal></div>
    
    <div>登录可得</div>
    <div>
        <h2>需要角色才能访问内容</h2>
        <shiro:hasRole name="admin">
            该内容只限admin角色才能查看
            <a href="#">删除</a>
        </shiro:hasRole>
    
        <shiro:lacksRole name="admin">
            没有admin角色看到的内容
        </shiro:lacksRole>
    </div>
    
    <div>
        <h2>某些特定权限看到的</h2>
        <div>
            <shiro:hasPermission name="create">
                当用户必须拥有create权限才能看到的这个内容
            </shiro:hasPermission>
        </div>
        <div>
            <shiro:lacksPermission name="create">
                这个用户没有create权限看到的
            </shiro:lacksPermission>
        </div>
    </div>
    </body>
    </html>

    权限配置说明

  • 相关阅读:
    什么是主从复制、读写分离、为什么要使用
    Swift 4.0 + Ipad开发项目中值得注意知识点
    Swift细节记录<一>
    ECMAScript 6复习<一>
    Swift4.0复习访问控制与作用域
    Swift4.0复习操作符方法与操作符的定制
    Swift4.0复习错误处理
    Swift4.0复习扩展
    Swift4.0复习泛型
    TCP的三次握手(建立连接)和四次挥手(关闭连接)
  • 原文地址:https://www.cnblogs.com/lin02/p/11480434.html
Copyright © 2011-2022 走看看