【问题标题】:microservices spring cloud, security, oauth2, Netflix OSS @EnableOAuth2Resource not exist in spring security 1.1微服务spring cloud,security,oauth2,Netflix OSS @EnableOAuth2Resource在spring security 1.1中不存在
【发布时间】:2017-02-03 01:45:25
【问题描述】:

我使用本教程http://callistaenterprise.se/blogg/teknik/2015/04/27/building-microservices-part-3-secure-APIs-with-OAuth/ 使用以下技术spring cloud、boot、security、oauth2 创建基于Netflix OSS 的有组织的webservices 项目。

我正在使用 spring security 1.1,我看到注释 @EnableOAuth2Resource 在 spring security 1.1 中不存在,我应该怎么做?

Maven 依赖项

<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>auctionblox</groupId>
<artifactId>auth-microservice</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<parent>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-parent</artifactId>
    <version>Brixton.RELEASE</version>
</parent>

<properties>
    <!-- Stand-alone RESTFul application for testing only -->
    <start-class>io.pivotal.microservices.services.Main</start-class>
</properties>

<dependencies>
    <dependency>
        <!-- Setup Spring Boot -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <!--<dependency>-->
        <!--&lt;!&ndash; Setup Spring MVC & REST, use Embedded Tomcat &ndash;&gt;-->
        <!--<groupId>org.springframework.boot</groupId>-->
        <!--<artifactId>spring-boot-starter-web</artifactId>-->
    <!--</dependency>-->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <dependency>
        <!-- Setup Spring Data common components -->
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
    </dependency>

    <dependency>
        <!-- Testing starter -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>

    <dependency>
        <!-- Setup Spring Data JPA Repository support -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-oauth2</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.security.oauth</groupId>
                <artifactId>spring-security-oauth2</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.security.oauth</groupId>
        <artifactId>spring-security-oauth2</artifactId>
        <version>2.0.10.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <dependency>
        <!-- Eureka service registration -->
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka-server</artifactId>
    </dependency>

    <dependency>
        <!-- Spring Cloud starter -->
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter</artifactId>
    </dependency>

    <dependency>
        <!-- In-memory database for testing/demos -->
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
    </dependency>





    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.39</version>
    </dependency>


</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>

【问题讨论】:

  • 什么是 Spring Security 1.1?分享你的依赖设置
  • @bilak 我的意思是 spring-cloud-security-1.1.0.RELEASE.jar。我更新了项目描述并添加了依赖项

标签: spring spring-mvc spring-security microservices


【解决方案1】:

使用@EnableResourceServer 代替@EnableOAuth2Resource

【讨论】:

    【解决方案2】:

    在 Spring Boot 1.2 中,我们必须将 Spring Cloud Security 用于 @EnableOAuth2Resource 注释。而在 Spring Boot 1.3 中,可以删除 Spring Cloud 依赖项,并将注释替换为 Spring Security OAuth2 中的 @EnableResourceServer 注释。

    更多详情:https://spring.io/blog/2015/11/30/migrating-oauth2-apps-from-spring-boot-1-2-to-1-3#resource-server

    【讨论】:

      猜你喜欢
      • 2014-12-27
      • 2019-04-29
      • 2019-09-25
      • 2020-11-06
      • 1970-01-01
      • 2015-09-07
      • 2020-07-04
      • 2017-03-31
      • 2015-09-27
      相关资源
      最近更新 更多