Comments (1)
3.2 开始支持java配置
WebSecurityConfigurerAdapter.configure(Httpsecurity http) 的默认配置
- 所有请求都需要认证
- 表单登录认证开放
- HTTP认证开放
调用/logout会发生的事情(默认情况下)
- 清除HTTP的session
- 清除配置的rememberMe
- 清除SecurityContextHolder
- 重定向到/login?logout
LogoutSuccessHandler被指定的时候,logoutSuccessUrl( )会被忽略。
HttpStatusReturningLogoutSuccessHandler用在restful的api下
spring security基本架构
- SecurityContextHolder 用来存储SecurityContext
- SecurityContext 用来保存Authentication 和一些特定的请求信息
- Authentication 用来代表 Spring security的主要数据
- GrantedAuthority 反映应用范围内的权限认证
- UserDetails 从数据源(DAO或者另外的数据),获取必要的认证信息
- UserDetailsService : 传入username,获取UserDetails
SecurityContextHolder存储方式
- SecurityContextHolder.MODE_GLOBAL : 全局存储
- SecurityContextHolder.MODE_INHERITABLETHREADLOCAL :线程与其产生的子线程共享存储
- SecurityContextHolder.MODE_THREADLOCAL : 线程之间单独存储
读取当前的user信息
SecurityContextHolder.getContext().getAuthentication().getPrincipal(); //用户信息
SecurityContextHolder.getContext().getAuthentication().getAuthorities();//用户权限
自定义user鉴别
实现UserDetailsService
同时在configure( AuthenticationManagerBuilder auth )中,配置auth.userDetailsService(myUserDetailsService);
后台实现登录(伪)
基于其存储原理,可进行以下的操作(官方Demo, PS : 官方为了展示security的内部流程而写的):
- 实现AuthenticationManager ,在其方法中写入权限 ;调用后得到完整的Authentication (官方demo是在里面验证了password的正确性)
- SecurityContextHolder.getContext().setAuthentication(authentication ); 写入权限
Web Application的认证
- 主要的类 : ExceptionTranslationFilter,AuthenticationEntryPoint
- ExceptionTranslationFilter :
from blog.
Related Issues (20)
- spring源码阅读笔记 HOT 13
- spring源码阅读笔记④--RequestDispatcherServlet
- springboot笔记 HOT 6
- springcloud文档阅读笔记
- spring data JPA 笔记 HOT 3
- Blog 项目所遇到部分问题 HOT 1
- MYSQL笔记 HOT 2
- Intellij Idea相关笔记 HOT 3
- Javascript/TypeScript/thymeleaf.....
- Java-other HOT 2
- Tool Mark HOT 2
- spring源码阅读笔记②--常用接口
- Golang HOT 3
- spring源码阅读笔记③
- spring源码阅读笔记⑤--注解记录--持续更新
- maven笔记 HOT 1
- springboot配置服务器符合CORS规范
- 《鸟叔的Linux私房菜》读书笔记 HOT 1
- code-base HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.