/** * Creates a new provider for a given configuration. * * @param credentialsServiceClient The client. * @param config The configuration. * @param tracer The tracer instance. * @throws NullPointerException if any of the parameters are {@code null}. */ @Autowired public UsernamePasswordAuthProvider(final HonoClient credentialsServiceClient, final ServiceConfigProperties config, final Tracer tracer) { this(credentialsServiceClient, new SpringBasedHonoPasswordEncoder(), config, tracer); }
/** * Creates a new encoder. * <p> * This constructor will create a new {@code SecureRandom} * as follows: * <ol> * <li>try to create a SecureRandom using algorithm <em>NativePRNGNonBlocking</em></li> * <li>if that fails, create a default SecureRandom, i.e. without specifying an * algorithm</li> * </ol> * and then invoke {@link #SpringBasedHonoPasswordEncoder(SecureRandom, int)}. * * @see "https://tersesystems.com/blog/2015/12/17/the-right-way-to-use-securerandom/" * @see "https://hackernoon.com/hack-how-to-use-securerandom-with-kubernetes-and-docker-a375945a7b21" */ public SpringBasedHonoPasswordEncoder() { this(newSecureRandom(), DEFAULT_BCRYPT_STRENGTH); }
/** * Exposes a password encoder to use for encoding clear text passwords * and for matching password hashes. * * @return The encoder. */ @Bean public HonoPasswordEncoder passwordEncoder() { return new SpringBasedHonoPasswordEncoder(credentialsProperties().getMaxBcryptIterations()); } }
/** * Creates a new encoder. * <p> * This constructor will create a new {@code SecureRandom} * as follows: * <ol> * <li>try to create a SecureRandom using algorithm <em>NativePRNGNonBlocking</em></li> * <li>if that fails, create a default SecureRandom, i.e. without specifying an * algorithm</li> * </ol> * and then invoke {@link #SpringBasedHonoPasswordEncoder(SecureRandom, int)}. * * @param bcryptStrength The strength to use for creating BCrypt hashes. Value must be * >= 4 and <= 31. Note that a higher value will increase the time * it takes to compute a hash. A value around 10 is considered a good compromise * between security and computation time. * @see "https://tersesystems.com/blog/2015/12/17/the-right-way-to-use-securerandom/" * @see "https://hackernoon.com/hack-how-to-use-securerandom-with-kubernetes-and-docker-a375945a7b21" */ public SpringBasedHonoPasswordEncoder(final int bcryptStrength) { this(newSecureRandom(), bcryptStrength); }