@Override
protected void configure(HttpSecurity http) throws Exception {
//如果配置为需要登录
if (needLogin) {
http
.authorizeRequests()
.antMatchers("/keepalived", "/revision","/static/**").permitAll()
.antMatchers("/manager/**").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/index",true)
.permitAll()
.and()
.logout().permitAll();
      }

配置如上所示。但是需要注意,检查的是ADMIN角色,库里存的字段要是ROLE_ADMIN,而不是ADMIN。

The HttpServletRequest.isUserInRole(String) will determine if SecurityContextHolder.getContext().getAuthentication().getAuthorities() contains a GrantedAuthority with the role passed into isUserInRole(String). Typically users should not pass in the "ROLE_" prefix into this method since it is added automatically. For example, if you want to determine if the current user has the authority "ROLE_ADMIN", you could use the following:

boolean isAdmin = httpServletRequest.isUserInRole("ADMIN");

This might be useful to determine if certain UI components should be displayed. For example, you might display admin links only if the current user is an admin.

Spring Boot Security 基于角色的访问控制的更多相关文章

  1. Spring Boot Security 保护你的程序

    Spring Boot Security 本示例要内容 基于角色的权限访问控制 加密.解密 基于Spring Boot Security 权限管理框架保护应用程序 String Security介绍 ...

  2. 一个基于角色的访问控制(RBAC)的简单示例

    关于"基于角色的访问控制"是什么,本文不再赘述,如果不明白,请自行查阅资料了解. 本文参考用户·角色·权限·表的设计的思想设计. 本文用到的技术有Spring Boot.Sprin ...

  3. YIi 权限管理和基于角色的访问控制

    验证和授权(Authentication and Authorization) 定义身份类 (Defining Identity Class) 登录和注销(Login and Logout) 访问控制 ...

  4. Spring Boot Security 整合 OAuth2 设计安全API接口服务

    简介 OAuth是一个关于授权(authorization)的开放网络标准,在全世界得到广泛应用,目前的版本是2.0版.本文重点讲解Spring Boot项目对OAuth2进行的实现,如果你对OAut ...

  5. Spring Boot Security配置教程

    1.简介 在本文中,我们将了解Spring Boot对spring Security的支持. 简而言之,我们将专注于默认Security配置以及如何在需要时禁用或自定义它. 2.默认Security设 ...

  6. Spring Boot Security Oauth2之客户端模式及密码模式实现

    Spring Boot Security Oauth2之客户端模式及密码模式实现 示例主要内容 1.多认证模式(密码模式.客户端模式) 2.token存到redis支持 3.资源保护 4.密码模式用户 ...

  7. RBAC基于角色的访问控制

    RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联.简单地说,一个用户拥有若干角色,每一个角色拥有若干权限.这样,就构造成"用 ...

  8. RBAC(Role-Based Access Control,基于角色的访问控制)

    RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联.简单地说,一个用户拥有若干角色,每一个角色拥有若干权限.这样,就构造成“用户-角色- ...

  9. RBAC(Role-Based Access Control)基于角色的访问控制

    RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联.简单地说,一个用户拥有若干角色,每一个角色拥有若干权限.这样,就构造成"用 ...

随机推荐

  1. mysql 获取上个月,这个月的第一天或最后一天

    /*上个月今天的当前时间*/select date_sub(now(),interval 1 month) /*上个月今天的当前时间(时间戳)*/select UNIX_TIMESTAMP(date_ ...

  2. 5、flask之信号和mateclass元类

    本篇导航: flask实例化参数 信号 metaclass元类解析 一.flask实例化参数 instance_path和instance_relative_config是配合来用的:这两个参数是用来 ...

  3. <script>标签中的 defer 与 async区别

    在html里,使用<script>标签对脚本进行外部或内部引用,<script>标签包含了两个特殊的属性:defer与async,他们的区别如下: 1.若<script& ...

  4. mac中配置jdk环境

  5. FZU 2234

    题目为中文,题意略. 这个题目我开始用贪心做bfs两次,这样做是错的,因为两次局部的最优解并不能得出全局的最优解,以下面样例说明: 3 0   10   -1 10   10   10 1   0  ...

  6. 批标准化(Batch Norm)

    BN作用: 加速收敛 控制过拟合,可以少用或不用Dropout和正则 降低网络对初始化权重不敏感 允许使用较大的学习率 一.如何加速收敛? 通过归一化输入值/隐藏单元值,以获得类似的范围值,可加速学习 ...

  7. CodeForces-749B

    给定3个坐标,求可能构成平行四边形的第四个点,枚举两个点,根据这两个点的横纵坐标差,来得到第四个点的坐标,注意生成的坐标需要判重. AC代码: #include<cstdio> #incl ...

  8. nginx proxy_pass 与 rewrite 简记

    rewrite syntax: rewrite regex replacement [flag] Default: - Context: server, location, if 如果正则表达式(re ...

  9. Unix代码段和数据段

    关于UNIX系统代码段和数据段分开的目的:方便编程. 1)代码段:代码段是用来存放可执行文件的操作指令,也就是说是它是可执行程序在内存中的镜像.代码段需要防止在运行时被非法修改,所以只准许读取操作,而 ...

  10. html标签详解

    html标签详解   <!DOCTYPE> 标签 <!DOCTYPE> 声明必须是 HTML 文档的第一行,位于 <html> 标签之前. <!DOCTYPE ...