Spring Security does not allow anonymous (anonymous) access to the Post interface (403)

Problem background: The system exposes the interface to the outside world, the interface path is configured with anonymous access (anonymous), the Get request can be accessed normally, and the Post request reports an error 403 or directly jumps to the login page.

Solution: Turn off CSRF in SecurityConfig

httpSecurity.csrf().disable()

The above problem was solved, but a new problem appeared when the front end called.

Problem background: The front end transfers the token to call the anonymous interface, and reports an error 403, but it can be accessed normally without passing the token.

Reason: anonymous allows anonymous access, passing the token is not anonymous, so it cannot be accessed.

Solution: Change anonymous to permitAll.

Final configuration:

The configurable permission types of Spring Security are attached, as follows:

Guess you like

Origin blog.csdn.net/secretdaixin/article/details/128955214