紧接上文《从0到1 手把手搭建spring cloud alibaba 微服务大型应用框架(二) (mini-cloud) 创建项目以及搭建源码启动版nacos 注册中心》今天主要来一步步详细聊一下如何搭建认证,中心,也就是下图的auth2.0认证服务

今天涉及的方面比较多,也会捎带聊聊一些内部原理以及代码等,所以分为上,中,下三部分来说

全片主要依照下面流程来说,主要也是一个从无到有,从粗到细的一个过程,尽量贴近大家一个开发流程,本文介绍的也不是最终的版本,在后面会有一些重构代码的文章,前期不会做到一步到位,直接贴上完善代码和一步步变为完善我觉得后者对大家帮助更大,后面会将源码公开到github

好了,先介绍一下整体文章流程

##1.创建authentication-center 服务
##2.将authentication-center 服务集成入spring cloud nacos注册中心
##3.选择oauth2 认证模式,分离认证服务器以及资源服务器,设计下沉式资源端认证模式
##4.按照spring 官方内存式认证demo 搭建oauth2 client 认证
##5.添加测试服务module 并集成如spring cloud nacos 中
##6.测试服务 作为resource server 进行认证测试
##7.将配置文件参数纳入nacos 配置中心进行管理
##8.将内存式认证改为实际redis 以及clientdetail ,userdetail 为数据库中获取
##9.将demo 权限认证改为根据当前登陆用户角色动态校验权限
##10.抽取认证服务器与资源服务器共通部分变为common module
##11.应用common 模块重构代码再次校验认证

 

1.创建authentication-center 服务

我们在mini-cloud 目录下新建一个module  ,起名为authentication-center 即认证中心,这个专门用来认证获取access_token ,reflush_token ,check_token 等,创建完module之后,我们将该服务集成进入到spring cloud nacos 体系

2.将authentication-center 服务集成入spring cloud nacos注册中心

需要相关改动的地方有如下几个文件,给出代码

MiniCloudAuthApplication.java
package com.minicloud.authentication;import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;/*** @Author alan.wang* @date: 2022-01-17 10:18*/
@SpringCloudApplication
public class MiniCloudAuthApplication {public static void main(String[] args) {SpringApplication.run(MiniCloudAuthApplication.class, args);}
}

bootstrap.yml

server:port: 8800spring:application:name: @artifactId@cloud:nacos:discovery:server-addr: ${NACOS_HOST:127.0.0.1}:${NACOS_PORT:8848}config:server-addr: ${spring.cloud.nacos.discovery.server-addr}file-extension: ymlshared-configs:- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}profiles:active: @profiles.active@

pom.xml

<?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"><parent><artifactId>mini-cloud</artifactId><groupId>org.mini-cloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>authentication-center</artifactId><dependencies><!--注册中心客户端--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!--配置中心客户端--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><!--安全模块 --><dependency><groupId>org.springframework.security.oauth</groupId><artifactId>spring-security-oauth2</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency><dependency><groupId>org.springframework.security.oauth.boot</groupId><artifactId>spring-security-oauth2-autoconfigure</artifactId></dependency><!--web 模块--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-jwt</artifactId></dependency><dependency><groupId>com.nimbusds</groupId><artifactId>nimbus-jose-jwt</artifactId></dependency></dependencies>
</project>

其实但是spring cloud 集成只需要

另外之前的mini-cloud 根pom.xml有些变动,增加了一些依赖管理,直接贴出来全部

 

<?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><groupId>org.mini-cloud</groupId><artifactId>mini-cloud</artifactId><packaging>pom</packaging><version>1.0-SNAPSHOT</version><modules><module>register-center</module><module>authentication-center</module><module>mini-cloud-tester</module></modules><properties><nacos-version>1.4.1</nacos-version><nacos-name>com.alibaba.nacos</nacos-name><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><!-- Compiler settings properties --><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><!-- Maven properties --><maven.test.skip>false</maven.test.skip><maven.javadoc.skip>true</maven.javadoc.skip><sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin><!-- Exclude all generated code --><sonar.jacoco.itReportPath>${project.basedir}/../test/target/jacoco-it.exec</sonar.jacoco.itReportPath><sonar.exclusions>file:**/generated-sources/**,**/test/**</sonar.exclusions><security.oauth.version>2.3.6.RELEASE</security.oauth.version><!-- plugin version --><versions-maven-plugin.version>2.2</versions-maven-plugin.version><dependency-mediator-maven-plugin.version>1.0.2</dependency-mediator-maven-plugin.version><clirr-maven-plugin.version>2.7</clirr-maven-plugin.version><maven-enforcer-plugin.version>1.4.1</maven-enforcer-plugin.version><maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version><maven-javadoc-plugin.version>2.10.4</maven-javadoc-plugin.version><maven-source-plugin.version>3.0.1</maven-source-plugin.version><maven-pmd-plugin.version>3.8</maven-pmd-plugin.version><apache-rat-plugin.version>0.12</apache-rat-plugin.version><maven-resources-plugin.version>3.0.2</maven-resources-plugin.version><coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version><jacoco-maven-plugin.version>0.7.8</jacoco-maven-plugin.version><maven-surefire-plugin.version>2.20</maven-surefire-plugin.version><findbugs-maven-plugin.version>3.0.4</findbugs-maven-plugin.version><sonar-maven-plugin.version>3.0.2</sonar-maven-plugin.version><maven-gpg-plugin.version>1.6</maven-gpg-plugin.version><maven-failsafe-plugin.version>2.19.1</maven-failsafe-plugin.version><maven-assembly-plugin.version>3.0.0</maven-assembly-plugin.version><maven-checkstyle-plugin.version>3.1.1</maven-checkstyle-plugin.version><!-- dependency version related to plugin --><extra-enforcer-rules.version>1.0-beta-4</extra-enforcer-rules.version><p3c-pmd.version>1.3.0</p3c-pmd.version><!-- dependency version --><spring-cloud-starter-netflix-hystrix.version>2.2.5.RELEASE</spring-cloud-starter-netflix-hystrix.version><spring-cloud-alibaba.version>2.2.3.RELEASE</spring-cloud-alibaba.version><spring-boot-dependencies.version>2.2.6.RELEASE</spring-boot-dependencies.version><servlet-api.version>3.0</servlet-api.version><commons-lang3.version>3.4</commons-lang3.version><commons-io.version>2.2</commons-io.version><commons-collections.version>3.2.2</commons-collections.version><commons-logging.version>1.2</commons-logging.version><commons-dbcp.version>1.4</commons-dbcp.version><commons-cli.version>1.2</commons-cli.version><slf4j-api.version>1.7.7</slf4j-api.version><logback.version>1.2.3</logback.version><log4j.version>2.13.3</log4j.version><httpcore.version>4.4.1</httpcore.version><httpclient.version>4.5</httpclient.version><httpasyncclient.version>4.1.3</httpasyncclient.version><mysql-connector-java.version>8.0.16</mysql-connector-java.version><derby.version>10.14.2.0</derby.version><cglib-nodep.version>2.1</cglib-nodep.version><jcip-annotations.version>1.0</jcip-annotations.version><jackson-core.version>2.10.4</jackson-core.version><jackson-databind.version>2.10.4</jackson-databind.version><jackson-core-asl.version>1.9.13</jackson-core-asl.version><jjwt.version>0.11.2</jjwt.version><netty-all.version>4.1.42.Final</netty-all.version><netty-common.version>4.1.31.Final</netty-common.version><mina-core.version>2.0.0-RC1</mina-core.version><guava.version>24.1.1-jre</guava.version><javatuples.version>1.2</javatuples.version><commonOkHttp.version>0.4.1</commonOkHttp.version><grpc-java.version>1.24.0</grpc-java.version><proto-google-common-protos.version>1.17.0</proto-google-common-protos.version><protobuf-java.version>3.8.0</protobuf-java.version><protoc-gen-grpc-java.version>1.24.0</protoc-gen-grpc-java.version><hessian.version>4.0.63</hessian.version><reflections.version>0.9.11</reflections.version><mockito-all.version>1.10.19</mockito-all.version><hamcrest-all.version>1.3</hamcrest-all.version><prometheus-simpleclient.version>0.5.0</prometheus-simpleclient.version><tomcat-embed-jasper.version>9.0.37</tomcat-embed-jasper.version><truth.version>0.30</truth.version><HikariCP.version>3.4.2</HikariCP.version><jraft-core.version>1.3.5</jraft-core.version><rpc-grpc-impl.version>1.3.5</rpc-grpc-impl.version></properties><!-- 管理依赖版本号,子项目不会默认依赖 --><dependencyManagement><dependencies><dependency><!-- Import dependency management from Spring Boot --><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot-dependencies.version}</version><type>pom</type><scope>import</scope></dependency><!-- Internal libs --><dependency><groupId>${nacos-name}</groupId><artifactId>nacos-config</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${nacos-name}</groupId><artifactId>nacos-core</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${nacos-name}</groupId><artifactId>nacos-naming</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${nacos-name}</groupId><artifactId>nacos-api</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${project.groupId}</groupId><artifactId>nacos-client</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${project.groupId}</groupId><artifactId>nacos-common</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${project.groupId}</groupId><artifactId>nacos-cmdb</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${project.groupId}</groupId><artifactId>nacos-console</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${project.groupId}</groupId><artifactId>nacos-distribution</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${nacos-name}</groupId><artifactId>nacos-address</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${nacos-name}</groupId><artifactId>nacos-istio</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${project.groupId}</groupId><artifactId>nacos-consistency</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${nacos-name}</groupId><artifactId>nacos-auth</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>${nacos-name}</groupId><artifactId>nacos-sys</artifactId><version>${nacos-version}</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>${servlet-api.version}</version><scope>provided</scope></dependency><!-- HikariCP --><dependency><groupId>com.zaxxer</groupId><artifactId>HikariCP</artifactId><version>${HikariCP.version}</version></dependency><!-- hessian --><dependency><groupId>com.caucho</groupId><artifactId>hessian</artifactId><version>${hessian.version}</version></dependency><!-- Apache commons --><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>${commons-lang3.version}</version></dependency><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>${commons-io.version}</version></dependency><dependency><groupId>commons-collections</groupId><artifactId>commons-collections</artifactId><version>${commons-collections.version}</version></dependency><dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>${commons-logging.version}</version></dependency><dependency><groupId>commons-dbcp</groupId><artifactId>commons-dbcp</artifactId><version>${commons-dbcp.version}</version></dependency><dependency><groupId>commons-cli</groupId><artifactId>commons-cli</artifactId><version>${commons-cli.version}</version></dependency><!-- Logging libs --><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>${slf4j-api.version}</version></dependency><dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>${logback.version}</version></dependency><dependency><groupId>ch.qos.logback</groupId><artifactId>logback-core</artifactId><version>${logback.version}</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId><version>${log4j.version}</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-api</artifactId><version>${log4j.version}</version></dependency><dependency><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-slf4j-impl</artifactId><version>${log4j.version}</version></dependency><!-- HTTP client libs --><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpcore</artifactId><version>${httpcore.version}</version></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>${httpclient.version}</version><exclusions><exclusion><artifactId>commons-logging</artifactId><groupId>commons-logging</groupId></exclusion></exclusions></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpasyncclient</artifactId><version>${httpasyncclient.version}</version></dependency><!-- JDBC libs --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>${mysql-connector-java.version}</version></dependency><dependency><groupId>org.apache.derby</groupId><artifactId>derby</artifactId><version>${derby.version}</version></dependency><!-- JRaft --><dependency><groupId>com.alipay.sofa</groupId><artifactId>jraft-core</artifactId><version>${jraft-core.version}</version><exclusions><exclusion><groupId>com.alipay.sofa</groupId><artifactId>bolt</artifactId></exclusion><exclusion><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-api</artifactId></exclusion><exclusion><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-core</artifactId></exclusion><exclusion><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-slf4j-impl</artifactId></exclusion><exclusion><groupId>org.apache.logging.log4j</groupId><artifactId>log4j-jcl</artifactId></exclusion></exclusions></dependency><dependency><groupId>com.alipay.sofa</groupId><artifactId>rpc-grpc-impl</artifactId><version>${rpc-grpc-impl.version}</version></dependency><!-- Third-party libs --><dependency><groupId>cglib</groupId><artifactId>cglib-nodep</artifactId><version>${cglib-nodep.version}</version></dependency><dependency><groupId>net.jcip</groupId><artifactId>jcip-annotations</artifactId><version>${jcip-annotations.version}</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-core</artifactId><version>${jackson-core.version}</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>${jackson-databind.version}</version></dependency><dependency><groupId>org.codehaus.jackson</groupId><artifactId>jackson-core-asl</artifactId><version>${jackson-core-asl.version}</version></dependency><dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt-api</artifactId><version>${jjwt.version}</version></dependency><dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt-impl</artifactId><version>${jjwt.version}</version><scope>runtime</scope></dependency><dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt-jackson</artifactId><version>${jjwt.version}</version><scope>runtime</scope></dependency><dependency><groupId>io.netty</groupId><artifactId>netty-all</artifactId><version>${netty-all.version}</version></dependency><dependency><groupId>io.netty</groupId><artifactId>netty-common</artifactId><version>${netty-common.version}</version></dependency><dependency><groupId>org.apache.mina</groupId><artifactId>mina-core</artifactId><version>${mina-core.version}</version></dependency><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>${guava.version}</version></dependency><dependency><groupId>org.javatuples</groupId><artifactId>javatuples</artifactId><version>${javatuples.version}</version></dependency><dependency><groupId>com.github.keran213539</groupId><artifactId>commonOkHttp</artifactId><version>${commonOkHttp.version}</version><scope>test</scope></dependency><!-- gRPC dependency start --><dependency><groupId>io.grpc</groupId><artifactId>grpc-netty-shaded</artifactId><version>${grpc-java.version}</version></dependency><dependency><groupId>io.grpc</groupId><artifactId>grpc-protobuf</artifactId><version>${grpc-java.version}</version></dependency><dependency><groupId>io.grpc</groupId><artifactId>grpc-stub</artifactId><version>${grpc-java.version}</version></dependency><dependency><groupId>io.grpc</groupId><artifactId>protoc-gen-grpc-java</artifactId><version>${grpc-java.version}</version><type>pom</type></dependency><dependency><groupId>com.google.api.grpc</groupId><artifactId>proto-google-common-protos</artifactId><version>${proto-google-common-protos.version}</version></dependency><!-- gRPC dependency end --><dependency><groupId>com.google.protobuf</groupId><artifactId>protobuf-java</artifactId><version>${protobuf-java.version}</version></dependency><dependency><groupId>org.reflections</groupId><artifactId>reflections</artifactId><version>${reflections.version}</version></dependency><dependency><groupId>org.mockito</groupId><artifactId>mockito-all</artifactId><version>${mockito-all.version}</version></dependency><dependency><groupId>org.hamcrest</groupId><artifactId>hamcrest-all</artifactId><version>${hamcrest-all.version}</version></dependency><dependency><groupId>io.prometheus</groupId><artifactId>simpleclient</artifactId><version>${prometheus-simpleclient.version}</version></dependency><dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-jasper</artifactId><version>${tomcat-embed-jasper.version}</version></dependency><dependency><groupId>com.google.truth</groupId><artifactId>truth</artifactId><version>${truth.version}</version></dependency><!--spring cloud alibaba--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>${spring-cloud-alibaba.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.springframework.security</groupId><artifactId>spring-security-jwt</artifactId><version>1.1.0.RELEASE</version></dependency><dependency><groupId>com.nimbusds</groupId><artifactId>nimbus-jose-jwt</artifactId><version>8.2.1</version></dependency><dependency><groupId>org.springframework.security.oauth.boot</groupId><artifactId>spring-security-oauth2-autoconfigure</artifactId><version>2.2.1.RELEASE</version></dependency><!--稳定版本,替代spring security bom内置--><dependency><groupId>org.springframework.security.oauth</groupId><artifactId>spring-security-oauth2</artifactId><version>${security.oauth.version}</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId><version>${spring-cloud-starter-netflix-hystrix.version}</version></dependency></dependencies></dependencyManagement><distributionManagement><snapshotRepository><!-- 这里的ID一定要在maven setting文件中存在于server下的ID --><id>sona</id><url>https://oss.sonatype.org/content/repositories/snapshots/</url></snapshotRepository><repository><id>sona</id><url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url></repository></distributionManagement><profiles><profile><id>dev</id><properties><!-- 环境标识,需要与配置文件的名称相对应 --><profiles.active>dev</profiles.active></properties><activation><!-- 默认环境 --><activeByDefault>true</activeByDefault></activation></profile><profile><id>test</id><properties><profiles.active>test</profiles.active></properties></profile><profile><id>prod</id><properties><profiles.active>prod</profiles.active></properties></profile></profiles><build><finalName>${project.name}</finalName><resources><resource><directory>src/main/resources</directory><filtering>true</filtering></resource></resources><pluginManagement><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></pluginManagement></build>
</project>

注册中心的application 改了个名,统一了一下,由nacos改成了MiniCloudRegisterApplication

好了测试一下是否集成入了spring cloud nacos ,先启动nacos 注册中心,再启动认证中心

 然后访问http://localhost:8848/nacos/ 控制台

发现确实刚刚搭建的认证服务以及集成入了nacos  

 3.选择oauth2 认证模式,分离认证服务器以及资源服务器,设计下沉式资源端认证模式

这里涉及到一些理论内容,我画了俩图描述一下什么是认证服务,什么是资源服务,他俩的关系是什么,理解起来容易一些

           认证服务与资源服务

     

               认证服务与资源服务关联

 

 白话总结一下:

认证服务:主要就是我们的认证中心,所有客户端访问资源服务的时候,资源服务都会内部访问一下认证服务去校验是否有权利

资源服务:就是被访问的接口,侠义上web的话可以说是我们的controller 的url

想详细了解的可以访问spring auth2.0官网以及官网提供的demo直接运行

auth2.0官网介绍:https://projects.spring.io/spring-security-oauth/docs/oauth2.html

auth2.0 默认支持以下认证模式 通过访问参数grant_type 区分

有兴趣得可以了解下,我们这里简单说明一下

authorization code:授权码模式,比较安全,但是仅能用在web 项目,需要有页面url

client_credentials: 客户端模式,这里主要就是针对app 或者某一服务得认证,例如微信平台对我们某一应用,阿里云oss 对我们某一应用等,这里不太适合我们普遍的用户通过账号密码登陆厂家

password:用户名密码模式,就是我们常用的本站用户通过用户名密码等登陆的场景,本文主要选取该模式,以后会说一下如何自定义授权模式,做到支持自己需要的授权,不在本文范围内

虽说我们选取的是password模式,但其实依然需要对client 认证做支持,因为我们认证中心以后可能会需要支持其他外部服务的接入,所以还是要对每个服务有一个clientId以及共通端的资源权限认定

4.按照spring 官方内存式认证demo 搭建oauth2 client 认证

我们开发任何功能,一般都会想用最简单的demo 完成最小闭环保证先跑起来,我们也这样,直接拿官网demo改一下,先保证跑起来

 auth2.0官网demo地址:GitHub - jgrandja/spring-security-oauth-2-4-migrate

 认证服务一般就需要做两件事就可以了

1. 继承  AuthorizationServerConfigurerAdapter 并开启 @EnableAuthorizationServer

2.继承  WebSecurityConfigurerAdapter 并开启 @EnableWebSecurity

1 是为了自定义加入自己的server端的自定义bean,比如clientservice ,.userdetailservice

2 是为了注入web服务本身需要的拦截器或者需要拦截的url等

闲话少说,本身代码很少也都是内存模式运行的,直接上代码,代码上我也做了详细注释

我们只要添加两个文件即可

AuthorizationServerConfig.java
/** Copyright 2012-2019 the original author or authors.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/
package com.minicloud.authentication.config;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;import javax.annotation.Resource;/*** @author alan.wang*/
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {@Resourceprivate AuthenticationManager authenticationManager;@Autowiredprivate UserDetailsService userDetailsService;/*** @desc :注入client 相关内如,内存模式直接注入模拟的一个client端* withClient :clientId* secret: clientId对应密码,记得spring5.0之后前面要加上{加密方式}密文* authorizedGrantTypes:接受哪些授权模式,参数 grant_type 区分* authorities:具有哪些权限,一般针对api级别,基本没用上* scopes:读写级别* */@Overridepublic void configure(ClientDetailsServiceConfigurer clients) throws Exception {clients.inMemory().withClient("test-auth-client").secret("{bcrypt}" + new BCryptPasswordEncoder().encode("123")).authorizedGrantTypes("authorization_code", "refresh_token", "client_credentials", "password").authorities("autho2").scopes("read", "write");}/*** @desc: 设置auth2.0本身开放的访问权限* 这里对/oauth/check_token 开放了表单提交权限*/@Overridepublic void configure(AuthorizationServerSecurityConfigurer security) throws Exception {security.checkTokenAccess("permitAll()").allowFormAuthenticationForClients();}/*** @desc: 主要是对endpoints(框架本身的url路径)注入自定义service* 这里对注入了默认的userDetailsService,authenticationManager,*/@Overridepublic void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {endpoints.allowedTokenEndpointRequestMethods(HttpMethod.GET, HttpMethod.POST).userDetailsService(userDetailsService).authenticationManager(authenticationManager);}}

 

SecurityConfig.java
package com.minicloud.authentication.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;/*** @Author alan.wang* @date: 2022-01-17 14:01*/@Configuration
@EnableWebSecuritypublic class SecurityConfig extends WebSecurityConfigurerAdapter {/*** @desc:对本web 服务的url拦截设置* 这里开放了所有/oauth/** 的权限,因为是框架的路径* */@Overridepublic void configure(HttpSecurity http) throws Exception {http.requestMatchers().anyRequest().and().authorizeRequests().antMatchers("/oauth/**").permitAll();}/*** @desc:注入默认的AuthenticationManager bean*/@Override@Beanpublic AuthenticationManager authenticationManagerBean() throws Exception {return super.authenticationManagerBean();}/*** @desc:注入默认的UserDetailsService bean 并添加两个测试用户* username:用户名* password:密码,同样注意标明{加密方式}密文* roles:角色,可以实多个**/@Beanpublic UserDetailsService userDetailsService()   {InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();manager.createUser(User.builder().username("user1").password("{bcrypt}" + new BCryptPasswordEncoder().encode("123")).roles("USER").build());manager.createUser(User.builder().username("admin").password("{bcrypt}" + new BCryptPasswordEncoder().encode("123")).roles("USER", "ADMIN").build());return manager;}/*** @desc:注入 PasswordEncoder 加密器* PasswordEncoderFactories.createDelegatingPasswordEncoder() 默认为bcrypt 加密**/@Beanpublic PasswordEncoder passwordEncoder() {return PasswordEncoderFactories.createDelegatingPasswordEncoder();}}

代码添加完毕之后重启认证中心服务来验证一下

我用的是user1 ,记得clientId 和密码都对应上,

http://localhost:8800/oauth/token?username=user1&password=123&grant_type=password&scope=read&client_id=test-auth-client&client_secret=123

ok,看见已经正常返回 access_token,与reflush_token ,开始进行下一步

5.添加测试服务module 并集成如spring cloud nacos 中

为了方便,我单独创建一个test module 里面放置所有测试服务相关的服务,为了便于以后测试微服务整体业务,也将测试服务作为一个业务端服务纳入spring cloud nacos

好了我们创建一个测试业务端用来当作资源服务进行整合测试,集成进入spring cloud nacos与上面认证中心集成是一样的,就不多说

application.yml

server:port: 8900spring:application:name: @artifactId@cloud:nacos:discovery:server-addr: ${NACOS_HOST:127.0.0.1}:${NACOS_PORT:8848}config:server-addr: ${spring.cloud.nacos.discovery.server-addr}file-extension: ymlshared-configs:- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}profiles:active: @profiles.active@

 pom.xml

<?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"><parent><artifactId>mini-cloud-tester</artifactId><groupId>org.mini-cloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>authentication-center-test</artifactId><dependencies><!--web 模块--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--注册中心客户端--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!--配置中心客户端--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><!--安全模块 --><dependency><groupId>org.springframework.security.oauth</groupId><artifactId>spring-security-oauth2</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency><dependency><groupId>org.springframework.security.oauth.boot</groupId><artifactId>spring-security-oauth2-autoconfigure</artifactId></dependency></dependencies>
</project>

然后全部启动,看看是否都集成入了nacos

进入nacos 控制台查看 http://localhost:8848/nacos/

ok,也都没问题,开始将他作为资源服务进行集成

6.测试服务 作为resource server 进行认证测试

对resource server 集成比较简单,只需要继承ResourceServerConfigurerAdapter,然后开启

@EnableResourceServer 即可 ,然后我们创建一个controller ,对该controller url进行校验

ResourceServerConfig.java
package com.minicloud.authentication.test.config;import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;/*** @Author alan.wang* @date: 2022-01-17 16:26*/
@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {/*** @desc: 设置需要拦截或者开放的url* 这里开放了/oauth/** 框架本身的url* 对/test/** 相关需要进行认证* */@Overridepublic void configure(HttpSecurity httpSecurity) throws Exception {httpSecurity.authorizeRequests().antMatchers("/oauth/**").permitAll().antMatchers("/test/**").authenticated();}
}

 

TestController.java
package com.minicloud.authentication.test.controller;import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** @Author alan.wang* @date: 2022-01-17 15:54*/
@RestController
@RequestMapping("/test")
public class TestController {@GetMapping("/hello")public ResponseEntity hello(){return ResponseEntity.ok("ok");}
}

application.yml

server:port: 8900spring:application:name: @artifactId@cloud:nacos:discovery:server-addr: ${NACOS_HOST:127.0.0.1}:${NACOS_PORT:8848}config:server-addr: ${spring.cloud.nacos.discovery.server-addr}file-extension: ymlshared-configs:- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}profiles:active: @profiles.active@security:oauth2:resource:token-info-uri: http://127.0.0.1:8800/oauth/check_tokenclient:client-id: test-auth-clientclient-secret: 123scope: read

 注意:token-info-uri: 这个是我们认证中心的地址

我们重启test 服务,然后启动测试,我们首先直接访问我们的测试controller url

http://localhost:8900/test/hello 

 

{
    "error": "unauthorized",
    "error_description": "Full authentication is required to access this resource"
}

提示很明显,需要提供访问认证

我们现在获取一下access_token

http://localhost:8800/oauth/token?username=user1&password=123&grant_type=password&scope=read&client_id=test-auth-client&client_secret=123

{
    "access_token": "6ee98a60-19c6-4843-9f77-954024bc2d9b",
    "token_type": "bearer",
    "refresh_token": "b6bf88c0-1128-4742-af8a-74bc513b7d9b",
    "expires_in": 41459,
    "scope": "read"
}

我们拿到access_token ,然后再访问http://localhost:8900/test/hello

这次正常可以访问资源的url了 ,注意access_token前要加bearer

篇幅太长,本文到此就结束了,我们现在都是在内存环境集成的,真实开发肯定不是这样的,我们一步步来, 下篇我们将内存式变为从redis 和数据库获取数据,达到真实框架能力

 

 

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

相关文章

  1. List、Map、Set三个接口,存取元素时,各有什么特点?

    这样的题属于随意发挥题&#xff1a;这样的题比较考水平&#xff0c;两个方面的水平&#xff1a;一是要真正明白这些内容&#xff0c;二是要有较强的总结和表述能力。如果你明白&#xff0c;但表述不清楚&#xff0c;在别人那里则等同于不明白。 首先&#xff0c;List与Set具有…...

    2024/5/4 18:43:19
  2. acwingC++语法基础课第四课判断语句的习题练习游戏时间 加薪 动物657. 选择练习1 671. DDD

    667. 游戏时间 题目 提交记录 讨论 题解 视频讲解 读取两个整数 A 和 B,表示游戏的开始时间和结束时间,以小时为单位。 然后请你计算游戏的持续时间,已知游戏可以在一天开始并在另一天结束,最长持续时间为 24 小时。 如果 A 与 B 相等,则视为持续了 24 小时。 输入格…...

    2024/4/14 16:31:46
  3. 鸿蒙应用开发培训笔记04:04 UI页面设计与开发

    文章目录零、本讲学习目标一、Java UI开发&#xff08;一&#xff09;Java UI概述1、用户界面是如何构建的&#xff1f;2、组件树&#xff08;1&#xff09;Component&#xff1a;组件&#xff08;2&#xff09;ComponentContainer&#xff1a;布局容器&#xff08;3&#xff0…...

    2024/5/4 20:00:51
  4. 全球与中国户外通信柜市场现状及未来发展趋势2022

    根据QYR&#xff08;恒州博智&#xff09;的统计及预测&#xff0c;2021年全球户外通信柜市场销售额达到了 亿美元&#xff0c;预计2028年将达到 亿美元&#xff0c;年复合增长率&#xff08;CAGR&#xff09;为 %&#xff08;2022-2028&#xff09;。地区层面来看&#xff0c;…...

    2024/4/14 16:32:57
  5. VS2010中的自动化测试(6)——Web性能测试(3)

    事务(Transaction) 我们可以划分一批请求组合成一个事务&#xff0c;然后我们就可以跟踪分析这个事务请求所花费的总体时间了。 事务可以通过简单的指定开始的request和结束的request来设定。 在Root节点右键鼠标&#xff0c;选择Add Transaction…点击。 然后在弹出的对话框…...

    2024/5/4 15:45:52
  6. LeetCode|633. 平方数之和

    633. 平方数之和 难度中等 给定一个非负整数 c &#xff0c;你要判断是否存在两个整数 a 和 b&#xff0c;使得 a2 b2 c 。 示例 1&#xff1a; 输入&#xff1a;c 5 输出&#xff1a;true 解释&#xff1a;1 * 1 2 * 2 5示例 2&#xff1a; 输入&#xff1a;c 3 输出…...

    2024/4/17 21:23:35
  7. 蓝桥杯 基础练习 十六进制转八进制

    资源限制 时间限制&#xff1a;1.0s 内存限制&#xff1a;512.0MB 问题描述   给定n个十六进制正整数&#xff0c;输出它们对应的八进制数。输入格式   输入的第一行为一个正整数n &#xff08;1<n<10&#xff09;。   接下来n行&#xff0c;每行一个由0~9、大写…...

    2024/5/4 23:35:36
  8. 浅谈tcp的半打开连接

    tcp连接一端在进行完三次握手以后进入ESTABLISHED状态&#xff0c;如果连接的对端在某一时刻在网络中消失&#xff0c;而本端没有感知到&#xff0c;还是处于ESTABLISHED状态&#xff0c;那么本端的连接就被称为半打开连接(Half Open)。 连接的对端在网络中消失的情况有好多&a…...

    2024/4/17 17:08:46
  9. 面试官问,Redis 是单线程还是多线程?我懵了

    我们平时看到介绍 Redis 的文章&#xff0c;都会说 Redis 是单线程的。但是我们学习的时候&#xff0c;比如 Redis 的 bgsave 命令&#xff0c;它的作用是在后台异步保存当前数据库的数据到磁盘&#xff0c;那既然是异步了&#xff0c;肯定是由别的线程去完成的&#xff0c;这怎…...

    2024/4/7 4:29:49
  10. python多进程/进程池/进程间共享数据实用场景分析和实践踩坑记录

    我们都知道&#xff0c;python这门语言比C慢主要有两个原因&#xff0c;一是python是动态类型语言&#xff0c;需要边解释边执行&#xff0c;二是全局解释其锁&#xff08;GIL&#xff09;的存在&#xff0c;让python无法利用多核CPU并发执行。 对于第一点是语言本身决定的&am…...

    2024/4/20 13:10:08
  11. 他的目的是什么?

    这么高的位置&#xff0c;从底部3块多&#xff0c;到现在快一百元了&#xff0c;今天稍微这点回调&#xff0c;就发文号召大家买&#xff0c;他的目的是什么&#xff1f;让他的数万粉丝给他接货嘛&#xff1f;会不会有人信直接去山岗上为他站岗&#xff1f;...

    2024/5/4 23:50:27
  12. 搭建一个 软件授权码管理系统

    今天来搭建一个适用于PHP 应用程序、WordPress 插件或主题等。凭借易于安装、最低服务器要求、用户友好的 UI 和无限脚本的成熟授权码和更新管理器。 软件授权码管理系统由两部分组成 - 将安装在您自己的服务器上的主脚本&#xff08;管理面板&#xff09;和将包含在您的 PHP 应…...

    2024/4/20 7:05:08
  13. wdcp系统mysql、php升级以及常见组件安装

    安装以下脚本时&#xff0c;请注意服务器内是否有安装云锁&#xff0c;安装前请先卸载或者停止服务&#xff08;教程&#xff09; 一、php版本升级 wdcp V2.5及wdcp V3.2版本下apache模式下使用的php升级。适用升级到5.4--7.2升级。ssh登陆以后复制以下命令&#xff0c;回车执…...

    2024/5/4 15:27:44
  14. c++笔记:容器简单应用

    一.迭代器 迭代器模式 相当于指向容器的指针 定义迭代器 类名<参数列表>&#xff1a;&#xff1a; iterator 名字 对象.begin(); 内部重载了* -> 可以向指针一样使用 二.array与vector array<T,N> 对象名 //相当于数组&#xff0c;但是比数组更安全…...

    2024/4/14 16:32:22
  15. kubectl、kuboard两种方式在集群中部署应用

    kuboard安装 K8S集群安装完毕后&#xff0c;kuboard的安装非常简单&#xff0c;在master节点执行命令&#xff1a; docker run -d \--restartunless-stopped \--namekuboard \-p 8081:80/tcp \-p 10081:10081/tcp \-e KUBOARD_ENDPOINT"http://192.188.1.241:8081"…...

    2024/4/25 20:08:42
  16. 郭宇,28岁,财富自由,提前退休

    1 今年2月12日&#xff0c;我在朋友圈和微博发了一封信&#xff0c;信里说&#xff0c;我选择在28岁的末尾退休&#xff0c;离开任职6年的字节跳动&#xff0c;去日本旅居。用「退休」而不是「辞职」&#xff0c;是因为我要跟互联网行业彻底告别。 6月&#xff0c;突然很多人…...

    2024/4/19 20:31:18
  17. ActiveMQ 反序列化漏洞 (CVE-2015-5254)

    漏洞简介 Apache ActiveMQ 是由美国 Pachitea&#xff08;Apache&#xff09;软件基金会开发的开源消息中间件&#xff0c;支持 Java 消息服务、集群、Spring 框架等。 Apache ActiveMQ 5.x版本之前的5.13.0安全漏洞&#xff0c;该程序造成的漏洞不限制代理中可以序列化的类。…...

    2024/4/16 5:18:07
  18. STM输入输出模式概略

    输入浮空&#xff1a;浮空就是逻辑器件与引脚即不接高电平&#xff0c;也不接低电平。 输入上拉模式&#xff1a;上拉就是把点位拉高&#xff0c;比如拉到Vcc&#xff08;上拉就是将不确定的信号通过一个电阻嵌位在高电平。电阻同时起到限流的作用 输入下拉&#xff1a;就是把…...

    2024/4/26 22:51:53
  19. 全球与中国工业洁净室市场现状及未来发展趋势2022

    根据QYR&#xff08;恒州博智&#xff09;的统计及预测&#xff0c;2021年全球工业洁净室市场销售额达到了 亿美元&#xff0c;预计2028年将达到 亿美元&#xff0c;年复合增长率&#xff08;CAGR&#xff09;为 %&#xff08;2022-2028&#xff09;。地区层面来看&#xff0c;…...

    2024/4/19 17:10:03
  20. 37、Flutter之TabBarView组件

    TabBarView 是 Material 组件库中提供了 Tab 布局组件&#xff0c;通常和 TabBar 配合使用。 TabBarView TabBarView 封装了 PageView&#xff0c;它的构造方法很简单 TabBarView({Key? key,required this.children, // tab 页this.controller, // TabControllerthis.physics…...

    2024/4/28 22:16:35

最新文章

  1. 应用分层和企业规范

    目录 一、应用分层 1、介绍 &#xff08;1&#xff09;为什么需要应用分层&#xff1f; &#xff08;2&#xff09;如何分层&#xff1f;&#xff08;三层架构&#xff09; MVC 和 三层架构的区别和联系 高内聚&#xff1a; 低耦合&#xff1a; 2、代码重构 controlle…...

    2024/5/4 23:59:23
  2. 梯度消失和梯度爆炸的一些处理方法

    在这里是记录一下梯度消失或梯度爆炸的一些处理技巧。全当学习总结了如有错误还请留言&#xff0c;在此感激不尽。 权重和梯度的更新公式如下&#xff1a; w w − η ⋅ ∇ w w w - \eta \cdot \nabla w ww−η⋅∇w 个人通俗的理解梯度消失就是网络模型在反向求导的时候出…...

    2024/3/20 10:50:27
  3. 腾讯云轻量服务器流量不够用了会怎么样?

    腾讯云轻量应用服务器是限制月流量的&#xff0c;如果当月流量不够用了&#xff0c;流量超额了怎么办&#xff1f;流量超额后&#xff0c;需要另外支付流量费&#xff0c;如果你的腾讯云账号余额&#xff0c;就会自动扣除对应的流量费&#xff0c;如果余额不足&#xff0c;轻量…...

    2024/5/1 13:01:36
  4. 在 Visual Studio Code (VSCode) 中隐藏以 . 开头的文件

    打开VSCode。 按下Ctrl ,快捷键打开设置。您也可以点击屏幕左下角的齿轮图标&#xff0c;然后选择“Settings”。 在设置搜索框中&#xff0c;键入files.exclude。 在找到的Files: Exclude项中&#xff0c;点击Add Pattern按钮来添加一个新的模式&#xff0c;或者直接在搜索…...

    2024/5/2 2:37:00
  5. 【外汇早评】美通胀数据走低,美元调整

    原标题:【外汇早评】美通胀数据走低,美元调整昨日美国方面公布了新一期的核心PCE物价指数数据,同比增长1.6%,低于前值和预期值的1.7%,距离美联储的通胀目标2%继续走低,通胀压力较低,且此前美国一季度GDP初值中的消费部分下滑明显,因此市场对美联储后续更可能降息的政策…...

    2024/5/4 23:54:56
  6. 【原油贵金属周评】原油多头拥挤,价格调整

    原标题:【原油贵金属周评】原油多头拥挤,价格调整本周国际劳动节,我们喜迎四天假期,但是整个金融市场确实流动性充沛,大事频发,各个商品波动剧烈。美国方面,在本周四凌晨公布5月份的利率决议和新闻发布会,维持联邦基金利率在2.25%-2.50%不变,符合市场预期。同时美联储…...

    2024/5/4 23:54:56
  7. 【外汇周评】靓丽非农不及疲软通胀影响

    原标题:【外汇周评】靓丽非农不及疲软通胀影响在刚结束的周五,美国方面公布了新一期的非农就业数据,大幅好于前值和预期,新增就业重新回到20万以上。具体数据: 美国4月非农就业人口变动 26.3万人,预期 19万人,前值 19.6万人。 美国4月失业率 3.6%,预期 3.8%,前值 3…...

    2024/5/4 23:54:56
  8. 【原油贵金属早评】库存继续增加,油价收跌

    原标题:【原油贵金属早评】库存继续增加,油价收跌周三清晨公布美国当周API原油库存数据,上周原油库存增加281万桶至4.692亿桶,增幅超过预期的74.4万桶。且有消息人士称,沙特阿美据悉将于6月向亚洲炼油厂额外出售更多原油,印度炼油商预计将每日获得至多20万桶的额外原油供…...

    2024/5/4 23:55:17
  9. 【外汇早评】日本央行会议纪要不改日元强势

    原标题:【外汇早评】日本央行会议纪要不改日元强势近两日日元大幅走强与近期市场风险情绪上升,避险资金回流日元有关,也与前一段时间的美日贸易谈判给日本缓冲期,日本方面对汇率问题也避免继续贬值有关。虽然今日早间日本央行公布的利率会议纪要仍然是支持宽松政策,但这符…...

    2024/5/4 23:54:56
  10. 【原油贵金属早评】欧佩克稳定市场,填补伊朗问题的影响

    原标题:【原油贵金属早评】欧佩克稳定市场,填补伊朗问题的影响近日伊朗局势升温,导致市场担忧影响原油供给,油价试图反弹。此时OPEC表态稳定市场。据消息人士透露,沙特6月石油出口料将低于700万桶/日,沙特已经收到石油消费国提出的6月份扩大出口的“适度要求”,沙特将满…...

    2024/5/4 23:55:05
  11. 【外汇早评】美欲与伊朗重谈协议

    原标题:【外汇早评】美欲与伊朗重谈协议美国对伊朗的制裁遭到伊朗的抗议,昨日伊朗方面提出将部分退出伊核协议。而此行为又遭到欧洲方面对伊朗的谴责和警告,伊朗外长昨日回应称,欧洲国家履行它们的义务,伊核协议就能保证存续。据传闻伊朗的导弹已经对准了以色列和美国的航…...

    2024/5/4 23:54:56
  12. 【原油贵金属早评】波动率飙升,市场情绪动荡

    原标题:【原油贵金属早评】波动率飙升,市场情绪动荡因中美贸易谈判不安情绪影响,金融市场各资产品种出现明显的波动。随着美国与中方开启第十一轮谈判之际,美国按照既定计划向中国2000亿商品征收25%的关税,市场情绪有所平复,已经开始接受这一事实。虽然波动率-恐慌指数VI…...

    2024/5/4 23:55:16
  13. 【原油贵金属周评】伊朗局势升温,黄金多头跃跃欲试

    原标题:【原油贵金属周评】伊朗局势升温,黄金多头跃跃欲试美国和伊朗的局势继续升温,市场风险情绪上升,避险黄金有向上突破阻力的迹象。原油方面稍显平稳,近期美国和OPEC加大供给及市场需求回落的影响,伊朗局势并未推升油价走强。近期中美贸易谈判摩擦再度升级,美国对中…...

    2024/5/4 23:54:56
  14. 【原油贵金属早评】市场情绪继续恶化,黄金上破

    原标题:【原油贵金属早评】市场情绪继续恶化,黄金上破周初中国针对于美国加征关税的进行的反制措施引发市场情绪的大幅波动,人民币汇率出现大幅的贬值动能,金融市场受到非常明显的冲击。尤其是波动率起来之后,对于股市的表现尤其不安。隔夜美国股市出现明显的下行走势,这…...

    2024/5/4 18:20:48
  15. 【外汇早评】美伊僵持,风险情绪继续升温

    原标题:【外汇早评】美伊僵持,风险情绪继续升温昨日沙特两艘油轮再次发生爆炸事件,导致波斯湾局势进一步恶化,市场担忧美伊可能会出现摩擦生火,避险品种获得支撑,黄金和日元大幅走强。美指受中美贸易问题影响而在低位震荡。继5月12日,四艘商船在阿联酋领海附近的阿曼湾、…...

    2024/5/4 23:54:56
  16. 【原油贵金属早评】贸易冲突导致需求低迷,油价弱势

    原标题:【原油贵金属早评】贸易冲突导致需求低迷,油价弱势近日虽然伊朗局势升温,中东地区几起油船被袭击事件影响,但油价并未走高,而是出于调整结构中。由于市场预期局势失控的可能性较低,而中美贸易问题导致的全球经济衰退风险更大,需求会持续低迷,因此油价调整压力较…...

    2024/5/4 23:55:17
  17. 氧生福地 玩美北湖(上)——为时光守候两千年

    原标题:氧生福地 玩美北湖(上)——为时光守候两千年一次说走就走的旅行,只有一张高铁票的距离~ 所以,湖南郴州,我来了~ 从广州南站出发,一个半小时就到达郴州西站了。在动车上,同时改票的南风兄和我居然被分到了一个车厢,所以一路非常愉快地聊了过来。 挺好,最起…...

    2024/5/4 23:55:06
  18. 氧生福地 玩美北湖(中)——永春梯田里的美与鲜

    原标题:氧生福地 玩美北湖(中)——永春梯田里的美与鲜一觉醒来,因为大家太爱“美”照,在柳毅山庄去寻找龙女而错过了早餐时间。近十点,向导坏坏还是带着饥肠辘辘的我们去吃郴州最富有盛名的“鱼头粉”。说这是“十二分推荐”,到郴州必吃的美食之一。 哇塞!那个味美香甜…...

    2024/5/4 23:54:56
  19. 氧生福地 玩美北湖(下)——奔跑吧骚年!

    原标题:氧生福地 玩美北湖(下)——奔跑吧骚年!让我们红尘做伴 活得潇潇洒洒 策马奔腾共享人世繁华 对酒当歌唱出心中喜悦 轰轰烈烈把握青春年华 让我们红尘做伴 活得潇潇洒洒 策马奔腾共享人世繁华 对酒当歌唱出心中喜悦 轰轰烈烈把握青春年华 啊……啊……啊 两…...

    2024/5/4 23:55:06
  20. 扒开伪装医用面膜,翻六倍价格宰客,小姐姐注意了!

    原标题:扒开伪装医用面膜,翻六倍价格宰客,小姐姐注意了!扒开伪装医用面膜,翻六倍价格宰客!当行业里的某一品项火爆了,就会有很多商家蹭热度,装逼忽悠,最近火爆朋友圈的医用面膜,被沾上了污点,到底怎么回事呢? “比普通面膜安全、效果好!痘痘、痘印、敏感肌都能用…...

    2024/5/4 2:59:34
  21. 「发现」铁皮石斛仙草之神奇功效用于医用面膜

    原标题:「发现」铁皮石斛仙草之神奇功效用于医用面膜丽彦妆铁皮石斛医用面膜|石斛多糖无菌修护补水贴19大优势: 1、铁皮石斛:自唐宋以来,一直被列为皇室贡品,铁皮石斛生于海拔1600米的悬崖峭壁之上,繁殖力差,产量极低,所以古代仅供皇室、贵族享用 2、铁皮石斛自古民间…...

    2024/5/4 23:55:16
  22. 丽彦妆\医用面膜\冷敷贴轻奢医学护肤引导者

    原标题:丽彦妆\医用面膜\冷敷贴轻奢医学护肤引导者【公司简介】 广州华彬企业隶属香港华彬集团有限公司,专注美业21年,其旗下品牌: 「圣茵美」私密荷尔蒙抗衰,产后修复 「圣仪轩」私密荷尔蒙抗衰,产后修复 「花茵莳」私密荷尔蒙抗衰,产后修复 「丽彦妆」专注医学护…...

    2024/5/4 23:54:58
  23. 广州械字号面膜生产厂家OEM/ODM4项须知!

    原标题:广州械字号面膜生产厂家OEM/ODM4项须知!广州械字号面膜生产厂家OEM/ODM流程及注意事项解读: 械字号医用面膜,其实在我国并没有严格的定义,通常我们说的医美面膜指的应该是一种「医用敷料」,也就是说,医用面膜其实算作「医疗器械」的一种,又称「医用冷敷贴」。 …...

    2024/5/4 23:55:01
  24. 械字号医用眼膜缓解用眼过度到底有无作用?

    原标题:械字号医用眼膜缓解用眼过度到底有无作用?医用眼膜/械字号眼膜/医用冷敷眼贴 凝胶层为亲水高分子材料,含70%以上的水分。体表皮肤温度传导到本产品的凝胶层,热量被凝胶内水分子吸收,通过水分的蒸发带走大量的热量,可迅速地降低体表皮肤局部温度,减轻局部皮肤的灼…...

    2024/5/4 23:54:56
  25. 配置失败还原请勿关闭计算机,电脑开机屏幕上面显示,配置失败还原更改 请勿关闭计算机 开不了机 这个问题怎么办...

    解析如下&#xff1a;1、长按电脑电源键直至关机&#xff0c;然后再按一次电源健重启电脑&#xff0c;按F8健进入安全模式2、安全模式下进入Windows系统桌面后&#xff0c;按住“winR”打开运行窗口&#xff0c;输入“services.msc”打开服务设置3、在服务界面&#xff0c;选中…...

    2022/11/19 21:17:18
  26. 错误使用 reshape要执行 RESHAPE,请勿更改元素数目。

    %读入6幅图像&#xff08;每一幅图像的大小是564*564&#xff09; f1 imread(WashingtonDC_Band1_564.tif); subplot(3,2,1),imshow(f1); f2 imread(WashingtonDC_Band2_564.tif); subplot(3,2,2),imshow(f2); f3 imread(WashingtonDC_Band3_564.tif); subplot(3,2,3),imsho…...

    2022/11/19 21:17:16
  27. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机...

    win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”问题的解决方法在win7系统关机时如果有升级系统的或者其他需要会直接进入一个 等待界面&#xff0c;在等待界面中我们需要等待操作结束才能关机&#xff0c;虽然这比较麻烦&#xff0c;但是对系统进行配置和升级…...

    2022/11/19 21:17:15
  28. 台式电脑显示配置100%请勿关闭计算机,“准备配置windows 请勿关闭计算机”的解决方法...

    有不少用户在重装Win7系统或更新系统后会遇到“准备配置windows&#xff0c;请勿关闭计算机”的提示&#xff0c;要过很久才能进入系统&#xff0c;有的用户甚至几个小时也无法进入&#xff0c;下面就教大家这个问题的解决方法。第一种方法&#xff1a;我们首先在左下角的“开始…...

    2022/11/19 21:17:14
  29. win7 正在配置 请勿关闭计算机,怎么办Win7开机显示正在配置Windows Update请勿关机...

    置信有很多用户都跟小编一样遇到过这样的问题&#xff0c;电脑时发现开机屏幕显现“正在配置Windows Update&#xff0c;请勿关机”(如下图所示)&#xff0c;而且还需求等大约5分钟才干进入系统。这是怎样回事呢&#xff1f;一切都是正常操作的&#xff0c;为什么开时机呈现“正…...

    2022/11/19 21:17:13
  30. 准备配置windows 请勿关闭计算机 蓝屏,Win7开机总是出现提示“配置Windows请勿关机”...

    Win7系统开机启动时总是出现“配置Windows请勿关机”的提示&#xff0c;没过几秒后电脑自动重启&#xff0c;每次开机都这样无法进入系统&#xff0c;此时碰到这种现象的用户就可以使用以下5种方法解决问题。方法一&#xff1a;开机按下F8&#xff0c;在出现的Windows高级启动选…...

    2022/11/19 21:17:12
  31. 准备windows请勿关闭计算机要多久,windows10系统提示正在准备windows请勿关闭计算机怎么办...

    有不少windows10系统用户反映说碰到这样一个情况&#xff0c;就是电脑提示正在准备windows请勿关闭计算机&#xff0c;碰到这样的问题该怎么解决呢&#xff0c;现在小编就给大家分享一下windows10系统提示正在准备windows请勿关闭计算机的具体第一种方法&#xff1a;1、2、依次…...

    2022/11/19 21:17:11
  32. 配置 已完成 请勿关闭计算机,win7系统关机提示“配置Windows Update已完成30%请勿关闭计算机”的解决方法...

    今天和大家分享一下win7系统重装了Win7旗舰版系统后&#xff0c;每次关机的时候桌面上都会显示一个“配置Windows Update的界面&#xff0c;提示请勿关闭计算机”&#xff0c;每次停留好几分钟才能正常关机&#xff0c;导致什么情况引起的呢&#xff1f;出现配置Windows Update…...

    2022/11/19 21:17:10
  33. 电脑桌面一直是清理请关闭计算机,windows7一直卡在清理 请勿关闭计算机-win7清理请勿关机,win7配置更新35%不动...

    只能是等着&#xff0c;别无他法。说是卡着如果你看硬盘灯应该在读写。如果从 Win 10 无法正常回滚&#xff0c;只能是考虑备份数据后重装系统了。解决来方案一&#xff1a;管理员运行cmd&#xff1a;net stop WuAuServcd %windir%ren SoftwareDistribution SDoldnet start WuA…...

    2022/11/19 21:17:09
  34. 计算机配置更新不起,电脑提示“配置Windows Update请勿关闭计算机”怎么办?

    原标题&#xff1a;电脑提示“配置Windows Update请勿关闭计算机”怎么办&#xff1f;win7系统中在开机与关闭的时候总是显示“配置windows update请勿关闭计算机”相信有不少朋友都曾遇到过一次两次还能忍但经常遇到就叫人感到心烦了遇到这种问题怎么办呢&#xff1f;一般的方…...

    2022/11/19 21:17:08
  35. 计算机正在配置无法关机,关机提示 windows7 正在配置windows 请勿关闭计算机 ,然后等了一晚上也没有关掉。现在电脑无法正常关机...

    关机提示 windows7 正在配置windows 请勿关闭计算机 &#xff0c;然后等了一晚上也没有关掉。现在电脑无法正常关机以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;关机提示 windows7 正在配…...

    2022/11/19 21:17:05
  36. 钉钉提示请勿通过开发者调试模式_钉钉请勿通过开发者调试模式是真的吗好不好用...

    钉钉请勿通过开发者调试模式是真的吗好不好用 更新时间:2020-04-20 22:24:19 浏览次数:729次 区域: 南阳 > 卧龙 列举网提醒您:为保障您的权益,请不要提前支付任何费用! 虚拟位置外设器!!轨迹模拟&虚拟位置外设神器 专业用于:钉钉,外勤365,红圈通,企业微信和…...

    2022/11/19 21:17:05
  37. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...

    前几天班里有位学生电脑(windows 7系统)出问题了&#xff0c;具体表现是开机时一直停留在“配置windows update失败 还原更改 请勿关闭计算机”这个界面&#xff0c;长时间没反应&#xff0c;无法进入系统。这个问题原来帮其他同学也解决过&#xff0c;网上搜了不少资料&#x…...

    2022/11/19 21:17:04
  38. 一个电脑无法关闭计算机你应该怎么办,电脑显示“清理请勿关闭计算机”怎么办?...

    本文为你提供了3个有效解决电脑显示“清理请勿关闭计算机”问题的方法&#xff0c;并在最后教给你1种保护系统安全的好方法&#xff0c;一起来看看&#xff01;电脑出现“清理请勿关闭计算机”在Windows 7(SP1)和Windows Server 2008 R2 SP1中&#xff0c;添加了1个新功能在“磁…...

    2022/11/19 21:17:03
  39. 请勿关闭计算机还原更改要多久,电脑显示:配置windows更新失败,正在还原更改,请勿关闭计算机怎么办...

    许多用户在长期不使用电脑的时候&#xff0c;开启电脑发现电脑显示&#xff1a;配置windows更新失败&#xff0c;正在还原更改&#xff0c;请勿关闭计算机。。.这要怎么办呢&#xff1f;下面小编就带着大家一起看看吧&#xff01;如果能够正常进入系统&#xff0c;建议您暂时移…...

    2022/11/19 21:17:02
  40. 还原更改请勿关闭计算机 要多久,配置windows update失败 还原更改 请勿关闭计算机,电脑开机后一直显示以...

    配置windows update失败 还原更改 请勿关闭计算机&#xff0c;电脑开机后一直显示以以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容&#xff0c;让我们赶快一起来看一下吧&#xff01;配置windows update失败 还原更改 请勿关闭计算机&#x…...

    2022/11/19 21:17:01
  41. 电脑配置中请勿关闭计算机怎么办,准备配置windows请勿关闭计算机一直显示怎么办【图解】...

    不知道大家有没有遇到过这样的一个问题&#xff0c;就是我们的win7系统在关机的时候&#xff0c;总是喜欢显示“准备配置windows&#xff0c;请勿关机”这样的一个页面&#xff0c;没有什么大碍&#xff0c;但是如果一直等着的话就要两个小时甚至更久都关不了机&#xff0c;非常…...

    2022/11/19 21:17:00
  42. 正在准备配置请勿关闭计算机,正在准备配置windows请勿关闭计算机时间长了解决教程...

    当电脑出现正在准备配置windows请勿关闭计算机时&#xff0c;一般是您正对windows进行升级&#xff0c;但是这个要是长时间没有反应&#xff0c;我们不能再傻等下去了。可能是电脑出了别的问题了&#xff0c;来看看教程的说法。正在准备配置windows请勿关闭计算机时间长了方法一…...

    2022/11/19 21:16:59
  43. 配置失败还原请勿关闭计算机,配置Windows Update失败,还原更改请勿关闭计算机...

    我们使用电脑的过程中有时会遇到这种情况&#xff0c;当我们打开电脑之后&#xff0c;发现一直停留在一个界面&#xff1a;“配置Windows Update失败&#xff0c;还原更改请勿关闭计算机”&#xff0c;等了许久还是无法进入系统。如果我们遇到此类问题应该如何解决呢&#xff0…...

    2022/11/19 21:16:58
  44. 如何在iPhone上关闭“请勿打扰”

    Apple’s “Do Not Disturb While Driving” is a potentially lifesaving iPhone feature, but it doesn’t always turn on automatically at the appropriate time. For example, you might be a passenger in a moving car, but your iPhone may think you’re the one dri…...

    2022/11/19 21:16:57