-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for TokenIntrospection and UserInfo cache
- Loading branch information
1 parent
377c56c
commit b94641b
Showing
25 changed files
with
812 additions
and
127 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
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
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
57 changes: 57 additions & 0 deletions
57
extensions/oidc/runtime/src/main/java/io/quarkus/oidc/TokenIntrospectionCache.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,57 @@ | ||
package io.quarkus.oidc; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
/** | ||
* Token introspection cache. | ||
*/ | ||
public interface TokenIntrospectionCache { | ||
|
||
/** | ||
* Add a new {@link TokenIntrospection} result to the cache. | ||
* | ||
* @param token the token which has been introspected | ||
* @param introspection the token introspection result | ||
* @param oidcConfig the tenant configuration | ||
* @param requestContext the request context which can be used to run the blocking tasks | ||
*/ | ||
Uni<Void> addIntrospection(String token, TokenIntrospection introspection, OidcTenantConfig oidcConfig, | ||
AddIntrospectionRequestContext requestContext); | ||
|
||
/** | ||
* Get the cached {@link TokenIntrospection} result. | ||
* | ||
* @param token the token which has to be introspected | ||
* @param oidcConfig the tenant configuration | ||
* @param requestContext the request context which can be used to run the blocking tasks | ||
*/ | ||
Uni<TokenIntrospection> getIntrospection(String token, OidcTenantConfig oidcConfig, | ||
GetIntrospectionRequestContext requestContext); | ||
|
||
/** | ||
* A context object that can be used to add a new token introspection result by running a blocking task. | ||
* <p> | ||
* Blocking {@code TokenIntrospectionCache} providers should use this context object to run blocking tasks, to prevent | ||
* excessive and unnecessary delegation to thread pools. | ||
*/ | ||
interface AddIntrospectionRequestContext { | ||
|
||
Uni<Void> runBlocking(Supplier<Void> function); | ||
|
||
} | ||
|
||
/** | ||
* A context object that can be used to get the existing token introspection result by running a blocking task. | ||
* <p> | ||
* Blocking {@code TokenIntrospectionCache} providers should use this context object to run blocking tasks, to prevent | ||
* excessive and unnecessary delegation to thread pools. | ||
*/ | ||
interface GetIntrospectionRequestContext { | ||
|
||
Uni<TokenIntrospection> runBlocking(Supplier<TokenIntrospection> function); | ||
|
||
} | ||
|
||
} |
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
60 changes: 60 additions & 0 deletions
60
extensions/oidc/runtime/src/main/java/io/quarkus/oidc/UserInfoCache.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,60 @@ | ||
package io.quarkus.oidc; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
/** | ||
* UserInfo cache. | ||
*/ | ||
public interface UserInfoCache { | ||
|
||
/** | ||
* Add a new {@link UserInfo} to the cache. | ||
* | ||
* @param token the token which was used to get {@link UserInfo} | ||
* @param userInfo {@link UserInfo} | ||
* @param oidcConfig the tenant configuration | ||
* @param requestContext the request context which can be used to run the blocking tasks | ||
*/ | ||
Uni<Void> addUserInfo(String token, UserInfo userInfo, OidcTenantConfig oidcConfig, | ||
AddUserInfoRequestContext requestContext); | ||
|
||
/** | ||
* Get the cached {@link UserInfo}. | ||
* | ||
* @param token the token which will be used to get new {@link UserInfo} if no {@link UserInfo} is cached. | ||
* Effectively this token is a cache key which has to be stored when | ||
* {@link #addUserInfo(String, UserInfo, OidcTenantConfig, AddUserInfoRequestContext)} | ||
* is called. | ||
* @param oidcConfig the tenant configuration | ||
* @param requestContext the request context which can be used to run the blocking tasks | ||
*/ | ||
Uni<UserInfo> getUserInfo(String token, OidcTenantConfig oidcConfig, | ||
GetUserInfoRequestContext requestContext); | ||
|
||
/** | ||
* A context object that can be used to add a new @{link UserInfo} by running a blocking task. | ||
* <p> | ||
* Blocking {@code UserInfoCache} providers should use this context object to run blocking tasks, to prevent | ||
* excessive and unnecessary delegation to thread pools. | ||
*/ | ||
interface AddUserInfoRequestContext { | ||
|
||
Uni<Void> runBlocking(Supplier<Void> function); | ||
|
||
} | ||
|
||
/** | ||
* A context object that can be used to get the existing token introspection result by running a blocking task. | ||
* <p> | ||
* Blocking {@code TokenIntrospectionCache} providers should use this context object to run blocking tasks, to prevent | ||
* excessive and unnecessary delegation to thread pools. | ||
*/ | ||
interface GetUserInfoRequestContext { | ||
|
||
Uni<UserInfo> runBlocking(Supplier<UserInfo> function); | ||
|
||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...nsions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/AbstractBlockingTaskRunner.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,42 @@ | ||
package io.quarkus.oidc.runtime; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import io.quarkus.runtime.BlockingOperationControl; | ||
import io.quarkus.runtime.ExecutorRecorder; | ||
import io.smallrye.mutiny.Uni; | ||
import io.smallrye.mutiny.subscription.UniEmitter; | ||
|
||
public abstract class AbstractBlockingTaskRunner<T> { | ||
public Uni<T> runBlocking(Supplier<T> function) { | ||
return Uni.createFrom().deferred(new Supplier<Uni<? extends T>>() { | ||
@Override | ||
public Uni<T> get() { | ||
if (BlockingOperationControl.isBlockingAllowed()) { | ||
try { | ||
return Uni.createFrom().item(function.get()); | ||
} catch (Throwable t) { | ||
return Uni.createFrom().failure(t); | ||
} | ||
} else { | ||
return Uni.createFrom().emitter(new Consumer<UniEmitter<? super T>>() { | ||
@Override | ||
public void accept(UniEmitter<? super T> uniEmitter) { | ||
ExecutorRecorder.getCurrent().execute(new Runnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
uniEmitter.complete(function.get()); | ||
} catch (Throwable t) { | ||
uniEmitter.fail(t); | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.