refactor(ext-oidc): replace auth modules with security extensions
This commit is contained in:
@@ -36,7 +36,7 @@ FlashApp.create(8080)
|
||||
// With custom resolvers
|
||||
LimiterConfig conf = new LimiterConfig()
|
||||
.registerResolver("auth_user", req ->
|
||||
ClaimsHolder.exists() ? ClaimsHolder.user().sub() : "anonymous");
|
||||
SecurityIdentity.current() != null ? SecurityIdentity.current().principal().name() : "anonymous");
|
||||
|
||||
FlashApp.create(8080)
|
||||
.install(new LimiterExtension(conf))
|
||||
|
||||
@@ -35,11 +35,11 @@ conf.registerResolver("ip", req -> {
|
||||
LimiterConfig conf = new LimiterConfig();
|
||||
```
|
||||
|
||||
### By authenticated user (OIDC / ClaimsHolder)
|
||||
### By authenticated user
|
||||
|
||||
```java
|
||||
conf.registerResolver("auth_user", req ->
|
||||
ClaimsHolder.exists() ? ClaimsHolder.user().sub() : "anonymous");
|
||||
SecurityIdentity.current() != null ? SecurityIdentity.current().principal().name() : "anonymous");
|
||||
```
|
||||
|
||||
Requests from unauthenticated users share the `"anonymous"` bucket. If you want
|
||||
@@ -88,7 +88,7 @@ returns the same key for the same user regardless of endpoint; the limit is set
|
||||
|
||||
```java
|
||||
conf.registerResolver("auth_user", req ->
|
||||
ClaimsHolder.exists() ? ClaimsHolder.user().sub() : "anon");
|
||||
SecurityIdentity.current() != null ? SecurityIdentity.current().principal().name() : "anon");
|
||||
```
|
||||
|
||||
```java
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ import dev.relism.flash.models.Request;
|
||||
*
|
||||
* <pre>{@code
|
||||
* conf.registerResolver("ip", req -> req.header("X-Forwarded-For"));
|
||||
* conf.registerResolver("auth_user", req -> ClaimsHolder.user().sub());
|
||||
* conf.registerResolver("auth_user", req -> SecurityIdentity.current().principal().name());
|
||||
* }</pre>
|
||||
*/
|
||||
@FunctionalInterface
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ import java.util.Map;
|
||||
* <pre>{@code
|
||||
* LimiterConfig conf = new LimiterConfig()
|
||||
* .registerResolver("auth_user", req -> {
|
||||
* // custom logic — e.g. extract sub from ClaimsHolder
|
||||
* return ClaimsHolder.exists() ? ClaimsHolder.user().sub() : "anonymous";
|
||||
* // custom logic — e.g. key by the authenticated caller
|
||||
* return SecurityIdentity.current() != null ? SecurityIdentity.current().principal().name() : "anonymous";
|
||||
* });
|
||||
*
|
||||
* app.install(new LimiterExtension(conf));
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ import java.util.Map;
|
||||
* <h3>Lambda routes (via Guard)</h3>
|
||||
* <pre>{@code
|
||||
* app.install(new LimiterExtension(
|
||||
* new LimiterConfig().registerResolver("auth_user", req -> ClaimsHolder.user().sub())));
|
||||
* new LimiterConfig().registerResolver("auth_user", req -> SecurityIdentity.current().principal().name())));
|
||||
*
|
||||
* // inside a FlashContext.onReady(...) callback:
|
||||
* Guard guard = ctx.require(Guard.class);
|
||||
|
||||
Reference in New Issue
Block a user