SpringSecurity项目中如何在多个模块中配置认证信息
⒈在SpringSecurity项目中创建AuthorizeConfigProvider接口用于配置认证信息
package cn.coreqi.ssoserver.authorize; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; public interface AuthorizeConfigProvider {
void config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config);
}
⒉我们实现此接口
package cn.coreqi.ssoserver.authorize.impl; import cn.coreqi.ssoserver.authorize.AuthorizeConfigProvider;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.stereotype.Component; @Component
public class CoreqiAuthorizeConfigProvider implements AuthorizeConfigProvider {
@Override
public void config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) {
config.antMatchers("/oauth/*","/login/*").permitAll()
.antMatchers(HttpMethod.GET,"/auth/*").hasRole("admin")
.anyRequest().authenticated(); //任何请求都需要身份认证
}
}
⒊在SpringSecurity项目中创建AuthorizeConfigManager接口用于调用系统中所有的配置信息
package cn.coreqi.ssoserver.authorize; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; public interface AuthorizeConfigManager {
void config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config);
}
⒋我们实现此接口
package cn.coreqi.ssoserver.authorize.impl; import cn.coreqi.ssoserver.authorize.AuthorizeConfigManager;
import cn.coreqi.ssoserver.authorize.AuthorizeConfigProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.stereotype.Component; import java.util.Set; @Component
public class CoreqiAuthorizeConfigManager implements AuthorizeConfigManager {
/**
* 将系统中所有的AuthorizeConfigProvider收集起来
*/
@Autowired
private Set<AuthorizeConfigProvider> authorizeConfigProviders;
@Override
public void config(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry config) {
for (AuthorizeConfigProvider authorizeConfigProvider : authorizeConfigProviders ){
authorizeConfigProvider.config(config);
}
config.anyRequest().authenticated();
}
}
⒌在SpringSecurity配置中进行如下配置
@EnableWebSecurity
public class SsoWebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired
private AuthorizeConfigManager authorizeConfigManager;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin()
.and()
.csrf().disable(); //禁用CSRF authorizeConfigManager.config(http.authorizeRequests());
}
}
SpringSecurity项目中如何在多个模块中配置认证信息的更多相关文章
- Maven多模块项目新建技巧-解决公共项目install之后可以在单独模块中直接编译
说明:如果按照这种方式http://www.cnblogs.com/EasonJim/p/8303878.html,且按照常规的install方式在子项目中编译项目,那么需要先install一下par ...
- 基于SqlSugar的开发框架循序渐进介绍(7)-- 在文件上传模块中采用选项模式【Options】处理常规上传和FTP文件上传
在基于SqlSugar的开发框架的服务层中处理文件上传的时候,我们一般有两种处理方式,一种是常规的把文件存储在本地文件系统中,一种是通过FTP方式存储到指定的FTP服务器上.这种处理应该由程序进行配置 ...
- require、module、exports dojo中的三个特殊模块标识
查看dojo源码过程中,发现这三个模块名并不以dojo.dijit.dojox开头,在dojo加载器中属于特殊模块名. require 这是一个上下文智能的加载器. 我们通过dojoConfig配置了 ...
- Python之os.path路径模块中的操作方法总结
#os.path模块主要集成了针对路径文件夹的操作功能,这里我们就来看一下Python中的os.path路径模块中的操作方法总结,需要的朋友可以参考下 解析路径路径解析依赖与os中定义的一些变量: o ...
- 05传智_jbpm与OA项目_部门模块中增加部门的jsp页面增加一个在线编辑器功能
这篇文章讲的是在线编辑器功能,之前的部门模块中,增加部门的功能jsp页面起先是这么做的.
- 在eclipse中公布maven的多模块web项目到tomcat上及单步debug模块jar
1.在eclipse中公布maven的多模块web项目到tomcat eclipse和maven及tomcat的部署略去,还有maven的基础知识和使用在此处略去. 依照例如以下的步骤操作: 将lib ...
- 基于Vue的工作流项目模块中,使用动态组件的方式统一呈现不同表单数据的处理方式
在基于Vue的工作流项目模块中,我们在查看表单明细的时候,需要包含公用表单信息,特定表单信息两部分内容.前者表单数据可以统一呈现,而后者则是不同业务的表单数据不同.为了实现更好的维护性,把它们分开作为 ...
- Smart3D系列教程3之 《论照片三维重建中Smart3D几个工作模块的功能意义》
[摘要] 近年来,倾斜摄影测量技术是国际测绘遥感领域近年发展起来的一项高新技术,利用照片进行三维重建成为一项关键性的技术.Smart3D软件,是照片三维重建主流软件之一,本文将就Smart3D建模软件 ...
- iOS 模仿一个小项目,总结一下里边的模块
ManoBoo: 参考链接:http://www.jianshu.com/p/fd4c46c31508 这个小的项目是参考ManoBoo的简书的,链接在上方,自己在仿做的过程中,也离不开Man ...
随机推荐
- 如何在springcloud分布式系统中实现分布式锁?
一.简介 一般来说,对数据进行加锁时,程序先通过acquire获取锁来对数据进行排他访问,然后对数据进行一些列的操作,最后需要释放锁.Redis 本身用 watch命令进行了加锁,这个锁是乐观锁.使用 ...
- [DUBBO] Unexpected error occur at send statistic, cause: Forbid consumer 192.168.3.151 access servic
[DUBBO] Unexpected error occur at send statistic, cause: Forbid consumer 192.168.3.151 access servic ...
- 2017-12-15python全栈9期第二天第七节之数字转换成布尔值
#!/user/bin/python# -*- coding:utf-8 -*-print(bool(2))
- Thymeleaf中的&&解析问题
1.问题: 最近使用了新的html模板thymeleaf..在模板里使用js语法时遇到问题,&&不能正确的被解析,使用if(a&&b){}可以通过模板解析,但是浏览器上 ...
- Linux系统IO分析工具之iotop常用参数介绍
Linux系统IO分析工具之iotop常用参数介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在一般运维工作中经常会遇到这么一个场景,服务器的IO负载很高(iostat中的 ...
- java中用jdom创建xml文档/将数据写入XML中
import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; i ...
- 2016vijos 1-3 兔子的晚会(生成函数+倍增FWT)
求出序列的生成函数后,倍增FWT #include<cstdio> using namespace std; #define N 2048 ; int inv; ]; int Pow(in ...
- Shell编程(二)Bash中调用Python
- java项目中文件含义
1. java项目 .project:是工程构建配置文件 .classpath:保存的是项目所用的外部引用包的路径 .settings:记录项目配置变化的记录文件夹 src:sourcefolder项 ...
- php中inset 和 和 empty 的区别
inset函数 用途:检测变量是否设置判断:检测变量是否设置,并且不是 NULL.如果已经使用 unset() 释放了一个变量之后,它将不再是 isset().若使用 isset() 测试一个被设置成 ...