java.lang.ClassNotFoundException: o.s.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter received when using o.s.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt() in the @SpringBootTest @AutoConfigureMockMvc tests.

Manual fix As is, a spring-boot-starter-oauth2-authorization-server test dependency has to be added to the project separately.

Expected behavior Since SecurityMockMvcRequestPostProcessors.jwt() comes from spring-security-test package the expected behavior would be for it to come with all the dependencies required to use it. Or at least to declare spring-boot-starter-oauth2-authorization-server as its optional dependency.

Sample Bug Demo To see the bug run ./mvnw test. To see success run ./mvnw test -P fixed. The fixed profile adds the missing dependency explicitly.

Comment From: Imrnkhan

Check Dependencies and add some dependencies and update project this way

org.springframework.security spring-security-test test

Comment From: Imrnkhan

org.springframework.security spring-security-test test

Comment From: marcusdacoregio

Hi, @voy13k. The spring-security-test provides some utility classes and methods that can be used to test our application. The SecurityMockMvcRequestPostProcessors#jwt() expects that you are using the Spring Security OAuth 2.0 Resource Server support, therefore, you need the spring-security-oauth2-resource-server dependency.

That behavior is expected because spring-security-test won't bring all the dependencies for you if, for example, you just want to use @WithMockUser.

Comment From: voy13k

Hi, @voy13k. The spring-security-test provides some utility classes and methods that can be used to test our application. The SecurityMockMvcRequestPostProcessors#jwt() expects that you are using the Spring Security OAuth 2.0 Resource Server support, therefore, you need the spring-security-oauth2-resource-server dependency.

That behavior is expected because spring-security-test won't bring all the dependencies for you if, for example, you just want to use @WithMockUser.

Whay not add such dependencies to spring-security-test POM as optional then? It was done in the gradle, why not maven? Would have saved me and countless others some headaches trying to search the internet.

Comment From: voy13k

org.springframework.security spring-security-test test

Your suggestion doesn't work. Please read the full report.