Skip to content

Commit

Permalink
Added autoconfiguration for a ReactiveJwtDecoder used for tests, to a…
Browse files Browse the repository at this point in the history
…void boilerplate mocks.
  • Loading branch information
rfc3092 committed Jan 14, 2025
1 parent bc53990 commit c9adfb8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package no.nav.testnav.libs.reactivesecurity.jwt;

import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.oauth2.jwt.JwtException;
import org.springframework.security.oauth2.jwt.ReactiveJwtDecoder;
import reactor.core.publisher.Mono;

class NoopReactiveJwtDecoder implements ReactiveJwtDecoder {

@Override
public Mono<Jwt> decode(String token) throws JwtException {
return Mono.just(Jwt.withTokenValue(null).build());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package no.nav.testnav.libs.reactivesecurity.jwt;

import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.security.oauth2.jwt.ReactiveJwtDecoder;

@AutoConfiguration
public class ReactiveJwtAutoConfiguration {

@Primary
@Bean
@Profile("test")
@ConditionalOnBean(ReactiveJwtDecoder.class)
ReactiveJwtDecoder reactiveJwtDecoderForTesting() {
return new NoopReactiveJwtDecoder();
}

}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
no.nav.testnav.libs.reactivesecurity.exchange.TokenServiceAutoConfiguration
no.nav.testnav.libs.reactivesecurity.exchange.TokenServiceAutoConfiguration
no.nav.testnav.libs.reactivesecurity.jwt.ReactiveJwtAutoConfiguration

0 comments on commit c9adfb8

Please sign in to comment.