美文网首页
2019-06-15 注册中心添加security客户端注册不

2019-06-15 注册中心添加security客户端注册不

作者: 李逍遥_416b | 来源:发表于2019-06-15 14:59 被阅读0次

    eureka服务端添加security验证之后,client注册失败 cannot execute any request on any know server

    原帖地址 : https://www.oschina.net/question/3688227_2275113 

    方法:需要在eureka的注册中心自己实现一个类开启basic认证

    package com.lhj.eureka.config;

    import org.springframework.context.annotation.Configuration;

    import org.springframework.security.config.annotation.web.builders.HttpSecurity;

    import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;

    import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

    import org.springframework.security.config.http.SessionCreationPolicy;

    @Configuration

    @EnableWebSecurity

    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

        /**

        * @Description: 高版本的丢弃了

        * security:

    *  basic:

        *    enabled: true 配置,应该使用以下方式开启

        * @Param: [http]

        * @Return: void

    */

        @Override

        protected void configure(HttpSecurity http) throws Exception {

            // Configure HttpSecurity as needed (e.g. enable http basic).

            http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);

            http.csrf().disable();

            //注意:为了可以使用 http://${user}:${password}@${host}:${port}/eureka/ 这种方式登录,所以必须是httpBasic,

            // 如果是form方式,不能使用url格式登录

            http.authorizeRequests().anyRequest().authenticated().and().httpBasic();

        }

    }

    相关文章

      网友评论

          本文标题:2019-06-15 注册中心添加security客户端注册不

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