SpringCloud配置服務(wù)端的ConfigServer設(shè)置安全認(rèn)證
一、大致介紹
1、前面提到的加密內(nèi)容,雖然說(shuō)對(duì)內(nèi)容進(jìn)行了加密,但是為了更安全的安全隔離,服務(wù)與服務(wù)之間也需要設(shè)置簡(jiǎn)單的安全認(rèn)證;
2、那么在本章節(jié)我們講解下如何配置服務(wù)端之間的簡(jiǎn)單認(rèn)證,Springcloud 的強(qiáng)大之處在于對(duì)認(rèn)證這塊僅僅配置一下即可;
3、然后后續(xù)我們還會(huì)講解 SpringCloud 的 auth2 等認(rèn)證機(jī)制,后續(xù)有待繼續(xù)講解;
4、這里還順便列舉下配置路徑的規(guī)則:
/****************************************************************************************
* 配置服務(wù)的路勁規(guī)則:
*
* /{application}/{profile}[/{label}]
* /{application}-{profile}.yml
* /{label}/{application}-{profile}.yml
* /{application}-{profile}.properties
* /{label}/{application}-{profile}.properties
****************************************************************************************/
二、實(shí)現(xiàn)步驟
2.1 添加 maven 引用包
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>springms-config-server-authc</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.springms.cloud</groupId>
<artifactId>springms-spring-cloud</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<dependencies>
<!-- 服務(wù)端配置模塊 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!-- 服務(wù)端登錄驗(yàn)證模塊 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
</project>2.2 添加應(yīng)用配置文件
(springms-config-server-authcsrcmainresourcesapplication.yml)
#配置登錄密碼
security:
basic:
enabled: true
user:
name: admin
password: admin
server:
port: 8275
spring:
application:
name: springms-config-server-authc
cloud:
config:
server:
git:
uri: https://gitee.com/ylimhhmily/OpenSource_CustomCircleLineProgressBar2.3 添加微服務(wù)啟動(dòng)類(lèi)
(springms-config-server-authc/src/main/java/com/springms/cloud/MsConfigServerAuthcApplication.java)
package com.springms.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
/**
* 配置服務(wù)端ConfigServer設(shè)置安全認(rèn)證。
*
* @author hmilyylimh
*
* @version 0.0.1
*
* @date 17/10/18
*
*/
@SpringBootApplication
@EnableConfigServer
public class MsConfigServerAuthcApplication {
public static void main(String[] args) {
SpringApplication.run(MsConfigServerAuthcApplication.class, args);
System.out.println("【【【【【【 ConfigServerAuthc微服務(wù) 】】】】】】已啟動(dòng).");
}
}三、測(cè)試
一、配置服務(wù)服務(wù)端Server應(yīng)用入口(正常測(cè)試):
1、注解:EnableConfigServer
2、編輯 application.yml 文件,配置登錄密碼;
3、啟動(dòng) springms-config-server-authc 模塊服務(wù),啟動(dòng)1個(gè)端口;
4、在瀏覽器輸入地址 http://localhost:8275/abc-default.properties 正常情況下會(huì)輸出配置文件的內(nèi)容;
5、在瀏覽器輸入地址 http://localhost:8275/abc-default.yml 正常情況下會(huì)輸出配置文件的內(nèi)容;
6、在瀏覽器輸入地址 http://localhost:8275/abc-hehui.yml 正常情況下會(huì)輸出配置文件的內(nèi)容;
7、在瀏覽器輸入地址 http://localhost:8275/aaa-bbb.yml 正常情況下會(huì)輸出配置文件的內(nèi)容;
8、在瀏覽器輸入地址 http://localhost:8275/aaa-bbb.properties 正常情況下會(huì)輸出配置文件的內(nèi)容;
9、在瀏覽器輸入地址 http://localhost:8275/master/abc-default.properties 正常情況下會(huì)輸出配置文件的內(nèi)容;
10、在瀏覽器輸入地址 http://localhost:8275/master/abc-default.yml 正常情況下會(huì)輸出配置文件的內(nèi)容;
11、在瀏覽器輸入地址 http://localhost:8275/master/abc-hehui.yml 正常情況下會(huì)輸出配置文件的內(nèi)容;
12、在瀏覽器輸入地址 http://localhost:8275/master/aaa-bbb.yml 正常情況下會(huì)輸出配置文件的內(nèi)容;
13、在瀏覽器輸入地址 http://localhost:8275/master/aaa-bbb.properties 正常情況下會(huì)輸出配置文件的內(nèi)容;
14、在瀏覽器輸入地址 http://localhost:8275/springms-config-server-dev.yml 正常情況下會(huì)輸出配置文件的內(nèi)容;
總結(jié):按照配置服務(wù)的路徑規(guī)則配置,基本上都可以訪問(wèn)得到結(jié)果數(shù)據(jù)。
下載地址 https://gitee.com/ylimhhmily/SpringCloudTutorial.git
以上就是SpringCloud配置服務(wù)端的ConfigServer設(shè)置安全認(rèn)證的詳細(xì)內(nèi)容,更多關(guān)于SpringCloud ConfigServer安全認(rèn)證的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
SpringBoot工程下Lombok的應(yīng)用教程詳解
這篇文章主要給大家介紹了關(guān)于SpringBoot工程下Lombok應(yīng)用的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
SpringCloud之分布式配置中心Spring Cloud Config高可用配置實(shí)例代碼
這篇文章主要介紹了SpringCloud之分布式配置中心Spring Cloud Config高可用配置實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-04-04
詳解SpringBoot修改啟動(dòng)端口server.port的四種方式
這篇文章主要介紹了詳解SpringBoot修改啟動(dòng)端口server.port的四種方式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
Java Web實(shí)現(xiàn)自動(dòng)登陸功能
這篇文章主要為大家詳細(xì)介紹了Java Web實(shí)現(xiàn)自動(dòng)登陸功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08

