美文网首页
spring-cloud-gateway 集成 security

spring-cloud-gateway 集成 security

作者: 一叶之秋_f4b7 | 来源:发表于2019-01-03 14:05 被阅读0次

    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

    实例:

    相关文章

      网友评论

          本文标题:spring-cloud-gateway 集成 security

          本文链接:https://www.haomeiwen.com/subject/onufrqtx.html