Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

While reading plain text password from properties files using @Value always getting 401 issue - SpringBoot

I am using Spring Boot 2.1.0 with Spring security 5.1.1. In my WebSecurityAuthenticator class, i have the @Value annotation to map password field with plain password value in the properties file. For Example :-

@Value("${spring.security.user.password}")
private String password;

In configureGlobalSecurity method,I used below code for authentication.

@Autowired

protected void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
        PasswordEncoder encoder =
         PasswordEncoderFactories.createDelegatingPasswordEncoder();


auth.inMemoryAuthentication().withUser(username).password(encoder.encode(password)).roles("USER");

    }

Here if i use the plaintext instead of password its working fine.If i read from properties file using @Value as mentioned above i am always getting 401 exception.

Plain text Example :- working fine :

auth.inMemoryAuthentication().withUser(username).password(encoder.encode("mypassword")).roles("USER");

From properties file :- Not working :

auth.inMemoryAuthentication().withUser(username).password(encoder.encode(password)).roles("USER");

Comments