快速开始 - wzz-code/cloud-security-sample GitHub Wiki
在项目中开始使用spring-cloud-stream的推荐方法是使用依赖关系管理系统 - 下面的代码段可以复制并粘贴到您的构建中。需要帮忙?请参阅我们使用 Maven 和 Gradle 构建的入门指南。
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-security</artifactId>
<version>1.0.3.RELEASE</version>
</dependency>
</dependencies>
dependencies {
compile 'org.springframework.cloud:spring-cloud-security:1.0.3.RELEASE'
}
如果您的应用程序还有一个Spring Cloud Zuul嵌入式反向代理(使用@EnableZuulProxy),那么您可以要求它将OAuth2访问令牌转发到其代理的服务。因此,上面的SSO应用程序可以简单地像这样:
@SpringBootApplication
@EnableOAuth2Sso
@EnableZuulProxy
class Application {
}
并且它(除了记录用户并且获取令牌之外)将认证令牌向下传递到 /proxy/* 服务。如果这些服务用 @EnableResourceServer
实现,那么它们将在正确的头中获得一个有效的令牌。