maven 引入:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
@EnableWebFluxSecurity
public class WebSecurityConfig {
@Bean
SecurityWebFilterChainwebFluxSecurityFilterChain(ServerHttpSecurity http)throws Exception {
http.authorizeExchange().pathMatchers(“/monitor/**”).hasRole("ADMIN")
.anyExchange().permitAll().and().cors().and()
.httpBasic().and()
.csrf().disable();
return http.build();
}
}
配置文件
management.endpoints.web.exposure.include=*
management.endpoints.web.base-path=/monitor
spring.security.user.name=mhuang
spring.security.user.password=huangmiao
spring.security.user.roles=ADMIN
实例:
、
网友评论