zoukankan      html  css  js  c++  java
  • eureka开启用户认证

    eureka Server未开启用户认证前,是匿名访问的,这样的话存在一定的安全性问题。因此将项目改成通过认证才能正常使用

    第一步 ,在eureka server项目的pom.xml文件添加Spring-Security依赖

    1 <dependency>
    2       <groupId>org.springframework.boot</groupId>
    3       <artifactId>spring-boot-starter-security</artifactId>
    4 </dependency>

    第二步,在application.yml文件中设置eureka server的用户名和密码

    1 spring:
    2   security:
    3     user:
    4       name: test
    5       password: 123456

    第三步 为了不改变原来eueka.client.service-url访问方式,需要使用httpBasic方式,增加Security 配置类:

     1 package com.ssc.eureka_server;
     2 
     3 import org.springframework.context.annotation.Configuration;
     4 import org.springframework.security.config.annotation.web.builders.HttpSecurity;
     5 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
     6 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
     7 
     8 @Configuration
     9 @EnableWebSecurity
    10 public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    11     @Override
    12     protected void configure(HttpSecurity http) throws Exception {
    13         // 关闭csrf
    14         http.csrf().disable();
    15         // 支持httpBasic
    16         http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
    17     }
    18 }

     第四步 启动服务,访问eureka server,需要输入正确的用户名和密码

     第五步  eureka client端的 eureka.client.service-url.default的值应该为 http://  用户名:密码@EUREKA_HOST:EUREKA_PORT/eureka

             

    gitee地址 : https://gitee.com/RookieIsMine/eureka_server_security

    生于忧患,死于安乐
  • 相关阅读:
    linux Centos防火墙工具iptables的使用
    SpringBoot中的注解分析
    context:property-placeholder
    HTTPS(SSL)证书下载及配置
    Dubbo之多注册中心以及zookepeer服务的查看
    重要事情老是忘?别急~看这里
    重要事情老是忘?别急~看这里
    多态
    抽象类,接口_05
    常用类
  • 原文地址:https://www.cnblogs.com/songlove/p/14803645.html
Copyright © 2011-2022 走看看