Skip to content

Commit

Permalink
feat: Add EL support for the cache resource field
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksii-bielik committed Apr 23, 2024
1 parent 3f0d056 commit 6aceaa8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
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

0 comments on commit 6aceaa8

Please sign in to comment.