http.authorizeRequests().antMatchers("/login.html").permitAll()//放行/login.html,不需要认证// .antMatchers("/css/**","/js/**","/images/**").permitAll()//放行静态资源// .antMatchers("/**/*.png").permitAll()//放行后缀.png// .regexMatchers(".+[.]png").permitAll()//放行后缀.png,正则表达式// .regexMatchers(HttpMethod.POST,"/demo").permitAll()//指定请求方法// .antMatchers("/main1.html").hasAuthority("admiN")//基于权限// .antMatchers("/main1.html").hasAnyAuthority("admin","admiN")// .antMatchers("/main1.html").hasRole("abC")//基于角色// .antMatchers("/main1.html").hasAnyRole("abC","abc")// .antMatchers("/main1.html").hasIpAddress("127.0.0.1")//基于IP地址.anyRequest().authenticated();//所有请求都必须认证才能访问,必须登录

1.先匹配url
.anyRequest()
.antMatchers
.regexMatchers
.mvcMatchers 比较较少用

2.再权限管理
denyAll
permitAll

hasAuthority
hasAnyAuthority
hasRole
hasAnyRole

fullAuthority(remember me)
authenticated //登录
hasIpAddress

项目tips

实际中一般先
1)处理放行页面 permitAll
2)处理特殊权限页面 hasAuth
3)剩余全部需登录

参考:
https://stackoverflow.com/questions/19525380/difference-between-role-and-grantedauthority-in-spring-security

Spring Security HttpSecurity.authorizeRequests相关推荐

  1. Spring Security HttpSecurity

    HttpSecurity 1.formLogin 2.authorizeRequests

  2. Spring Security HttpSecurity.formLogin

    http.formLogin() // .usernameParameter("username123")//自定义入参,需要和前端保持一致,默认是username // .pas ...

  3. spring security之httpSecurity使用示例

    httpSecurity 类似于spring security的xml配置文件命名空间配置中的<http>元素.它允许对特定的http请求基于安全考虑进行配置.默认情况下,适用于所有的请求 ...

  4. Spring Security中HttpSecurity常用方法及说明

    本文来说下spring security中HttpSecurity常用方法,这个类在spring security中使用的非常多,功能十分丰富,其中包含的方法也是非常多,在实际的开发中,需要重写里面的 ...

  5. SpringSecurity权限管理框架系列(六)-Spring Security框架自定义配置类详解(二)之authorizeRequests配置详解

    1.预置演示环境 这个演示环境继续沿用 SpringSecurit权限管理框架系列(五)-Spring Security框架自定义配置类详解(一)之formLogin配置详解的环境. 2.自定义配置类 ...

  6. Spring Security Config : HttpSecurity安全配置器 SessionManagementConfigurer

    概述 介绍 作为一个配置HttpSecurity的SecurityConfigurer,SessionManagementConfigurer作了如下配置工作 : 为HttpSecurity提供如下过 ...

  7. spring boot整合spring security笔记

    最近自己做了一个小项目,正在进行springboot和spring Security的整合,有一丢丢的感悟,在这里分享一下: 首先,spring boot整合spring security最好是使用T ...

  8. Spring Security 之集群Session配置

    1.   新建Maven项目 cluster-session 2.   pom.xml <project xmlns="http://maven.apache.org/POM/4.0. ...

  9. Spring boot使用Spring Security和OAuth2保护REST接口

    在本文中,我将会演示SpringSecurity+OAuth2如何去保护SpringBoot上的RESTAPI端点,以及客户端和用户凭证如何存储在关系数据库中.因此,我们需要做到以下几点: 配置Spr ...

最新文章

  1. javascript弹出窗口居中代码
  2. 死磕Java并发:J.U.C之Condition
  3. 连分数中一个有意思的小玩意儿
  4. maven实战总结,工作中常见操作
  5. python3如何使用mysql_python3怎么用sqlalchemy操作mysql
  6. 启动标志_牛股启动的标志:天衣无缝。
  7. luogu 1484\1792 种树 奇怪的贪心可反悔
  8. 执行ssh-add时出现Could not open a connection to your authentication agent
  9. Gridview SummaryItem 格式化数字
  10. this.getstate_Java线程类Thread.State getState()方法(带示例)
  11. ClearCase是全球领先的软件配置管理工具
  12. Expression Design与Blend制作滚动的小球动画教程
  13. 产品读书《自控力:斯坦福大学最受欢迎的心理学课程》
  14. Unity 2D 打地鼠游戏制作过程总结
  15. html meta标签 小图标,meta标签详解及添加ico图标
  16. 树莓派可以搜索到wifi但是连接不上的问题解决方法
  17. 通过httpclient发送请求的几种方式,发送文件、参数、json对象
  18. Mysql、Oracle、DM、Tbase数据库差异性
  19. linux无法切用户,为什么我的linux 无法进行用户的切换?(ylmf os3.0)
  20. DRM应用程序进阶 (atomic-crtc)

热门文章

  1. 计算机组成原理2(PCI总线结构框图)
  2. 项目解析jsx文件_React 基础:JSX 扩展语法
  3. 从零开始学前端:中括号代替点操作,获取对象,自定义标签属性 --- 今天你学习了吗?(JS:Day3)
  4. C/S架构和B/S架构
  5. php登录改为用户名,Laravel 认证脚手架改为使用用户名登录
  6. httpd mysql认证_Apache Httpd服务器之认证与授权
  7. Python课程期末考试编程题自动批卷原理与实现模板
  8. Python使用空域融合技术进行图像去噪
  9. 设计模式 C++工厂方法模式
  10. 基于函数的二叉树的描述