File tree Expand file tree Collapse file tree
spring-5-reactive/src/main/java/com/baeldung/reactive/security Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .baeldung .reactive .security ;
22
3+ import org .springframework .boot .actuate .autoconfigure .security .reactive .EndpointRequest ;
34import org .springframework .context .annotation .Bean ;
45import org .springframework .security .config .annotation .method .configuration .EnableReactiveMethodSecurity ;
56import org .springframework .security .config .annotation .web .reactive .EnableWebFluxSecurity ;
910import org .springframework .security .core .userdetails .UserDetails ;
1011import org .springframework .security .web .server .SecurityWebFilterChain ;
1112
13+ import com .baeldung .reactive .actuator .FeaturesEndpoint ;
14+
1215@ EnableWebFluxSecurity
1316@ EnableReactiveMethodSecurity
1417public class SecurityConfig {
1518
1619 @ Bean
1720 public SecurityWebFilterChain securitygWebFilterChain (ServerHttpSecurity http ) {
1821 return http .authorizeExchange ()
19- .pathMatchers ("/admin" ).hasAuthority ("ROLE_ADMIN" )
20- .anyExchange ().permitAll ()
21- .and ().formLogin ()
22- .and ().build ();
22+ .pathMatchers ("/admin" )
23+ .hasAuthority ("ROLE_ADMIN" )
24+ .matchers (EndpointRequest .to (FeaturesEndpoint .class ))
25+ .permitAll ()
26+ .anyExchange ()
27+ .permitAll ()
28+ .and ()
29+ .formLogin ()
30+ .and ()
31+ .csrf ()
32+ .disable ()
33+ .build ();
2334 }
2435
2536 @ Bean
2637 public MapReactiveUserDetailsService userDetailsService () {
2738 UserDetails user = User .withDefaultPasswordEncoder ()
28- .username ("user" )
29- .password ("password" )
30- .roles ("USER" )
31- .build ();
39+ .username ("user" )
40+ .password ("password" )
41+ .roles ("USER" )
42+ .build ();
3243
3344 UserDetails admin = User .withDefaultPasswordEncoder ()
34- .username ("admin" )
35- .password ("password" )
36- .roles ("ADMIN" )
37- .build ();
45+ .username ("admin" )
46+ .password ("password" )
47+ .roles ("ADMIN" )
48+ .build ();
3849
3950 return new MapReactiveUserDetailsService (user , admin );
4051 }
You can’t perform that action at this time.
0 commit comments