Add documentation for authentication webfilter extension points (#320)

* Add documentation for authentication webfilter extension points

* Refine requirements of extension point definition
wan92hen-patch-1
John Niang 9 months ago committed by GitHub
parent 276bbb729a
commit 08ebdfc95f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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 留下机会。
后续会根据需求实现其他认证相关的扩展点。

@ -49,9 +49,9 @@ spec:
``` ```
:::tip Note :::tip Note
每一个扩展点都会声明一个对应的 `ExtensionPointDefinition` 自定义模型对象被称之为扩展点定义,用于描述该扩展点的信息,例如:扩展点的名称、描述、扩展点的类型等。 单实例或多实例的扩展点需要声明对应的 `ExtensionPointDefinition` 自定义模型对象被称之为扩展点定义,用于描述该扩展点的信息,例如:扩展点的名称、描述、扩展点的类型等。
而每一个扩展也必须声明一个对应的 `ExtensionDefinition` 自定义模型对象被称之为扩展定义,用于描述该扩展的信息,例如:扩展的名称、描述、对应扩展点的对象名称等。 单实例或多实例扩展点的实现也必须声明一个对应的 `ExtensionDefinition` 自定义模型对象被称之为扩展定义,用于描述该扩展的信息,例如:扩展的名称、描述、对应扩展点的对象名称等。
::: :::
关于如何在插件中声明自定义模型对象请参考:[自定义模型](../../server/extension.md#declare-extension-object) 关于如何在插件中声明自定义模型对象请参考:[自定义模型](../../server/extension.md#declare-extension-object)

@ -181,6 +181,7 @@ module.exports = {
}, },
items: [ items: [
"developer-guide/plugin/api-reference/server/extension-points/additional-webfilter", "developer-guide/plugin/api-reference/server/extension-points/additional-webfilter",
"developer-guide/plugin/api-reference/server/extension-points/authentication-webfilter",
"developer-guide/plugin/api-reference/server/extension-points/attachment", "developer-guide/plugin/api-reference/server/extension-points/attachment",
"developer-guide/plugin/api-reference/server/extension-points/comment-subject", "developer-guide/plugin/api-reference/server/extension-points/comment-subject",
"developer-guide/plugin/api-reference/server/extension-points/comment-widget", "developer-guide/plugin/api-reference/server/extension-points/comment-widget",

Loading…
Cancel
Save