Skip to content

Introduce JWT Flow API in Test Support #6634

Closed
@jzheaux

Description

@jzheaux

It would be handy in tests to be able to specify a Jwt authentication in tests:

this.mockMvc.perform(get("/")
        .with(jwt()))
        .andExcept(status().isOk());

Some features we should consider:

  • Providing a completely instantiated Jwt:
Jwt jwt = ...;
this.mockMvc.perform(get("/")
        .with(jwt(jwt)))
        ...
  • Providing authorities:
Jwt jwt = ...;
this.mockMvc.perform(get("/")
        .with(jwt(jwt).authorities("SCOPE_message:read"))
        ...
  • Providing claims:
this.mockMvc.perform(get("/")
        .with(jwt().claim(SUB, "the-subject")))
        ...
  • Providing headers:
this.mockMvc.perform(get("/")
        .with(jwt().header("alg", RS256)))
        ...

These would result in the SecurityContext containing an instance of JwtAuthenticationToken.

Also, we should introduce its reactive equivalent.

Metadata

Metadata

Assignees

Labels

in: testAn issue in spring-security-testtype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions