zoukankan      html  css  js  c++  java
  • 三种SpringSecurity方法级别权限控制

    JSR-250注解

    1、在pom.xml添加
    <dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>jsr250-api</artifactId>
    <version>1.0</version>
    </dependency>

    2、在spring-mvc.xml 开启注解
    <security:global-method-security jsr250-annotations="enabled"></security:global-method-security>

    3、在权限控制的方法上面使用注解
    @RolesAllowed("ADMIN")

    这种也可以写@RolesAllowed("ROLE_ADMIN"),上面是省略ROLE_前缀
    @Secured注解

    1、在spring-mvc.xml 开启注解
    <security:global-method-security secured-annotations="enabled"></security:global-method-security>

    2、在权限控制的方法上面使用注解
    @Secured("ROLE_ADMIN")
    这里不能省略ROLE_前缀
     基于表达式操作

    1、在spring-mvc.xml 开启注解
    <security:global-method-security pre-post-annotations="enabled"></security:global-method-security>

    2、在权限控制的方法上面使用注解
    @PreAuthorize("authentication.principal.username == 'peny'")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    这里可以省略ROLE_前缀;  @PreAuthorize("hasRole('ADMIN')")
  • 相关阅读:
    函数(五)——装饰器,递归调用,匿名函数
    函数(四)——装饰器
    函数(三)
    函数(二)
    函数(一)
    python基础(九)
    python基础(八)
    python基础(七)
    javaweb开发 idea ssm开发(二)
    PHP计算两个经纬度地点之间的距离
  • 原文地址:https://www.cnblogs.com/weiapro/p/11521995.html
Copyright © 2011-2022 走看看