文章目录
  1. 1. spring-cloud security+auth2集成问题
    1. 1.1. security4升级到5的问题
    2. 1.2. Encoded password does not look like BCrypt
    3. 1.3. Redis存储问题

spring-cloud security+auth2集成问题

网络上和官网的例子都是老版本的,集成到spring cloud的2.0之后的版本有很
多问题,在本人集成时遇到的问题都整理起来。

security4升级到5的问题

报错信息:

Spring Security 5 : There is no PasswordEncoder mapped for the id “null”
  • 原因:

security5之后不默认不允许不加密的密码和secret

  • 参考文章

https://stackoverflow.com/questions/49654143/spring-security-5-there-is-no-passwordencoder-mapped-for-the-id-null

  • 解决办法:

1, 添加password encoder

2, 设置密码时通过jsonFormat规则:{noop}secret

参考文章:

https://spring.io/blog/2017/11/01/spring-security-5-0-0-rc1-released#password-storage-format

Encoded password does not look like BCrypt

也是升级问题导致,输入参数不是一个加密的格式

参考文章

https://stackoverflow.com/questions/49582971/encoded-password-does-not-look-like-bcrypt

https://www.cnkirito.moe/spring-security-6/

Redis存储问题

报错信息:

NoSuchMethodError.RedisConnection.set([B[B)V issue

原因:
因为我是auth2.0的2.0.1的版本,2.x版本有一直有这个bug,直到Update spring-security-oauth2 to 2.3.3.RELEASE这个版本才fix掉

参考文章:
https://github.com/spring-projects/spring-security-oauth2-boot/issues/27

由于我是spring-cloud的方式集成的,我的maven pom.xml:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>

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

        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
            <version>1.16.18</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-oauth2</artifactId>
        </dependency>
    </dependencies>

解决办法:

  1. 将springboot的版本升级到:2.1.1.RELEASE
  2. 将spring-cloud版本升级到:Finchley.SR2

好了,再运行一遍,ok了。。。。。。

paste image

文章目录
  1. 1. spring-cloud security+auth2集成问题
    1. 1.1. security4升级到5的问题
    2. 1.2. Encoded password does not look like BCrypt
    3. 1.3. Redis存储问题