Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add EL support for the cache resource field #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>io.gravitee.policy</groupId>
<artifactId>gravitee-policy-oauth2</artifactId>
<version>3.0.4</version>
<version>3.0.5</version>

<name>Gravitee.io APIM - Policy - OAuth2</name>
<description>Check access token validity during request processing using token introspection</description>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/io/gravitee/policy/oauth2/Oauth2Policy.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,10 @@ private Cache getPolicyTokenIntrospectionCache(HttpExecutionContext ctx) {
if (oAuth2PolicyConfiguration.getOauthCacheResource() != null) {
CacheResource cacheResource = ctx
.getComponent(ResourceManager.class)
.getResource(oAuth2PolicyConfiguration.getOauthCacheResource(), CacheResource.class);
.getResource(
ctx.getTemplateEngine().getValue(oAuth2PolicyConfiguration.getOauthCacheResource(), String.class),
CacheResource.class
);
if (cacheResource != null) {
return cacheResource.getCache(ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ public void onRequest(Request request, Response response, ExecutionContext execu
// Set access_token in context
executionContext.setAttribute(CONTEXT_ATTRIBUTE_OAUTH_ACCESS_TOKEN, accessToken);

if (oAuth2PolicyConfiguration.getOauthCacheResource() != null) {
oAuth2PolicyConfiguration.setOauthCacheResource(
executionContext.getTemplateEngine().getValue(oAuth2PolicyConfiguration.getOauthCacheResource(), String.class)
);
}

CacheResource<?> cacheResource = executionContext
.getComponent(ResourceManager.class)
.getResource(oAuth2PolicyConfiguration.getOauthCacheResource(), CacheResource.class);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/schemas/schema-form.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"oauthCacheResource": {
"title": "Cache resource",
"description": "Cache resource used to store the tokens.",
"description": "Cache resource used to store the tokens. Supports EL.",
"type": "string",
"x-schema-form": {
"event": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ void shouldPutIntrospectionToCache() throws IOException {

private void prepareCacheResource() {
when(configuration.getOauthCacheResource()).thenReturn(OAUTH_CACHE_RESOURCE);
when(templateEngine.getValue(OAUTH_CACHE_RESOURCE, String.class)).thenReturn(OAUTH_CACHE_RESOURCE);
when(cacheResource.getCache(any(HttpExecutionContext.class))).thenReturn(cache);
when(resourceManager.getResource(OAUTH_CACHE_RESOURCE, CacheResource.class)).thenReturn(cacheResource);
}
Expand Down