Online studies - Day 17 - Lecture - User Authentication Zuul six

4.4  Routing Configuration
4.4.1 Requirements Analysis 
Zuul gateway with proxy functionality, according to the request url forwarded to the micro-services, as follows:

 
client request gateway / API / learning , forwarding, via the routing / learning 
client requests the gateway / api / course forwarded through the routing / Course 
4.4.2  routing configuration 
in appcation.yml configuration:

zuul:
routes:
manage‐course: #路由名称,名称任意,保持所有路由名称唯一
path: /course/**
serviceId: xc‐service‐manage‐course #指定服务id,从Eureka中找到服务的ip和端口
#url: http://localhost:31200 #也可指定url
strip‐prefix: false #true:代理转发时去掉前缀,false:代理转发时不去掉前缀
sensitiveHeaders: #默认zuul会屏蔽cookie,cookie不会传到下游服务,这里设置为空则取消默认的黑名
单,如果设置了具体的头信息则不会传到下游服务
# ignoredHeaders: Authorization

serviceId : recommended serviceId , Zuul will from Eureka found the service id corresponding ip and port. 
prefifix-Strip: #true to false : proxy forwarding prefix is removed, to false: without removing the prefix forwarding agent, e.g., as a true request 
request / Course / coursebase / GET / .. , to forwarding agent / coursebase / GET / , if false then forwarded to the agent / Course, / coursebase / GET
sensitiveHeaders : sensitive head set, the default will filter out the cookie , set here to indicate empty but consider
ignoredHeaders : you can set misplaced header information, the default is empty, but expressed worry any head 
4.4.3  test 
request http: // localhost: 50201 / api / course / coursepic / list / 4028e58161bd22e60161bd23672a0001Queries course pictures letter 
message
http: // localhost: 50201 / api is the gateway addresses and forwards through route xc-service-manage-course service. 
Since management has added the teaching curriculum interception, here temporarily in order to test the gateway function "/ course / coursepic / list" url preclude certification. 
In the course management services  ResourceServerConfifig add class "/ course / coursepic / list / *", the code is as follows:

@Override
public void configure(HttpSecurity http) throws Exception {
//所有请求必须认证通过
http.authorizeRequests()
//下边的路径放行
.antMatchers("/v2/api‐docs", "/swagger‐resources/configuration/ui",
"/swagger‐resources","/swagger‐resources/configuration/security",
"/swagger‐ui.html","/course/coursepic/list/*")
.permitAll()
.anyRequest().authenticated();
}

4.4.4  complete routing configuration

zuul:
routes:
xc‐service‐learning: #路由名称,名称任意,保持所有路由名称唯一
path: /learning/**
serviceId: xc‐service‐learning #指定服务id,从Eureka中找到服务的ip和端口
strip‐prefix: false
sensitiveHeaders:
manage‐course:
path: /course/**
serviceId: xc‐service‐manage‐course
strip‐prefix: false
sensitiveHeaders:
manage‐cms:
path: /cms/**
serviceId: xc‐service‐manage‐cms
strip‐prefix: false
sensitiveHeaders:
manage‐sys:
path: /sys/**
serviceId: xc‐service‐manage‐cms
strip‐prefix: false
sensitiveHeaders:
service‐ucenter:
path: /ucenter/**
serviceId: xc‐service‐ucenter
sensitiveHeaders:
strip‐prefix: false
xc‐service‐manage‐order:
path: /order/**
serviceId: xc‐service‐manage‐order
sensitiveHeaders:
strip‐prefix: false

 

Published 835 original articles · won praise 152 · Views 140,000 +

Guess you like

Origin blog.csdn.net/qq_40208605/article/details/104394424