美文网首页
@Secure注解笔记

@Secure注解笔记

作者: Children乏 | 来源:发表于2021-05-19 15:13 被阅读0次

使用示例

    @Secured({"ROLE_user"})
    @GetMapping(value = "get")
    public String get() {
        return "hello get";
    }

踩坑记录:
1、前置条件:必须在@Configuration类中加入如下注解

@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    // ...
}

2、注解内容:大括号中的字符串内容须加上“ROLE_”前缀

试过写成@Secured({"user"}),此时不论用户含有"user"或"ROLE_user"都校验不通过
org.springframework.security.access.vote.RoleVoter源码发现@Secured仅支持带前缀的字符串

    public boolean supports(ConfigAttribute attribute) {
        if ((attribute.getAttribute() != null)
                && attribute.getAttribute().startsWith(getRolePrefix())) {
            return true;
        }
        else {
            return false;
        }
    }

相关文章

  • @Secure注解笔记

    使用示例 踩坑记录:1、前置条件:必须在@Configuration类中加入如下注解 2、注解内容:大括号中的字符...

  • Android & Java 注解和自定义注解处理器

    写在前面:本文是实际工作中学习成果,记为笔记 目录 背景 什么是注解 注解实战:动态注解 注解实战:静态注解 注解...

  • to Learn list

    maven B 笔记 spring IOC docBspring 笔记spring 常用注解 spring AOP...

  • Spring MVC的标签库(学习笔记)

      在《Spring MVC的常用注解(学习笔记)》中提到了使用@ModelAttribute注解,利用Model...

  • ssm整合

    SSM整合笔记 整合Spring 编写xml配置文件,开启注解扫描(指定Controller注解不扫描)