Giter Site home page Giter Site logo

@WebMvcTest and WebSecurity with @EnableMethodSecurity not looking for @PreAuthorize annotation in the interface about spring-boot HOT 4 CLOSED

alexisgayte avatar alexisgayte commented on June 16, 2024
@WebMvcTest and WebSecurity with @EnableMethodSecurity not looking for @PreAuthorize annotation in the interface

from spring-boot.

Comments (4)

wilkinsona avatar wilkinsona commented on June 16, 2024 1

Thanks for the sample. It allowed me to determine that this is a duplicate of #33415. You can work around it by importing AOP auto-configuration:

@Import(SecurityConfig.class)
@WebMvcTest(value = HelloController.class)
@ImportAutoConfiguration(AopAutoConfiguration.class)
class HelloControllerTest {

from spring-boot.

wilkinsona avatar wilkinsona commented on June 16, 2024

Thanks for the report, but it's not clear to me why you have opened a Spring Boot issue. Spring Boot isn't involved with the discovery of the @PreAuthorize annotations. It's Spring Security that does that. Perhaps you're saying that the problem only occurs with @WebMvcTest and doesn't occur when running the application's main method or perhaps when using @SpringBootTest? If that's the case and you would like us to investigate, please provide a complete yet minimal sample that demonstrates these differences in behaviour. If that's not the case, this should probably be a Spring Security issue as it sounds like it's out of Spring Boot's control.

from spring-boot.

alexisgayte avatar alexisgayte commented on June 16, 2024

Yes that is the case it is linked to @WebMvcTest I believe.
Everything works fine otherwise, the app itself is fine.

Here is the test repo : https://github.com/alexisgayte/spring-framework-30489/tree/main

I personally moved the interface into the controller that resolved my issue.
But that looks a bug. May be Spring Security but looks more on @WebMvcTest.

The test fail due to a 404. meaning spring can't find the mapping.

from spring-boot.

alexisgayte avatar alexisgayte commented on June 16, 2024

Thanks for your time.

from spring-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.