Method security

To enable method security, first, annotate the Spring Security configurations class with @EnableReactiveMethodSecurity:

@EnableReactiveMethodSecurity
public class SpringSecurityWebFluxConfig {

}

After that, for any method that you would like to have some security features for, use all of the various security-related annotations discussed in previous chapters:

@GetMapping("/movies")
@PreAuthorize("hasRole('ADMIN')")
public Flux<Movie> getAllMovies() {
return reactiveMovieRepository.findAll();
}

In the preceding method, we are directing Spring Security that the method execution for getAllMovies() should be allowed if the user is authenticated and has the ADMIN role granted.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.50.183