-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c272f5
commit f10db91
Showing
99 changed files
with
2,850 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
开发计划 | ||
=== | ||
|
||
- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
# spring-security-oauth2 | ||
spring-security-kit | ||
==== | ||
|
||
Spring Security OAuth2 开箱即用 | ||
|
||
项目列表 | ||
---- | ||
|
||
使用 | ||
--- | ||
|
||
使用方需要提供的类: | ||
```java | ||
UserDetailsService | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Introduction | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Summary | ||
|
||
* [Introduction](README.md) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
用户id的获取 |
Binary file added
BIN
+9.1 KB
docs/asset/images/authentication-filter-provider-userDetailsService-group.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.1 KB
...ing/spring-security/authentication-filter-provider-userDetailsService-group.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.3 KB
docs/asset/spring/spring-security/authentication-flow-to-company-flow-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+42.5 KB
docs/asset/spring/spring-security/authentication-flow-to-company-flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
登录方式 | ||
=== | ||
|
||
username/email/phone + password | ||
--- | ||
|
||
phone + smscode | ||
--- | ||
|
||
social account | ||
--- | ||
|
||
### weixin | ||
|
||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Remember Me 和 Anonymous | ||
=== | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Remember Me | ||
=== | ||
|
||
实现原理 | ||
|
||
cookie |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
## 认证失败/成功的结果handler | ||
|
||
## 授权失败的handler | ||
|
||
## 拓展 | ||
|
||
### @ControllerAdvice 在过滤器链的位置 | ||
|
||
### 获取公共对象的方法 | ||
|
||
TODO | ||
--- | ||
|
||
- 排插的口(策略模式) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
OAuth 2.0 | ||
=== | ||
|
||
四种模式 | ||
--- | ||
|
||
### password | ||
|
||
简介 | ||
|
||
流程 | ||
|
||
restful使用 | ||
```shell | ||
curl http://localhost:8080/auth/token?grant_type=password | ||
``` | ||
|
||
### client | ||
```shell | ||
curl http://localhost:8080/auth/token?grant_type=client | ||
``` | ||
|
||
### authentication_code | ||
```shell | ||
curl http://localhost:8080/auth/token?grant_type=authentication_code | ||
``` | ||
|
||
### refresh_token | ||
```shell | ||
curl http://localhost:8080/auth/token?grant_type=refresh_token | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
更多安全认证 | ||
=== | ||
|
||
ip访问限制 | ||
--- | ||
|
||
限制频繁操作 | ||
--- |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## 前言 | ||
Spring Seuciry相关的内容看了实在是太多了,但总觉得还是理解得不够巩固,还是需要靠知识输出做巩固。 | ||
|
||
Spring Security简单地说,就是一个过滤器链,但详细理解下来又会觉得极其复杂,这和Spring的magic配置有着很大的关系。 | ||
|
||
## 过滤器链 | ||
|
||
在介绍认证流程之前,非常有必要讲解一下Spring Security的过滤器链。 | ||
|
||
![Spring Security FilterChain](../asset/images/spring-security-filter-chain.png) | ||
|
||
我们可以从SpringSecurity的源码看到过滤器链的构造过程。DefaultSecurityFilterChain | ||
|
||
```java | ||
|
||
``` | ||
|
||
| 过滤器类 | 字符串表示 | 功能 | | ||
| --- | --- | --- | --- | | ||
| SecurityContextPersistenFilter | 无 | | | | ||
|
||
- 默认配置 | ||
- 配置方法(如何生效) | ||
- 覆盖方法 | ||
- 是否自动生效 | ||
- 过滤器链如何和系统进行连接 | ||
|
||
特殊讲解几个过滤器类 | ||
|
||
### SecurityContextPersistenFilter | ||
|
||
### ExceptionTranslationFilter | ||
|
||
### FilterSecurityInterceptor | ||
|
||
- [ ] 如何卸载或者替换默认的Filter | ||
- [ ] 一个前台成功之后,是否还会经过其他前台的处理 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
验证码的更多实现 | ||
--- | ||
|
||
### 防止获取验证码接口被恶意攻击 | ||
|
||
### 异常ip要求输入验证码 | ||
|
||
### 待解决问题 | ||
|
||
如果过于频繁的去刷 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
验证码实现 | ||
=== | ||
|
||
### 图片验证码 | ||
|
||
### 短信验证码 | ||
|
||
### 文字验证码 | ||
|
||
### 拼图验证码 | ||
|
||
### 他山之石 | ||
|
||
大疆的验证码方案 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Web验证码的讲解 | ||
=== | ||
|
||
What(是什么) | ||
--- | ||
|
||
为防止服务器端的资源被客户端的计算机程序滥用或攻击,服务器需要区分当前用户是计算机还是人类,一般在网站的关键操作位置都会采用验证码技术来区分。 | ||
|
||
全自动区分计算机和人类的图灵测试(Completely Automated Public Turing test to tell Computers and Humans Apart,简称CAPTCHA),俗称验证码,是一种区分用户是计算机或人的全自动化程序。 | ||
|
||
Why(为什么要做) | ||
--- | ||
|
||
不做会有什么后果吗? | ||
|
||
How(如何实现) | ||
--- | ||
|
||
Where(什么时候使用) | ||
--- | ||
|
||
- 登录接口 | ||
- 注册接口 | ||
- 频繁访问时被限制 | ||
- ip被限制 | ||
- 怀疑为机器人(如谷歌) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Security Auth App | ||
=== | ||
|
||
模块介绍 | ||
--- | ||
认证流程 | ||
|
||
特征 | ||
--- | ||
|
||
app端没有cookie,因而不是使用cookie和session,使用token进行验证。 | ||
|
||
功能 | ||
--- | ||
|
||
- [ ] remember me | ||
|
||
Token方案 | ||
--- | ||
|
||
保存 | ||
|
||
如何使用 | ||
--- | ||
|
||
### 获取token/刷新token | ||
|
||
可选择启动设置 | ||
|
||
开放可配置类 |
21 changes: 21 additions & 0 deletions
21
...uth-app/src/main/java/io/github/donespeak/springsecuritykit/app/EnableSecurityKitApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.github.donespeak.springsecuritykit.app; | ||
|
||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Import; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* @author Yang Guanrong | ||
* @date 2020/02/04 09:47 | ||
*/ | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@ComponentScan(basePackageClasses = {EnableSecurityKitApp.class}) | ||
public @interface EnableSecurityKitApp { | ||
} |
37 changes: 37 additions & 0 deletions
37
...ithub/donespeak/springsecuritykit/app/authentication/KitAuthenticationFailureHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.github.donespeak.springsecuritykit.app.authentication; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.github.donespeak.springsecuritykit.core.support.ApiError; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author Yang Guanrong | ||
* @date 2020/02/04 00:45 | ||
*/ | ||
@Component("kitAuthenticationFailureHandler") | ||
public class KitAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Override | ||
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, | ||
AuthenticationException exception) throws IOException, ServletException { | ||
|
||
ApiError apiError = new ApiError("" + HttpStatus.UNAUTHORIZED.value(), exception.getMessage()); | ||
|
||
response.setStatus(HttpStatus.UNAUTHORIZED.value()); | ||
response.setContentType("application/json;charset=UTF-8"); | ||
response.getWriter().write(objectMapper.writeValueAsString(apiError)); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ithub/donespeak/springsecuritykit/app/authentication/KitAuthenticationSuccessHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.donespeak.springsecuritykit.app.authentication; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* 浏览器环境下登录成功的处理器 | ||
* | ||
* @author zhailiang | ||
*/ | ||
@Component("kitAuthenticationSuccessHandler") | ||
public class KitAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { | ||
|
||
private Logger log = LoggerFactory.getLogger(getClass()); | ||
|
||
@Override | ||
public void onAuthenticationSuccess(HttpServletRequest request, javax.servlet.http.HttpServletResponse response, | ||
Authentication authentication) throws ServletException, IOException { | ||
super.onAuthenticationSuccess(request, response, authentication); | ||
} | ||
} |
Oops, something went wrong.