阿里云需要网站建设方案书网站开发要学的课程

news/2025/9/23 21:26:05/文章来源:
阿里云需要网站建设方案书,网站开发要学的课程,wordpress是哪国程序,李沧网站建设谁家好前言 之前虽然单独讲过Security Client和Resource Server的对接#xff0c;但是都是基于Spring webmvc的#xff0c;Gateway这种非阻塞式的网关是基于webflux的#xff0c;对于集成Security相关内容略有不同#xff0c;且涉及到代理其它微服务#xff0c;所以会稍微比较麻…前言 之前虽然单独讲过Security Client和Resource Server的对接但是都是基于Spring webmvc的Gateway这种非阻塞式的网关是基于webflux的对于集成Security相关内容略有不同且涉及到代理其它微服务所以会稍微比较麻烦些今天就带大家来实现Gateway网关对接OAuth2认证服务。 Gateway对接说明 身份问题 在本次示例中网关既是客户端(OAuth2 Client Server)又是资源服务(OAuth2 Resource Server)Client服务负责认证Resource负责鉴权这样如果有在浏览器直接访问网关的需要可以直接在浏览器由框架引导完成OAuth2认证过程。 框架版本与架构说明 架构图 Spring Cloud依赖版本 框架版本号Spring Boot3.1.0Nacos Server2.2.1Spring Cloud2022.0.4Spring Cloud Alibaba2022.0.0.0Spring Security6.1.0Spring OAuth2 Client6.1.0Spring OAuth2 Resource Server6.1.0 读者可以自选版本使用作为对接方版本问题不大不确定Spring Cloud Alibaba 在部署时会不会有Spring Boot的版本限制如果3.1.x无法使用请降级至3.0.10版本开发时测试都是没问题的。 网关集成认证服务请求流程图说明 用户请求受限资源网关检测没有认证信息通过RedirectServerAuthenticationEntryPoint处理并发起OAuth2登录授权申请授权申请到达认证服务认证服务检测到未登录重定向至登录页面并展示给用户用户登录成功后请求重定向至授权申请接口通过校验后携带Token重定向至回调地址(redirect_uri)注意这里回调地址要设置为网关的地址htttp://{网关ip}:{网关port}/login/oauth2/code/{registrationId}后边的/login/oauth2/code/{registrationId}路径是固定的这是框架(Security OAuth2 Client)自带的端点请求到达网关由OAuth2LoginAuthenticationWebFilter拦截并调用父类AuthenticationWebFilter的filter方法进行处理AuthenticationWebFilter调用OidcAuthorizationCodeReactiveAuthenticationManager或OAuth2LoginReactiveAuthenticationManager类处理(由授权申请的scope决定包含openid就走OidcAuthorizationCodeReactiveAuthenticationManager否则走另一个)在获取AccessToken成功以后调用ReactiveOAuth2UserService获取用户信息获取到用户信息后会解析并将认证信息保存至ReactiveSecurityContextHolder中完成这一系列的认证之后会重定向至最一开始请求的受限资源这时候就能获取到认证信息了如果访问的是被网关代理的服务则会通过令牌中继(TokenRelay)携带token访问 这就是网关通过认证服务获取认证信息的一个流程基本上只需要添加配置文件即可由框架引导进行OAuth2认证流程。 开始编码 前置条件 搭建好标准OAuth2认证服务搭建nacos服务 项目结构 gateway-example # 父模块│ ├─gateway-client-example # 网关│ ├─normal-resource-example # webmvc资源服务│ ├─webflux-resource-example # webflux资源服务│ └─pom.xml # 公共依赖依赖管理 创建一个空的maven项目 引入Spring Boot、Spring Cloud、Spring Cloud Alibaba如下 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion3.1.0/versionrelativePath/ !-- lookup parent from repository --/parentgroupIdcom.example/groupIdartifactIdgateway-example/artifactIdversion0.0.1/versionpackagingpom/packagingnamegateway-example/namedescriptiongateway-example/descriptionmodulesmodulegateway-client-example/modulemodulenormal-resource-example/modulemodulewebflux-resource-example/module/modulespropertiesjava.version17/java.version!-- 修复漏洞 --snakeyaml.version2.0/snakeyaml.version!-- Spring Cloud版本号 --spring-cloud.version2022.0.4/spring-cloud.version!-- Spring Cloud Alibaba版本号 --spring-cloud-alibaba.version2022.0.0.0/spring-cloud-alibaba.version/propertiesdependencies!-- Lombok --dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependency!-- Spring Boot 测试依赖 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency!-- 服务注册与发现 --dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-discovery/artifactId/dependency!-- 配置中心 --dependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-starter-alibaba-nacos-config/artifactId/dependency!-- 资源服务器starter --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-oauth2-resource-server/artifactId/dependency/dependenciesdependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversion${spring-cloud.version}/versiontypepom/typescopeimport/scope/dependencydependencygroupIdcom.alibaba.cloud/groupIdartifactIdspring-cloud-alibaba-dependencies/artifactIdversion${spring-cloud-alibaba.version}/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagement/project 里边的modules标签是在新建module时自动添加的 创建网关gateway-client-example模块 Spring Cloud 相关依赖已经在parent模块中引入所以该模块只需要引入Gateway、Client依赖pom如下 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.example/groupIdartifactIdgateway-example/artifactIdversion0.0.1/version/parentartifactIdgateway-client-example/artifactIdnamegateway-client-example/namedescriptiongateway-client-example/descriptiondependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-oauth2-client/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-webflux/artifactId/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-gateway/artifactId/dependencydependencygroupIdio.projectreactor/groupIdartifactIdreactor-test/artifactIdscopetest/scope/dependency!-- 负载均衡依赖 --dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-loadbalancer/artifactId/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationexcludesexcludegroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/exclude/excludes/configuration/plugin/plugins/build/project编写客户端配置 package com.example.config;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper; import org.springframework.security.oauth2.core.user.OAuth2UserAuthority;import java.util.Collection; import java.util.HashSet; import java.util.Set;/*** 客户端配置** author vains*/ Configuration public class ClientServerConfig {/*** 解析用户权限信息当在浏览器中直接访问接口框架自动调用OIDC流程登录时会用到该配置** return GrantedAuthoritiesMapper*/Beanpublic GrantedAuthoritiesMapper userAuthoritiesMapper() {return (authorities) - {SetGrantedAuthority mappedAuthorities new HashSet();authorities.forEach(authority - {if (authority instanceof OAuth2UserAuthority oAuth2UserAuthority) {// 从认证服务获取的用户信息中提取权限信息Object userAuthorities oAuth2UserAuthority.getAttributes().get(authorities);if (userAuthorities instanceof Collection? collection) {// 转为SimpleGrantedAuthority的实例并插入mappedAuthorities中collection.stream().filter(a - a instanceof String).map(String::valueOf).map(SimpleGrantedAuthority::new).forEach(mappedAuthorities::add);}}});return mappedAuthorities;};}} 该配置会在获取到用户信息后解析用户的权限信息详见文档 编写网关资源服务配置 package com.example.config;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.converter.Converter; import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity; import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; import org.springframework.security.config.web.server.ServerHttpSecurity; import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter; import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter; import org.springframework.security.oauth2.server.resource.authentication.ReactiveJwtAuthenticationConverterAdapter; import org.springframework.security.web.server.SecurityWebFilterChain; import reactor.core.publisher.Mono;/*** 资源服务器配置** author vains*/ Configuration EnableWebFluxSecurity EnableReactiveMethodSecurity public class ResourceServerConfig {/*** 配置认证相关的过滤器链** param http Spring Security的核心配置类* return 过滤器链*/Beanpublic SecurityWebFilterChain defaultSecurityFilterChain(ServerHttpSecurity http) {// 禁用csrf与corshttp.csrf(ServerHttpSecurity.CsrfSpec::disable);http.cors(ServerHttpSecurity.CorsSpec::disable);// 开启全局验证http.authorizeExchange((authorize) - authorize//全部需要认证.anyExchange().authenticated());// 开启OAuth2登录http.oauth2Login(Customizer.withDefaults());// 设置当前服务为资源服务解析请求头中的tokenhttp.oauth2ResourceServer((resourceServer) - resourceServer// 使用jwt.jwt(jwt - jwt// 请求中携带token访问时会触发该解析器适配器.jwtAuthenticationConverter(grantedAuthoritiesExtractor()))/*// xhr请求未携带Token处理.authenticationEntryPoint(this::authenticationEntryPoint)// 权限不足处理.accessDeniedHandler(this::accessDeniedHandler)// Token解析失败处理.authenticationFailureHandler(this::failureHandler)*/);return http.build();}/*** 自定义jwt解析器设置解析出来的权限信息的前缀与在jwt中的key** return jwt解析器适配器 ReactiveJwtAuthenticationConverterAdapter*/public ConverterJwt, MonoAbstractAuthenticationToken grantedAuthoritiesExtractor() {JwtGrantedAuthoritiesConverter grantedAuthoritiesConverter new JwtGrantedAuthoritiesConverter();// 设置解析权限信息的前缀设置为空是去掉前缀grantedAuthoritiesConverter.setAuthorityPrefix();// 设置权限信息在jwt claims中的keygrantedAuthoritiesConverter.setAuthoritiesClaimName(authorities);JwtAuthenticationConverter jwtAuthenticationConverter new JwtAuthenticationConverter();jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(grantedAuthoritiesConverter);return new ReactiveJwtAuthenticationConverterAdapter(jwtAuthenticationConverter);}} 需要注意的是开启方法级别鉴权的注解变了webflux的注解和webmvc的注解不一样并且过滤器链也换成SecurityWebFilterChain了jwt自定义解析器的方式也不一致实现方式见上方代码 说明文档如下 EnableReactiveMethodSecurity注解文档 Jwt解析器适配器详见文档 编写application.yml添加nacos配置 spring:cloud:nacos:serverAddr: 127.0.0.1:8848config:import:- nacos:gateway.yml?refreshtrueapplication:name: gateway 在nacos中创建gateway.yml配置文件 添加客户端与资源服务配置并添加其它资源服务的代理配置 server:port: 7000 spring:security:oauth2:# 资源服务器配置resourceserver:jwt:# Jwt中claims的iss属性也就是jwt的签发地址即认证服务器的根路径# 资源服务器会进一步的配置通过该地址获取公钥以解析jwtissuer-uri: http://192.168.119.1:8080client:provider:# 认证提供者,自定义名称custom-issuer:# Token签发地址(认证服务地址)issuer-uri: http://192.168.119.1:8080# 获取用户信息的地址默认的/userinfo端点需要IdToken获取为避免麻烦自定一个用户信息接口user-info-uri: ${spring.security.oauth2.client.provider.custom-issuer.issuer-uri}/useruser-name-attribute: nameregistration:messaging-client-oidc:# oauth认证提供者配置和上边配置的认证提供者关联起来provider: custom-issuer# 客户端名称自定义client-name: gateway# 客户端id从认证服务申请的客户端idclient-id: messaging-client# 客户端秘钥client-secret: 123456# 客户端认证方式client-authentication-method: client_secret_basic# 获取Token使用的授权流程authorization-grant-type: authorization_code# 回调地址这里设置为Spring Security Client默认实现使用code换取token的接口当前服务(gateway网关)的地址redirect-uri: http://127.0.0.1:7000/login/oauth2/code/messaging-client-oidcscope:- message.read- message.write- openid- profilecloud:gateway:default-filters:# 令牌中继- TokenRelay# 代理路径代理至服务后会去除第一个路径的内容- StripPrefix1routes:# 资源服务代理配置- id: resourceuri: lb://resourcepredicates:- Path/resource/**# 资源服务代理配置- id: webfluxuri: lb://webflux-resourcepredicates:- Path/webflux/**注意配置文件中令牌中继(TokenRelay)的配置就是添加一个filterTokenRelay; 当网关引入spring-boot-starter-oauth2-client依赖并设置spring.security.oauth2.client.*属性时会自动创建一个TokenRelayGatewayFilterFactory过滤器它会从认证信息中获取access token并放入下游请求的请求头中。 详见Gateway关于TokenRelay的文档 项目结构 创建webmvc资源服务模块normal-resource-example 在pom.xml中添加web依赖如下 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.example/groupIdartifactIdgateway-example/artifactIdversion0.0.1/version/parentartifactIdnormal-resource-example/artifactIdnamenormal-resource-example/namedescriptionnormal-resource-example/descriptiondependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationexcludesexcludegroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/exclude/excludes/configuration/plugin/plugins/build/project创建资源服务器配置添加自定义jwt解析器 package com.example.config;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter; import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter;/*** 资源服务器配置** author vains*/ Configuration EnableWebSecurity EnableMethodSecurity(jsr250Enabled true, securedEnabled true) public class ResourceServerConfig {/*** 自定义jwt解析器设置解析出来的权限信息的前缀与在jwt中的key** return jwt解析器 JwtAuthenticationConverter*/Beanpublic JwtAuthenticationConverter jwtAuthenticationConverter() {JwtGrantedAuthoritiesConverter grantedAuthoritiesConverter new JwtGrantedAuthoritiesConverter();// 设置解析权限信息的前缀设置为空是去掉前缀grantedAuthoritiesConverter.setAuthorityPrefix();// 设置权限信息在jwt claims中的keygrantedAuthoritiesConverter.setAuthoritiesClaimName(authorities);JwtAuthenticationConverter jwtAuthenticationConverter new JwtAuthenticationConverter();jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(grantedAuthoritiesConverter);return jwtAuthenticationConverter;}} 编写application.yml添加nacos配置 spring:cloud:nacos:serverAddr: 127.0.0.1:8848config:import:- nacos:resource.yml?refreshtrueapplication:name: resource在nacos中创建resource.yml配置文件添加资源服务配置 server:port: 7100spring:security:oauth2:# 资源服务器配置resourceserver:jwt:# Jwt中claims的iss属性也就是jwt的签发地址即认证服务器的根路径# 资源服务器会进一步的配置通过该地址获取公钥以解析jwtissuer-uri: http://192.168.119.1:8080注意端口不能与网关和认证服务重复 模块结构 创建webflux资源服务模块 pom.xml添加webflux依赖如下 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdcom.example/groupIdartifactIdgateway-example/artifactIdversion0.0.1/version/parentartifactIdwebflux-resource-example/artifactIdnamewebflux-resource-example/namedescriptionwebflux-resource-example/descriptiondependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-webflux/artifactId/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationexcludesexcludegroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/exclude/excludes/configuration/plugin/plugins/build /project创建资源服务配置并且添加jwt解析器适配器 跟网关的资源服务配置差不多如下 package com.example.config;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.converter.Converter; import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity; import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; import org.springframework.security.config.web.server.ServerHttpSecurity; import org.springframework.security.oauth2.jwt.Jwt; import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter; import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter; import org.springframework.security.oauth2.server.resource.authentication.ReactiveJwtAuthenticationConverterAdapter; import org.springframework.security.web.server.SecurityWebFilterChain; import reactor.core.publisher.Mono;/*** 资源服务器配置** author vains*/ Configuration EnableWebFluxSecurity EnableReactiveMethodSecurity public class ResourceServerConfig {/*** 配置认证相关的过滤器链** param http Spring Security的核心配置类* return 过滤器链*/Beanpublic SecurityWebFilterChain defaultSecurityFilterChain(ServerHttpSecurity http) {// 禁用csrf与corshttp.csrf(ServerHttpSecurity.CsrfSpec::disable);http.cors(ServerHttpSecurity.CorsSpec::disable);// 开启全局验证http.authorizeExchange((authorize) - authorize//全部需要认证.anyExchange().authenticated());// 设置当前服务为资源服务解析请求头中的tokenhttp.oauth2ResourceServer((resourceServer) - resourceServer// 使用jwt.jwt(jwtSpec - jwtSpec// 设置jwt解析器适配器.jwtAuthenticationConverter(grantedAuthoritiesExtractor())));return http.build();}/*** 自定义jwt解析器设置解析出来的权限信息的前缀与在jwt中的key** return jwt解析器适配器 ReactiveJwtAuthenticationConverterAdapter*/public ConverterJwt, MonoAbstractAuthenticationToken grantedAuthoritiesExtractor() {JwtGrantedAuthoritiesConverter grantedAuthoritiesConverter new JwtGrantedAuthoritiesConverter();// 设置解析权限信息的前缀设置为空是去掉前缀grantedAuthoritiesConverter.setAuthorityPrefix();// 设置权限信息在jwt claims中的keygrantedAuthoritiesConverter.setAuthoritiesClaimName(authorities);JwtAuthenticationConverter jwtAuthenticationConverter new JwtAuthenticationConverter();jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(grantedAuthoritiesConverter);return new ReactiveJwtAuthenticationConverterAdapter(jwtAuthenticationConverter);}} 编写application.yml添加nacos配置 spring:cloud:nacos:serverAddr: 127.0.0.1:8848config:import:- nacos:webflux.yml?refreshtrueapplication:name: webflux-resourcenacos中添加webflux.yml配置文件并添加资源服务配置 server:port: 7200spring:security:oauth2:# 资源服务器配置resourceserver:jwt:# Jwt中claims的iss属性也就是jwt的签发地址即认证服务器的根路径# 资源服务器会进一步的配置通过该地址获取公钥以解析jwtissuer-uri: http://192.168.119.1:8080与webmvc的资源服务的配置是一样的注意端口不能与其它服务端口冲突 模块结构 在三个模块中添加测试类一式三份 webmvc测试接口 package com.example.controller;import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;/*** 测试接口** author vains*/ RestController public class TestController {GetMapping(/test01)PreAuthorize(hasAnyAuthority(message.write))public String test01() {return test01;}GetMapping(/test02)PreAuthorize(hasAnyAuthority(test02))public String test02() {return test02;}GetMapping(/app)PreAuthorize(hasAnyAuthority(app))public String app() {return app;}} webflux测试接口 package com.example.controller;import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Mono;/*** 测试接口** author vains*/ RestController public class TestController {GetMapping(/test01)PreAuthorize(hasAnyAuthority(message.write))public MonoString test01() {return Mono.just(test01);}GetMapping(/test02)PreAuthorize(hasAnyAuthority(test02))public MonoString test02() {return Mono.just(test02);}GetMapping(/app)PreAuthorize(hasAnyAuthority(app))public MonoString app() {return Mono.just(app);}} 测试 前置条件 启动认证服务启动nacosnacos中都有相关配置 启动项目 依次启动三个服务顺序无所谓 在postman中直接访问网关接口或代理的服务接口 被重定向至登录了携带X-Requested-With请求头访问代表当前是xhr请求 响应401框架有区分是浏览器请求还是xhr请求对于浏览器请求会重定向到页面对于xhr请求默认会响应401状态码可自己实现异常处理这里错误信息在请求头中是因为没有重写异常处理网关资源服务配置代码中有注释。 在浏览器中访问网关接口或代理的服务接口 访问 浏览器打开地址http://127.0.0.1:7000/resource/app 请求到达网关后检测到未登录会引导用户进行OAuth2认证流程 登录后提交 登录提交后认证服务重定向授权申请接口校验通过后会生成code并携带code重定向至回调地址注意这里的回调地址是网关的服务地址由网关中的OAuth2 Client处理如图 网关会根据code换取token获取token后根据token获取用户信息并调用网关客户端配置中自定义的userAuthoritiesMapper解析权限信息。 访问权限不足的接口 响应403并将错误信息放入响应头中 使用token访问网关 过期token 响应401并在响应头中提示token已过期 错误token 响应401并在响应头中提示token无法解析 权限不足token 响应403并提示权限不足 正常请求 响应200并正确响应接口信息 写在最后 本文带大家简单实现了Spring Cloud Gateway对接认证服务Gateway中添加客户端主要是为了如果代理服务有静态资源(html、css、image)时可以直接发起OAuth2授权流程在浏览器登录后直接访问同时也是开启令牌中继的必要依赖引入Resource Server依赖是当需要对网关的接口鉴权时可以直接使用如果网关只负责转发应该是可以去掉资源服务相关依赖和配置的由各个被代理的微服务对自己的接口进行鉴权。这些东西在之前基本都是讲过的内容所以本文很多地方都是一笔带过的如果某些地方不清楚可以针对性的翻翻之前的文章也可以在评论区中提出。 如果有什么问题或者需要补充的请在评论区指出谢谢。 附录 Gitee仓库地址 Gateway令牌中继文档 OAuth2登录后用户权限解析文档 webflux开启方法鉴权EnableReactiveMethodSecurity注解说明文档 webflux的Jwt解析器适配器说明文档 webflux对接OAuth2 Client文档 webflux对接OAuth2 Resource Server文档

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/913934.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

中国建设银行下载官方网站共享门店新增跑腿距离计算优化

随着VR技术的不断进步,VR全景技术已经成为了文化展示和传播的一项重要工具,相较于传统视频、图文等展现方式,VR全景体验更加直观、便捷,其中蕴涵的信息量也更加丰富,这也为公众了解博物馆和历史文化带来了更为深刻的体…

备案期间能否做网站解析wordpress php占内存

尽管BERT为代表的预训练模型大肆流行,但是身处工业界才会知道它落地有多难,尤其是QPS动辄几百的在线推荐、搜索系统,哪怕在大厂也很难在线上系统见到它们。 今天就想反其道而行之,谈谈工业界搜索、推荐、广告这类核心场景中落地能…

零基础建设网站视频wordpress当前页面id

1 引言 在学习前,我想说一句,那就是为什么要学习Java。 每个人的出发点都不同,对于做信息化的工程技术人员来说,java不懂,就没法干项目。 尽管有c和matlab等基础,但java看起来与这些语言都不太一样。 做…

深圳市盐田区住房和建设局网站泽成杭州seo网站推广排名

文章目录 1. 添加动画2. Animation2.1 制作界面2.2 制作好的 Animation 动画2.3 添加和使用事件 3. Animator3.1 制作界面3.2 一些参数解释3.3 动画参数 4. Animator中相关类、属性、API4.1 类4.2 属性4.3 API4.4 几个关键方法 5. 动画播放和暂停控制 1. 添加动画 选中待提添加…

为什么我的网站没有百度索引量国产做爰全免费的视频网站

STM32 在 Windows 上的交叉编译二 调试 在上一篇博客 《在Windows上交叉编译STM32(环境搭建)》 ,已经让 CubeMX 生成的工程成功编译,并下载到板子上了。 这篇博客主要继续介绍接下来的步骤,调试。硬件是使用的 ST-LINK ,别的也无…

旋转图像-leetcode

题目描述 给定一个 n n 的二维矩阵 matrix 表示一个图像。请你将图像顺时针旋转 90 度。 你必须在 原地 旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要 使用另一个矩阵来旋转图像。 示例 1:输入:matrix …

【ChipIntelli 系列】ASR部分——合成语言模型和多网络(多语种)切换

打开 ChipIntelli 的AI开发平台,找到组件开发的语言模型开发。在页面中编辑语料然后下载文件 共有两个文件夹:拷贝两个文件夹下的文件到SDK中 以双网络为例: 如果您使用的是CI130X SDK,请按如下步骤将合成的文件拷…

dots.llm1:小红书开源的 MoE 架构大语言模型 - 实践

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

哪些ERP系统值得长期使用?2025年最新盘点来了!

哪些ERP系统值得长期使用?2025年最新盘点来了!在数字化转型加速的背景下,企业对ERP系统的依赖日益加深。根据行业调研数据显示,持续应用集成化ERP系统的企业在运营效率、数据准确性和战略决策能力上较传统管理模式有…

商品网站建设设计思路dw怎么做网站

文章目录 一、redis1.1 redis概述1.2 redis安装 二、string2.1 基础命令2.2 存储结构2.3 应用 三、list3.1 基础命令3.2 应用 四、hash4.1 基础命令4.2 存储结构4.3 应用 五、set5.1 基础命令5.2 存储结构5.3 应用 六、zset6.1 基础命令6.2 存储结构6.3 应用 一、redis 1.1 re…

下载网站源码行业网站设计公司

文章来源:http://www.bjfhrd.com 体育木地板上有许多暗门,以制造特殊效果,如火焰、烟雾,使房屋、树木、山或人物在一瞬间出现或销售。这种特殊的要求,对于专业体育木地板德施工就有了一定的要求。 专业体育木地板施工&…

湖南教育平台网站建设查公司注册信息怎么查

转载自 关于SimpleDateFormat时间格式化线程安全问题昨天推送的文章《关于创建和销毁对象》一文中,2.1重复利用对象这一小节所举的SimpleDateFormat格式化时间的例子是不合适的,因为多线程场景下,SimpleDateFormat存在线程安全问题。在此&am…

网站的建设与维护需要资质吗网站设置子目录

HTTP HTTP版本HTTP2和HTTP3区别 HTTP版本 HTTP(超文本传输协议)的发展史可以分为以下几个版本: 1. HTTP/0.9:最初的版本只能传输HTML文本,并且没有header和body,仅支持GET请求。 2. HTTP/1.0&#xff1a…

如何对网站的图片做cdn如何做企业文化培训

1、什么是流 我们可以先想象水流是怎样的?溪水不断流动,最终融入大海;我们今天的学习IO其实如同水流一样,当我们读取文件信息或者写入信息时,如同水流一样,不断读取或者写入,直到业务流程结束。…

个人导航网站怎么备案网站上线准备

本文来自腾讯蓝鲸智云社区用户: CanWay 平台化工程涉及双重核心意义。一方面,是类似利用IDE等工具提高工程师效率的平台化工程,如GitOps或命令行调度般便捷。然而,本文重点探讨的是基于价值流的平台化工程,尤其针对传统金融行业&a…

部队网站模板html网页框架代码实例

分类算法之逻辑回归逻辑回归(Logistic Regression),简称LR。它的特点是能够是我们的特征输入集合转化为0和1这两类的概率。一般来说,回归不用在分类问题上,因为回归是连续型模型,而且受噪声影响比较大。如果…

好看的单页面网站中小企业网站功能

#需要资源或有问题的,可私博主!!! #需要资源或有问题的,可私博主!!! #需要资源或有问题的,可私博主!!! 某企业根据自身业务需求&…

内网环境怎么安装软件(用 yum / apt 下载离线包并搬入内网)

目录内网环境怎么安装软件(用 yum / apt 下载离线包并搬入内网) 内网环境怎么安装软件(用 yum / apt 下载离线包并搬入内网) 很多同学觉得在内网装软件很简单:在有网络的机器上把包下载好,再拷贝到内网安装。思路…

tanh函数

tanh函数(双曲正切函数)是神经网络中一种常用的激活函数,它的数学表达式为: $$\tanh(x) = \frac{e^x - e{-x}}{ex + e^{-x}}$$ 它的输出范围是 $(-1, 1)$。 tanh函数的特点非线性:和 Sigmoid 函数一样,tanh 函数…

P13617 [ICPC 2024 APC] Bit Counting Sequence

P13617 [ICPC 2024 APC] Bit Counting Sequence对于一个非负整数 \(x\),令 \(p(x)\) 为 \(x\) 的二进制表示中 1 的个数。例如,\(p(26)=3\),因为 \(26=(11010)_2\)。 给定长为 \(n\) 的整数序列 \((a_1, a_2, ..., …