1. 程式人生 > >Spring Cloud (18) | 給Eureka Server加上安全驗證

Spring Cloud (18) | 給Eureka Server加上安全驗證

啟動Spring Cloud Eureka Server專案工程的時候,直接輸入localhost:8761,就可以看到所有註冊服務,這樣在生產環境是極不安全,如何解決這個問題呢?
首先,在eureka server專案中pom.xml檔案中加入依賴:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
</dependency>

然後,在application.yml中加入安全驗證,使用者名稱和密碼:
使用者名稱:jack.ma
密碼:1qaz2wsx

server: 
  port: 8761 

# 安全認證的配置  
security:  
  basic:  
    enabled: true  
  user:  
    name: jack.ma  # 使用者名稱  
    password: 1qaz2wsx   # 使用者密碼  
eureka:  
  client:  
    register-with-eureka: false  
    fetch-registry: false  
    service-url:  
      defaultZone: http://${security.user
.name}:${security.user.password}@${eureka.instance.hostname}:${server.port}/eureka/ # 安全的註冊地址

最後,在瀏覽器中輸入:http://localhost:8761, 就會彈出登入驗證視窗:
這裡寫圖片描述
輸入使用者名稱和密碼,回車之後,就可以看到服務註冊頁面!

註冊到Eureka Server的微服務中的defaultZone要改成如下:

eureka:
  client:
    serviceUrl:
      defaultZone: http://jack.ma:[email protected]
:8761/eureka/

更多系列文章推薦:

相關推薦

Spring Cloud (18) | Eureka Server加上安全驗證

啟動Spring Cloud Eureka Server專案工程的時候,直接輸入localhost:8761,就可以看到所有註冊服務,這樣在生產環境是極不安全,如何解決這個問題呢? 首先,在eureka server專案中pom.xml檔案中加入依賴:

spring cloud-Eureka Server加上安全的使用者認證詳解

前言 在前面的一篇文章中spring cloud中啟動Eureka Server 我們啟動了Eureka Server,然後在瀏覽器中輸入http://localhost:8761/後,直接回車,就進入了spring cloud的服務治理頁面,這麼做在生產環境是極不安全的,下面,我們就

微服務Spring Cloud實戰-編寫Eureka Server

編寫Eureka Server 1.建立一個ArtifactId是microservice-descovery-eureka的Maven工程,併為專案新增以下依賴。 並且在之前的專案內pom.xml新增 org.springframework.cloud spring-cl

idea中建立EurekaServer註冊中心和eureka client和Eureka Server加上安全的使用者認證

new -project 選擇spring initializr 建立自己的包名,類名。 這一步與建立springboot有區別,畫重點了,注意下面的兩個紅框框 專案名 在Application類上添加註解@EnableEurekaServer宣告註冊中心

Eureka Server 加上安全認證之後,服務無法註冊

接前幾篇 服務註冊中心加了安全認證之後,然後我執行eureka client 。。。發現。。。。 報錯了,註冊不了。。。後來才發現,註冊地址要改一下。。改成下面這樣: eureka:

spring-cloud中的eureka啟動出錯Cannot execute request on any known server

在使用springCloud中的eureka註冊中心的時候,啟動後報錯: There was a problem with the instance info replicator com.netflix.discovery.shared.transport.Transp

Spring Cloud 註冊中心Eureka

ont 允許 包括 enter 1.0 bbb oid pub try 一、簡介 最近在看Spring Cloud微服務,接下來的時間和大家一起分享我所看到的,公司現在用的是dubbo ,之後有時間也去了解了解dubbo的源碼。與dubbo相比較,Spring

Spring Cloud中,Eureka常見問題總結

rose cte registry 應該 per 端口 ict 使用配置 ipaddress Spring Cloud中,Eureka常見問題總結。 1 eureka.environment: 指定環境 參考文檔: 1 eureka.datacenter: 指定數據中心

Spring Cloud 入門教程 - Eureka服務註冊與發現

spring spring cloud spring cloud eureka spring boot 簡介 在微服務中,服務註冊與發現對管理各個微服務子系統起著關鍵作用。隨著系統水平擴展的越來越多,系統拆分為微服務的數量也會相應增加,那麽管理和獲取這些微服務的URL就會變得十分棘手,如果我們

微服務spring cloud實戰-脫離Eureka使用Ribbon

脫離Eureka使用Ribbon 1.複製專案microservice-consumer-movie-ribbon,將ArtifactId修改為microservice-consumer-movie-without-eureka。 2.為了讓測試更有說服力,乾脆讓專案去掉Eureka

Spring Cloud第一篇 Eureka簡介及原理

Eureka是Netflix開發的服務發現元件,本身是一個基於REST的服務。Spring Cloud將它整合在其子專案spring-cloud-netflix中,以實現Spring Cloud的服務發現功能。目前Eureka 專案相當活躍,程式碼更新相當頻繁,目前最新的版本是1.5.5

spring cloud (二、服務註冊安全demo_eureka)

        spring cloud (一、服務註冊demo_eureka)      加強服務的安全性,我們接下來加上訪問的賬號密碼;      首先需要新增對應的依賴  

Netflix Eureka原始碼分析(18)——eureka server網路故障時的的自我保護機制原始碼剖析

假如說,20個服務例項,結果在1分鐘之內,只有8個服務例項保持了心跳 --> eureka server是應該將剩餘的12個沒有心跳的服務例項都摘除嗎? 這個時候很可能說的是,eureka server自己網路故障了,那些服務沒問題的。只不過eureka server

【夯實Spring CloudSpring Cloud中的Eureka服務註冊與發現詳解

本文屬於【夯實Spring Cloud】系列文章,該系列旨在用通俗易懂的語言,帶大家瞭解和學習Spring Cloud技術,希望能給讀者帶來一些乾貨。系列目錄如下: 【夯實Spring Cloud】Dubbo沉睡5年,Spring Cloud開始崛起! 【夯實Spring C

Spring Cloud入門教程-Config Server從github 遠端讀取配置檔案

      接上一篇文章,這裡記錄一下Config Server從github 遠端讀取配置檔案。         Spring cloud Config支援從遠端Git倉庫讀取配置檔案,即 Config Server可以不從本地的倉庫讀取,而是從遠端Git倉庫讀取。這

走進Spring Cloud之三 eureka Producer(服務提供者)(Greenwich版本)

service-producer(eureka client) 前面我們已經成功的建立了叢集版的註冊中心,接下來我們就可以把我們的服務註冊到我們叢集註冊中心提供給消費者使用。 新建moudel(service-producer) pom.xml 修改pom.x

Spring-cloud微服務 Eureka學習教程-分散式搭建EurekaServer、EurekaClient(中級)

        我們這裡只有一臺伺服器,所以我們先仿叢集搭建。          完整demo專案程式碼:https://github.com/wades2/EurekaDemo2   &nb

Spring-cloud微服務 Eureka學習教程-單伺服器配置之快速搭建EurekaServer、EurekaClient(基礎)

以下例項程式碼下載地址:https://github.com/wades2/EurekaDemo        Eureka是Spring Cloud Netflix的一個子模組,也是核心模組之一。用於雲端服務發現,一個基於REST的服務,用於定位服務,以

Spring系列學習之Spring Cloud Security微服務使用者資料安全

英文原文:https://spring.io/projects/spring-cloud-security 目錄 概述 特性 入門 快速開始 學習 文件 示例 概述 Spring Cloud Security提供了一組原語,用於構建安全的應用程式和服務,而

Eureka Server新增安全認證

配置註冊中心的Maven的pom檔案 <!--設定登入密碼需要用到Spring Security--> <dependency> <groupId>org.springframework.boot</groupId>