Spring Security(十六):5.7 Multiple HttpSecurity
We can configure multiple HttpSecurity instances just as we can have multiple <http>
blocks. The key is to extend the WebSecurityConfigurerAdapter
multiple times. For example, the following is an example of having a different configuration for URL’s that start with /api/
.
- @EnableWebSecurity
- public class MultiHttpSecurityConfig {
- @Bean
- public UserDetailsService userDetailsService() throws Exception {
- InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
- manager.createUser(User.withUsername("user").password("password").roles("USER").build());
- manager.createUser(User.withUsername("admin").password("password").roles("USER","ADMIN").build());
- return manager;
- }
- @Configuration
- @Order(1) 1
- public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
- protected void configure(HttpSecurity http) throws Exception {
- http
- .antMatcher("/api/**") 2
- .authorizeRequests()
- .anyRequest().hasRole("ADMIN")
- .and()
- .httpBasic();
- }
- }
- @Configuration 3
- public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http
- .authorizeRequests()
- .anyRequest().authenticated()
- .and()
- .formLogin();
- }
- }
- }
Configure Authentication as normal
1、Create an instance of WebSecurityConfigurerAdapter that contains @Order to specify which WebSecurityConfigurerAdapter should be considered first.
2、The http.antMatcher states that this HttpSecurity will only be applicable to URLs that start with /api/
3、Create another instance of WebSecurityConfigurerAdapter. If the URL does not start with /api/ this configuration will be used. This configuration is considered after
ApiWebSecurityConfigurationAdapter since it has an @Order value after 1 (no @Order defaults to last).
Spring Security(十六):5.7 Multiple HttpSecurity的更多相关文章
- Spring Security 解析(六) —— 基于JWT的单点登陆(SSO)开发及原理解析
Spring Security 解析(六) -- 基于JWT的单点登陆(SSO)开发及原理解析 在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把 ...
- Spring Boot(十六):使用Jenkins部署Spring Boot
Spring Boot(十六):使用Jenkins部署Spring Boot jenkins是devops神器,介绍如何安装和使用jenkins部署Spring Boot项目 jenkins搭建 部署 ...
- Spring Security(六):2.3 Release Numbering
It is useful to understand how Spring Security release numbers work, as it will help you identify th ...
- 【Spring Security】六、自定义认证处理的过滤器
这里接着上一章的自定义过滤器,这里主要的是配置自定义认证处理的过滤器,并加入到FilterChain的过程.在我们自己不在xml做特殊的配置情况下,security默认的做认证处理的过滤器为Usern ...
- Spring Security教程(六):自定义过滤器进行认证处理
这里接着上篇的自定义过滤器,这里主要的是配置自定义认证处理的过滤器,并加入到FilterChain的过程. 在我们自己不在xml做特殊的配置情况下,security默认的做认证处理的过滤器为Usern ...
- Spring MVC(十六)--Spring MVC国际化实例
上一篇文章总结了一下Spring MVC中实现国际化所需的配置,本文继上一文举一个完整的例子,我选择用XML的方式.我的场景是这样的: 访问一个页面时,这个页面有个表格,对表头中的列名实现国际化. 第 ...
- 网站开发进阶(十六)错误提示:Multiple annotations found at this line:- basePath cannot be resolved to a variable
错误提示:Multiple annotations found at this line: basePath cannot be resolved to a variable 出现以上错误,主要是由下 ...
- (转)Spring Boot(十六):使用 Jenkins 部署 Spring Boot
http://www.ityouknow.com/springboot/2017/11/11/spring-boot-jenkins.html enkins 是 Devops 神器,本篇文章介绍如何安 ...
- Spring Boot(十六):使用 Jenkins 部署 Spring Boot
Jenkins 是 Devops 神器,本篇文章介绍如何安装和使用 Jenkins 部署 Spring Boot 项目 Jenkins 搭建.部署分为四个步骤: 第一步,Jenkins 安装 第二步, ...
- spring boot(十六)使用Jenkins部署spring boot
jenkins是devops神器,本篇文章介绍如何安装和使用jenkins部署Spring Boot项目 jenkins搭建 部署分为三个步骤: 第一步,jenkins安装 第二步,插件安装和配置 第 ...
随机推荐
- 51NOD 1185 威佐夫游戏 V2(威佐夫博弈)
1185 威佐夫游戏 V2 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 有2堆石子.A B两个人轮流拿,A先拿.每次可以从一堆中取任意个或从2堆中取 ...
- BZOJ 1874: [BeiJing2009 WinterCamp]取石子游戏(SG函数)
Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 871 Solved: 365[Submit][Status][Discuss] Description ...
- 2018-12-03 VS Code英汉词典插件v0.0.7-尝试词性搭配
续上文VS Code英汉词典插件v0.0.6-改为TS实现, 加测试后, 继续重构(提取常量, 避免var, 添加类型等等), 并完善测试. 测试方法参考: Testing Visual Studio ...
- SAP MM PR中的Fixed ID字段与MD04里PR单据号后的星号
SAP MM PR中的Fixed ID字段与MD04里PR单据号后的星号 如下图是我手工使用ME51N 创建的一个采购申请单据, MD04去看这个PR, 这个PR号码后面有一个*号,代表它是一 ...
- Openlayer3之绚丽的界面框架-Materialize
一群做C++的老伙计搞前端开发,徒手写html和css应该会折寿..在网上找了半天,Materialize算是用起来很方便的一款前端界面框架.Google的Material Design看起来感觉还是 ...
- JMeter 正则表达式提取器结合ForEach控制器遍历提取变量值
正则表达式提取器结合ForEach控制器遍历提取变量值 by:授客 QQ:1033553122 1. 需要解决的问题 使用正则提取器提取了一组变量值,需要在其它sampler中,循环引用组中的某几 ...
- C# 开启一个新进程并为新进程设置工作目录
Process p = new System.Diagnostics.Process(); //设置新进程的工作目录,如果不设置那么新进程的工作目录为开启这个进程的工作目录 p.StartInfo.W ...
- 接口的绑定方案和动态SQL
1. 接口绑定方案 MyBatis中, 提供了一套接口绑定方案. 程序员可以提供一个接口, 然后提供对应接口的一个mapper.xml文件. MyBatis会自动将接口和xml文件进行绑定. 实际上就 ...
- LeetCode题解之Squares of a Sorted Array
1.题目描述 2.问题分析 使用过两个计数器. 3.代码 class Solution { public: vector<int> sortedSquares(vector<int& ...
- java POI导出Excel文件数据库的数据
在web开发中,有一个经典的功能,就是数据的导入导出.特别是数据的导出,在生产管理或者财务系统中用的非常普遍,因为这些系统经常要做一些报表打印的工作.这里我简单实现导出Excel文件. POI jar ...