合集-spring-security源码阅读
摘要:Form表单登录 默认登录 1.pom配置 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <depende
阅读全文
摘要:部分源码 1.前面一demo的配置是基于内存数据源配置,但是再实际应用中我们都是查库 @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { /** * inMemoryAuth
阅读全文
摘要:说明 在 spring-security使用-登录(一) 我们使用的是重写了Spring-security的filter的方式来进行自定义,但是这样的弊端,就是侵入太大。直接把spring-security的filter给替换掉了, 通过AuthenticationProvider的方式是在spri
阅读全文
摘要:主要是通过Authentication封装 接口定义 public interface Authentication extends Principal, Serializable { //用来获取用户的权限。 Collection<? extends GrantedAuthority> getAu
阅读全文
摘要:自动挤掉前一个用户 1.配置一个用户只允许一个会话 protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .anyRequest().authenticated() .and()
阅读全文
摘要:session共享的几种方案 方案一 不放在服务器应用中管理,放在第三方统一管理,如redis,数据库等,现在主流都是放在redis 因为redis高效qps最高能达到10万+ 方案二 session 拷贝,集群情况某一台服务器session发生改变,通知其他服务器,这样会有个问题,如果集群实例太多
阅读全文
摘要:类图 默认提供2种实现 defaultfHttpFirewall 看源码可以看出来比较宽松,我们一般使用StrictHttpFirewall 限制请求方法 如果需要修改可以自定义StrictHttpFirewall public class StrictHttpFirewall implements
阅读全文
摘要:基于注解 需要配置启用@EnableGlobalMethodSecurity(prePostEnabled = true,securedEnabled = true) prePostEnabled: 确定 前置注解[@PreAuthorize,@PostAuthorize,..] 是否启用 secu
阅读全文
摘要:时序图 @startuml participant "security starter" as sb participant "WebSecurityConfiguration" as wc participant "webSecurity" as ws participant "WebSecuri
阅读全文
摘要:1.SecurityFilterChain是由HttpSecurty根据各个config配置生成的Filter SecurityFilterChain是接口,默认实现是由DefaultSecurityFilterChain SecurityFilterChain只充当描述的作用,描述哪些url走这批
阅读全文
摘要:FilterChainProxy内部存储了我们各个HttpSecurty生成的SecurityFilterChain。FilterChainProxy实现了ServletFilter接口。只真正的入口 org.springframework.security.web.FilterChainProxy
阅读全文
摘要:作用 我们获取当前登录用户信息是根据SecurityContextHolder.getContext()获取的,SecurityContextHolder.getContext()本质是ThreadLocal实现 Spring MVC WebAsyncTask是异步另外一个线程 所以用于保证我们在T
阅读全文
摘要:主要是在认证 Filter链执行之前 维护SecurityContextHolder 方便我们后续通过SecurityContextHolder.getContext()获取当前会话用户信息 通过SecurityContextConfigurer初始化 默认设置源码处:https://www.cnb
阅读全文
摘要:提供我们在Filter链 执行之前或者之后往Header写入内容 通过HttpSecurity 可以指定 默认是在之后调用 http.headers().addHeaderWriter() 通过org.springframework.security.config.annotation.web.co
阅读全文
摘要:负责处理登出相关逻辑,默认url映射是/logout org.springframework.security.config.annotation.web.configurers.LogoutConfigurer 初始化 默认初始化处https://www.cnblogs.com/LQBlog/p/
阅读全文
摘要:最常用的一中过滤器,用于登录认证 http.formLogin() 初始化 类图 AbstractAuthenticationProcessingFilter负责 认证成功和认证失败的调度 提供抽象方法attemptAuthentication 具体的认证逻辑由子类实现 <1> org.sprin
阅读全文
摘要:用于校验session是否过期 过期移除 初始化处:org.springframework.security.config.annotation.web.configurers.SessionManagementConfigurer#configure public void configure(H
阅读全文
摘要:对Session控制和管理 配置 @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .anyRequest() .authenticated() .and
阅读全文
摘要:实现记住密码的自动登录,比如session过期 初始化处 org.springframework.security.config.annotation.web.configurers.RememberMeConfigurer RememberMeAuthenticationProvider的作用可以
阅读全文
摘要:统一的异常处理过滤器,我们可以处理统一的身份认证或者授权的异常 比如未登录访问登录页面 需要认证权限的地方 通过HttpSecurity 可以指定 通过org.springframework.security.config.annotation.web.configurers.ExceptionHa
阅读全文
摘要:FilterSecurityInterceptor最后一个过滤器,主要做认证和授权拦截,比如我们未登录访问需要登录的页面或者我们配置了授权的页面 http.authorizeRequests() .antMatchers("/hello").hasRole("admin").antMatchers(
阅读全文
摘要:使用方式参考:https://www.cnblogs.com/LQBlog/p/15505361.html#autoid-0-0-0 使用注解权限需要通过以下方式启用 @EnableGlobalMethodSecurity(prePostEnabled = true,securedEnabled =
阅读全文
摘要:MethodSecurityInterceptor是Spring Security对于Spring Aop的切入逻辑 @Override public Object invoke(MethodInvocation mi) throws Throwable { //<1>调用方法前的权限校验 Inte
阅读全文
摘要:在有些项目中一套系统可能有多套登录逻辑 比如 /manage/** 管理后台相关接口走后台认证 /h5/api/** 小程序相关接口走token认证 在spring-security源码-初始化(九) 1.在"5.WebSecurityConfiguration首先会初始化一个webSecurity
阅读全文
摘要:比如我们有的业务场景需要走outh2 或者短信验证码登录 下面以短信验证码为例 首先梳理默认的登录流程 1.http.formLogin() 会在WebSecurityConfigurerAdapter创建一个FormLoginConfigurer 2.WebSecurityConfigurerAd
阅读全文
摘要:默认是跳转页面,针对ajax请求我们需要返回json字符串 自定义认证我认为有2种 一种是登录验证 还有一种是未登录访问需要登录授权的页面 登录认证 一般都是使用默认登录或者继承AbstractAuthenticationProcessingFilter方式可以参考上一篇Spring-Securit
阅读全文
摘要:自定义相关授权注解,正常情况不用自定义。支持el比如 @PostMapping("/create") @Operation(summary = "新增字典数据") @PreAuthorize("@ss.hasPermission('system:dict:create')") public Comm
阅读全文

浙公网安备 33010602011771号