Skip to content

Fix Password Encoding for Default user #10762

@rwinch

Description

@rwinch

The code in AuthenticationManagerConfiguration assumes a PasswordEncoder of NoOpPasswordEncoder which was the default of Spring Security until recently. Now the default is PasswordEncoderFactories.createDelegatingPasswordEncoder().

This is the un-tested version of the updates that should be made:

public class AuthenticationManagerConfiguration {
	private static final Log logger = LogFactory
			.getLog(AuthenticationManagerConfiguration.class);
	@Autowired(required = false)
	private PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
	@Bean
	public InMemoryUserDetailsManager inMemoryUserDetailsManager() throws Exception {
		String password = UUID.randomUUID().toString();
		logger.info(String.format("%n%nUsing default security password: %s%n", password));
		String encodedPassword = this.encoder.encode(password);
		return new InMemoryUserDetailsManager(
				User.withUsername("user").password(encodedPassword).roles().build());
	}

}

A similar change needs to be done in ReactiveAuthenticationManagerConfiguration

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions