View Javadoc
1   /*
2    * Copyright 2014 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.bremersee.spring.boot.autoconfigure.security.authentication;
18  
19  import java.util.function.Supplier;
20  import org.springframework.security.crypto.keygen.KeyGenerators;
21  import org.springframework.security.crypto.password.LdapShaPasswordEncoder;
22  import org.springframework.security.crypto.password.PasswordEncoder;
23  
24  /**
25   * The password encoder provider.
26   *
27   * @author Christian Bremer
28   */
29  @FunctionalInterface
30  public interface LdaptivePasswordEncoderProvider extends Supplier<PasswordEncoder> {
31  
32    /**
33     * Creates a new default provider.
34     *
35     * @return the default password encoder provider
36     */
37    static LdaptivePasswordEncoderProvider defaultProvider() {
38      return new DefaultLdaptivePasswordEncoderProvider();
39    }
40  
41    /**
42     * The default password encoder provider.
43     */
44    class DefaultLdaptivePasswordEncoderProvider implements LdaptivePasswordEncoderProvider {
45  
46      /**
47       * Instantiates a new default ldaptive password encoder provider.
48       */
49      DefaultLdaptivePasswordEncoderProvider() {
50      }
51  
52      @Override
53      public PasswordEncoder get() {
54        //noinspection deprecation
55        return new LdapShaPasswordEncoder(KeyGenerators.shared(0));
56      }
57    }
58  
59  }