Example usage for org.springframework.beans.factory ObjectProvider getIfAvailable

List of usage examples for org.springframework.beans.factory ObjectProvider getIfAvailable

Introduction

In this page you can find the example usage for org.springframework.beans.factory ObjectProvider getIfAvailable.

Prototype

default T getIfAvailable(Supplier<T> defaultSupplier) throws BeansException 

Source Link

Document

Return an instance (possibly shared or independent) of the object managed by this factory.

Usage

From source file:org.springframework.boot.autoconfigure.security.reactive.ReactiveAuthenticationManagerConfiguration.java

private UserDetails getUserDetails(SecurityProperties.User user,
        ObjectProvider<PasswordEncoder> passwordEncoder) {
    String encodedPassword = passwordEncoder
            .getIfAvailable(PasswordEncoderFactories::createDelegatingPasswordEncoder)
            .encode(user.getPassword());
    List<String> roles = user.getRoles();
    return User.withUsername(user.getName()).password(encodedPassword)
            .roles(roles.toArray(new String[roles.size()])).build();
}