Skip to content

Commit

Permalink
browser基本认证配置完成
Browse files Browse the repository at this point in the history
  • Loading branch information
guanrongYang committed Apr 5, 2020
1 parent 1c272f5 commit f10db91
Show file tree
Hide file tree
Showing 99 changed files with 2,850 additions and 249 deletions.
4 changes: 4 additions & 0 deletions PLAN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
开发计划
===

-
15 changes: 14 additions & 1 deletion README.md
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
```
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Introduction

4 changes: 4 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Summary

* [Introduction](README.md)

1 change: 1 addition & 0 deletions docs/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
用户id的获取
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.
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.
425 changes: 425 additions & 0 deletions docs/authentication/authentication-flow.md

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions docs/authentication/login-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
登录方式
===

username/email/phone + password
---

phone + smscode
---

social account
---

### weixin

### qq

### google
3 changes: 3 additions & 0 deletions docs/authentication/remember-me-and-anonymous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Remember Me 和 Anonymous
===

6 changes: 6 additions & 0 deletions docs/authentication/remember-me.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Remember Me
===

实现原理

cookie
15 changes: 15 additions & 0 deletions docs/authentication/success-failure-handler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

## 认证失败/成功的结果handler

## 授权失败的handler

## 拓展

### @ControllerAdvice 在过滤器链的位置

### 获取公共对象的方法

TODO
---

- 排插的口(策略模式)
31 changes: 31 additions & 0 deletions docs/authorize/OAuth2.md
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
```
8 changes: 8 additions & 0 deletions docs/more-security/more-security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
更多安全认证
===

ip访问限制
---

限制频繁操作
---
Empty file added docs/social/Socail-QQ.md
Empty file.
Empty file added docs/social/Social-Google.md
Empty file.
Empty file added docs/social/Social-Weixin.md
Empty file.
Empty file added docs/social/Social.md
Empty file.
37 changes: 37 additions & 0 deletions docs/spring-security/spring-security-filter-chain.md
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
- [ ] 一个前台成功之后,是否还会经过其他前台的处理
10 changes: 10 additions & 0 deletions docs/verification-code/more-for-verification-code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
验证码的更多实现
---

### 防止获取验证码接口被恶意攻击

### 异常ip要求输入验证码

### 待解决问题

如果过于频繁的去刷
14 changes: 14 additions & 0 deletions docs/verification-code/validation-code-solution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
验证码实现
===

### 图片验证码

### 短信验证码

### 文字验证码

### 拼图验证码

### 他山之石

大疆的验证码方案
26 changes: 26 additions & 0 deletions docs/verification-code/web-verification-code.md
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被限制
- 怀疑为机器人(如谷歌)
30 changes: 30 additions & 0 deletions security-auth-app/README.md
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

可选择启动设置

开放可配置类
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 {
}
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));
}
}
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);
}
}
Loading

0 comments on commit f10db91

Please sign in to comment.