Multiple markers at this line - The type NoOpPasswordEncoder is deprecated - The method getInstance() from the type NoOpPasswordEncoder is deprecated

Viewed 7297

I am working on Spring Cloud + Boot example. In this example I am looking to do SSO. When I run this application, I get the response fine, but looks like

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);
    }
}

But STS, shows error. What is the replacement of the deprecated method ?

enter image description here

Output: enter image description here

4 Answers

I was able to solve this issue using below code. I am using Spring Boot version 2.0.4.RELEASE. Done !

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");
    }
}

Don't use NoOpPasswordEncoder. It does nothing. Use instead: Pbkdf2PasswordEncoder, SCryptPasswordEncoder or BCryptPasswordEncoder. I use usually BCryptPasswordEncoder.

Initiated as bean:

 @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

You should not use this password encoder because it is not safe. From the official docs:

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.

Just add {noop} before the password inside double quotes, As shown in image

Your code should look like this,

auth
        .inMemoryAuthentication()
        .withUser("john")
        .password("{noop}durgesh")
        .roles("NORMAL");

It works then. However, it's not recommended to use noop in production as it is totally unsafe.

Related