Spring Boot 2.0.0 + OAuth2

后端 未结 4 1898
迷失自我
迷失自我 2020-12-07 01:55

Does Spring Boot 2 + Sping Security OAuth2 still support the @AuthorizationServer annotation? From reading the release notes some things haven\'t been ported ov

4条回答
  •  无人及你
    2020-12-07 02:12

    Spring Security 5 uses a modernized password storage, see OAuth2 Autoconfig:

    If you use your own authorization server configuration to configure the list of valid clients through an instance of ClientDetailsServiceConfigurer as shown below, take note that the passwords you configure here are subject to the modernized password storage that came with Spring Security 5.

    To solve your problem, see Spring Security Reference:

    Troubleshooting

    The following error occurs when one of the passwords that are stored has no id as described in the section called “Password Storage Format”.

    java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
         at org.springframework.security.crypto.password.DelegatingPasswordEncoder$UnmappedIdPasswordEncoder.matches(DelegatingPasswordEncoder.java:233)
         at org.springframework.security.crypto.password.DelegatingPasswordEncoder.matches(DelegatingPasswordEncoder.java:196)
    

    The easiest way to resolve the error is to switch to explicitly provide the PasswordEncoder that you passwords are encoded with. The easiest way to resolve it is to figure out how your passwords are currently being stored and explicitly provide the correct PasswordEncoder. If you are migrating from Spring Security 4.2.x you can revert to the previous behavior by exposing a NoOpPasswordEncoder bean. For example, if you are using Java Configuration, you can create a configuration that looks like:

    Reverting to NoOpPasswordEncoder is not considered to be secure. You should instead migrate to using DelegatingPasswordEncoder to support secure password encoding.

    @Bean
    public static NoOpPasswordEncoder passwordEncoder() {
        return NoOpPasswordEncoder.getInstance();
    }
    

    if you are using XML configuration, you can expose a PasswordEncoder with the id passwordEncoder:

        class="org.springframework.security.crypto.NoOpPasswordEncoder" factory-method="getInstance"/>
    

    Alternatively, you can prefix all of your passwords with the correct id and continue to use DelegatingPasswordEncoder. For example, if you are using BCrypt, you would migrate your password from something like:

    $2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG
    

    to

    {bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG
    

提交回复
热议问题