Skip to content

Commit 6758208

Browse files
joshbaskarankjellp
authored andcommitted
feat: set up config for oauth resource server with custom jwt decoder
1 parent 574c6cc commit 6758208

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

services/localega-tsd-proxy/src/main/java/no/elixir/fega/ltp/LocalEGATSDProxyApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
8181
.authenticated()
8282
.requestMatchers("/user")
8383
.authenticated())
84+
.oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults()))
8485
.oauth2Login(
8586
auth ->
8687
auth.redirectionEndpoint(endpoint -> endpoint.baseUri("/oidc-protected"))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package no.elixir.fega.ltp.config;
2+
3+
import com.github.benmanes.caffeine.cache.Caffeine;
4+
import java.util.concurrent.TimeUnit;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.cache.Cache;
7+
import org.springframework.cache.caffeine.CaffeineCache;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
import org.springframework.security.oauth2.jwt.JwtDecoder;
11+
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
12+
13+
@Configuration
14+
public class JwtDecoderConfig {
15+
16+
@Bean
17+
public JwtDecoder jwtDecoder(@Value("${aai.service-base-url}") String aaiBase) {
18+
19+
com.github.benmanes.caffeine.cache.Cache<Object, Object> nativeCache =
20+
Caffeine.newBuilder().expireAfterWrite(60, TimeUnit.MINUTES).maximumSize(100).build();
21+
22+
Cache jwkCache = new CaffeineCache("jwkCache", nativeCache);
23+
24+
return NimbusJwtDecoder.withJwkSetUri(aaiBase + "/oidc/jwk").cache(jwkCache).build();
25+
}
26+
}

0 commit comments

Comments
 (0)