Annotation Interface WithOpaqueToken


@Target({METHOD,TYPE}) @Retention(RUNTIME) @Inherited @Documented @WithSecurityContext(factory=AuthenticationFactory.class) public @interface WithOpaqueToken
Annotation to setup test SecurityContext with an Authentication instantiated by the (Reactive)OpaqueTokenAuthenticationConverter in the security conf. Usage on tests decorated with @AutoConfigureAddonsSecurity or @AutoConfigureAddonsWebSecurity::
 @Test
 @WithOpaqueToken("ch4mp_auth0.json")
 public void test() {
     ...
 }
 
For usage with @ParameterizedTest, you'll need a @MethodSource in a test running with @TestInstance(Lifecycle.PER_CLASS). Authentication instance should be injected in the test with @ParameterizedAuthentication.
 @Autowired
 WithOpaqueToken.AuthenticationFactory authFactory;

 @ParameterizedTest
 @MethodSource("authSource")
 void givenUserIsPersona_whenGetGreet_thenReturnsGreeting(@ParameterizedAuthentication Authentication auth) {
     ...
 }

 Stream<AbstractAuthenticationToken> authSource() {
     return authFactory.authenticationsFrom("ch4mp.json", "tonton-pirate.json");
 }
 
If using spring-addons-oauth2-test without spring-addons-starter-oidc-test, you should explicitly import @Import(AuthenticationFactoriesTestConf.class) (otherwise, the @Addons...Test will pull this configuration for you)
Author:
Jérôme Wacongne <ch4mp@c4-soft.com>
  • Element Details

    • value

      @AliasFor("file") String value
      Default:
      ""
    • file

      @AliasFor("value") String file
      Default:
      ""
    • json

      String json
      Default:
      ""
    • bearerString

      String bearerString
      Default:
      "test.jwt.bearer"