Spring Security HttpSecurity.authorizeRequests
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相关推荐
- Spring Security HttpSecurity
HttpSecurity 1.formLogin 2.authorizeRequests
- Spring Security HttpSecurity.formLogin
http.formLogin() // .usernameParameter("username123")//自定义入参,需要和前端保持一致,默认是username // .pas ...
- spring security之httpSecurity使用示例
httpSecurity 类似于spring security的xml配置文件命名空间配置中的<http>元素.它允许对特定的http请求基于安全考虑进行配置.默认情况下,适用于所有的请求 ...
- Spring Security中HttpSecurity常用方法及说明
本文来说下spring security中HttpSecurity常用方法,这个类在spring security中使用的非常多,功能十分丰富,其中包含的方法也是非常多,在实际的开发中,需要重写里面的 ...
- SpringSecurity权限管理框架系列(六)-Spring Security框架自定义配置类详解(二)之authorizeRequests配置详解
1.预置演示环境 这个演示环境继续沿用 SpringSecurit权限管理框架系列(五)-Spring Security框架自定义配置类详解(一)之formLogin配置详解的环境. 2.自定义配置类 ...
- Spring Security Config : HttpSecurity安全配置器 SessionManagementConfigurer
概述 介绍 作为一个配置HttpSecurity的SecurityConfigurer,SessionManagementConfigurer作了如下配置工作 : 为HttpSecurity提供如下过 ...
- spring boot整合spring security笔记
最近自己做了一个小项目,正在进行springboot和spring Security的整合,有一丢丢的感悟,在这里分享一下: 首先,spring boot整合spring security最好是使用T ...
- Spring Security 之集群Session配置
1. 新建Maven项目 cluster-session 2. pom.xml <project xmlns="http://maven.apache.org/POM/4.0. ...
- Spring boot使用Spring Security和OAuth2保护REST接口
在本文中,我将会演示SpringSecurity+OAuth2如何去保护SpringBoot上的RESTAPI端点,以及客户端和用户凭证如何存储在关系数据库中.因此,我们需要做到以下几点: 配置Spr ...
最新文章
- javascript弹出窗口居中代码
- 死磕Java并发:J.U.C之Condition
- 连分数中一个有意思的小玩意儿
- maven实战总结,工作中常见操作
- python3如何使用mysql_python3怎么用sqlalchemy操作mysql
- 启动标志_牛股启动的标志:天衣无缝。
- luogu 1484\1792 种树 奇怪的贪心可反悔
- 执行ssh-add时出现Could not open a connection to your authentication agent
- Gridview SummaryItem 格式化数字
- this.getstate_Java线程类Thread.State getState()方法(带示例)
- ClearCase是全球领先的软件配置管理工具
- Expression Design与Blend制作滚动的小球动画教程
- 产品读书《自控力:斯坦福大学最受欢迎的心理学课程》
- Unity 2D 打地鼠游戏制作过程总结
- html meta标签 小图标,meta标签详解及添加ico图标
- 树莓派可以搜索到wifi但是连接不上的问题解决方法
- 通过httpclient发送请求的几种方式,发送文件、参数、json对象
- Mysql、Oracle、DM、Tbase数据库差异性
- linux无法切用户,为什么我的linux 无法进行用户的切换?(ylmf os3.0)
- DRM应用程序进阶 (atomic-crtc)