|
@@ -0,0 +1,65 @@
|
|
|
+/*
|
|
|
+ * Copyright 2002-2017 the original author or authors.
|
|
|
+ *
|
|
|
+ * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
+ * you may not use this file except in compliance with the License.
|
|
|
+ * You may obtain a copy of the License at
|
|
|
+ *
|
|
|
+ * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
+ *
|
|
|
+ * Unless required by applicable law or agreed to in writing, software
|
|
|
+ * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
+ * See the License for the specific language governing permissions and
|
|
|
+ * limitations under the License.
|
|
|
+ */
|
|
|
+
|
|
|
+package org.springframework.security.crypto.factory;
|
|
|
+
|
|
|
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
+import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
|
|
|
+import org.springframework.security.crypto.password.NoOpPasswordEncoder;
|
|
|
+import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
+import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
|
|
|
+import org.springframework.security.crypto.password.StandardPasswordEncoder;
|
|
|
+import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Used for creating {@link PasswordEncoder} instances
|
|
|
+ * @author Rob Winch
|
|
|
+ * @since 5.0
|
|
|
+ */
|
|
|
+public class PasswordEncoderFactories {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates a {@link DelegatingPasswordEncoder} with default mappings. Additional
|
|
|
+ * mappings may be added and the encoding will be updated to conform with best
|
|
|
+ * practices. However, due to the nature of {@link DelegatingPasswordEncoder} the
|
|
|
+ * updates should not impact users. The mappings current are:
|
|
|
+ *
|
|
|
+ * <ul>
|
|
|
+ * <li>noop - {@link NoOpPasswordEncoder}</li>
|
|
|
+ * <li>pbkdf2 - {@link Pbkdf2PasswordEncoder} (Also used for encoding)</li>
|
|
|
+ * <li>scrypt - {@link SCryptPasswordEncoder}</li>
|
|
|
+ * <li>sha256 - {@link StandardPasswordEncoder}</li>
|
|
|
+ * </ul>
|
|
|
+ *
|
|
|
+ * @return the {@link PasswordEncoder} to use
|
|
|
+ */
|
|
|
+ public static PasswordEncoder createDelegatingPasswordEncoder() {
|
|
|
+ String encodingId = "bcrypt";
|
|
|
+ Map<String,PasswordEncoder> encoders = new HashMap<>();
|
|
|
+ encoders.put(encodingId, new BCryptPasswordEncoder());
|
|
|
+ encoders.put("noop", NoOpPasswordEncoder.getInstance());
|
|
|
+ encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
|
|
|
+ encoders.put("scrypt", new SCryptPasswordEncoder());
|
|
|
+ encoders.put("sha256", new StandardPasswordEncoder());
|
|
|
+
|
|
|
+ return new DelegatingPasswordEncoder(encodingId, encoders);
|
|
|
+ }
|
|
|
+
|
|
|
+ private PasswordEncoderFactories() {}
|
|
|
+}
|