spring-cloud-gateway 集成 security 实现部分请求校验

maven 引入:


    org.springframework.cloud

    spring-cloud-starter-gateway


    org.springframework.boot

    spring-boot-starter-security

@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


实例:


spring-cloud-gateway 集成 security 实现部分请求校验_第1张图片

你可能感兴趣的:(spring-cloud-gateway 集成 security 实现部分请求校验)