-
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
39f6472
commit d05abe0
Showing
28 changed files
with
799 additions
and
126 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
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
30 changes: 30 additions & 0 deletions
30
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,30 @@ | ||
package io.quarkus.oidc; | ||
|
||
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, | ||
OidcContext<Void> 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, | ||
OidcContext<TokenIntrospection> requestContext); | ||
} |
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
31 changes: 31 additions & 0 deletions
31
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,31 @@ | ||
package io.quarkus.oidc; | ||
|
||
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, OidcContext<Void> 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, OidcContext<UserInfo> requestContext); | ||
} |
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.