此行有多个标记 - 不推荐使用 NoOpPasswordEncoder 类型 - 不推荐使用 NoOpPasswordEncoder 类型中的 getInstance() 方法

Jef*_*ook 6 spring single-sign-on spring-boot microservices spring-cloud

我正在研究 Spring Cloud + Boot 示例。在此示例中,我希望进行 SSO。当我运行这个应用程序时,我得到了很好的响应,但看起来像

此行有多个标记 - 不推荐使用 NoOpPasswordEncoder 类型 - 不推荐使用 NoOpPasswordEncoder 类型中的 getInstance() 方法

应用程序属性

server.port: 9000
server.servlet.context-path: /services
security.oauth2.client.clientId: pluralsight
security.oauth2.client.clientSecret: pluralsightsecret
security.oauth2.client.authorized-grant-types: authorization_code,refresh_token,password,client_credentials
security.oauth2.client.scope:toll_read,toll_report
Run Code Online (Sandbox Code Playgroud)

服务配置.java

@Configuration
public class ServiceConfig extends GlobalAuthenticationConfigurerAdapter {

    @Override
    public void init(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
            .passwordEncoder(NoOpPasswordEncoder.getInstance())
            .withUser("agoldberg").password("pass1").roles("USER")
            .and()
            .withUser("bgoldberg").password("pass2").roles("USER", "OPERATOR");
    }
}
Run Code Online (Sandbox Code Playgroud)

主要方法:

@SpringBootApplication
@EnableAuthorizationServer
public class PluralsightSpringcloudM4SecureauthserverApplication {

    public static void main(String[] args) {
        SpringApplication.run(PluralsightSpringcloudM4SecureauthserverApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

但是STS,显示错误。已弃用的方法的替代是什么?

在此输入图像描述

输出: 在此输入图像描述

Jef*_*ook 5

我能够使用下面的代码解决这个问题。我正在使用 Spring Boot 版本2.0.4.RELEASE。完毕 !

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configuration.GlobalAuthenticationConfigurerAdapter;

@Configuration
public class ServiceConfig extends GlobalAuthenticationConfigurerAdapter {

    @Override
    public void init(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
            .withUser("agoldberg").password("{noop}pass1").roles("USER")
            .and()
            .withUser("bgoldberg").password("{noop}pass2").roles("USER", "OPERATOR");
    }
}
Run Code Online (Sandbox Code Playgroud)