Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation for authentication webfilter extension points (#320)
* Add documentation for authentication webfilter extension points * Refine requirements of extension point definition
- Loading branch information
Showing
3 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...-guide/plugin/api-reference/server/extension-points/authentication-webfilter.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,81 @@ | ||
--- | ||
title: 认证安全过滤器 | ||
description: 提供 Security WebFilter 扩展点,插件可实现自定义认证逻辑,例如:用户名密码认证,JWT 认证,匿名认证。 | ||
--- | ||
|
||
此前,Halo 提供了 AdditionalWebFilter 作为扩展点供插件扩展认证相关的功能。但是近期我们明确了 AdditionalWebFilter | ||
的使用用途,故不再作为认证的扩展点。 | ||
|
||
目前,Halo 提供了三种认证扩展点:表单登录认证、普通认证和匿名认证。 | ||
|
||
## 表单登录(FormLogin) | ||
|
||
示例如下: | ||
|
||
```java | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import org.springframework.web.server.WebFilterChain; | ||
import reactor.core.publisher.Mono; | ||
import run.halo.app.security.FormLoginSecurityWebFilter; | ||
|
||
@Component | ||
public class MyFormLoginSecurityWebFilter implements FormLoginSecurityWebFilter { | ||
|
||
@Override | ||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { | ||
// Do your logic here | ||
return chain.filter(exchange); | ||
} | ||
} | ||
|
||
``` | ||
|
||
## 普通认证(Authentication) | ||
|
||
示例如下: | ||
|
||
```java | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import org.springframework.web.server.WebFilterChain; | ||
import reactor.core.publisher.Mono; | ||
import run.halo.app.security.AuthenticationSecurityWebFilter; | ||
|
||
@Component | ||
public class MyAuthenticationSecurityWebFilter implements AuthenticationSecurityWebFilter { | ||
|
||
@Override | ||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { | ||
// Do your logic here | ||
return chain.filter(exchange); | ||
} | ||
} | ||
``` | ||
|
||
## 匿名认证(Anonymous Authentication) | ||
|
||
示例如下: | ||
|
||
```java | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import org.springframework.web.server.WebFilterChain; | ||
import reactor.core.publisher.Mono; | ||
import run.halo.app.security.AnonymousAuthenticationSecurityWebFilter; | ||
|
||
@Component | ||
public class MyAnonymousAuthenticationSecurityWebFilter | ||
implements AnonymousAuthenticationSecurityWebFilter { | ||
|
||
@Override | ||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { | ||
// Do your logic here | ||
return chain.filter(exchange); | ||
} | ||
} | ||
``` | ||
|
||
我们在实现扩展点的时候需要注意:如果当前请求不满足认证条件,请一定要调用 `chain.filter(exchange)`,给其他 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
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