Я работаю над примером Spring Cloud + Boot. В этом примере я хочу использовать SSO. Когда я запускаю это приложение, я получаю ответ нормально, но похоже
Multiple markers at this line - The type NoOpPasswordEncoder is deprecated - The method getInstance() from the type NoOpPasswordEncoder is deprecated
application.properties
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
ServiceConfig.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");
}
}
MainMethod:
@SpringBootApplication
@EnableAuthorizationServer
public class PluralsightSpringcloudM4SecureauthserverApplication {
public static void main(String[] args) {
SpringApplication.run(PluralsightSpringcloudM4SecureauthserverApplication.class, args);
}
}
Но СТС показывает ошибку. Чем заменить устаревший метод?
Вы не должны использовать этот кодировщик паролей, потому что это небезопасно. Из официальные документы:
This PasswordEncoder is not secure. Instead use an adaptive one way function like BCryptPasswordEncoder, Pbkdf2PasswordEncoder, or SCryptPasswordEncoder. Even better use DelegatingPasswordEncoder which supports password upgrades.
Мне удалось решить эту проблему, используя приведенный ниже код. Я использую версию 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");
}
}
Не используйте NoOpPasswordEncoder. Ничего не делает. Вместо этого используйте: Pbkdf2PasswordEncoder, SCryptPasswordEncoder или BCryptPasswordEncoder. Я обычно использую BCryptPasswordEncoder.
Инициируется как bean-компонент:
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}