Suppress deprecation warnings in spring-security-crypto

This commit is contained in:
Johnny Lim 2018-05-05 10:04:56 +09:00 committed by Rob Winch
parent 2a0f529ee4
commit 9b42831c70
8 changed files with 26 additions and 24 deletions

View File

@ -20,7 +20,6 @@ import static org.springframework.security.crypto.util.EncodingUtils.subArray;
import org.bouncycastle.crypto.BufferedBlockCipher; import org.bouncycastle.crypto.BufferedBlockCipher;
import org.bouncycastle.crypto.InvalidCipherTextException; import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.crypto.engines.AESFastEngine;
import org.bouncycastle.crypto.modes.CBCBlockCipher; import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.paddings.PKCS7Padding; import org.bouncycastle.crypto.paddings.PKCS7Padding;
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher; import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
@ -51,8 +50,9 @@ public class BouncyCastleAesCbcBytesEncryptor extends BouncyCastleAesBytesEncryp
public byte[] encrypt(byte[] bytes) { public byte[] encrypt(byte[] bytes) {
byte[] iv = this.ivGenerator.generateKey(); byte[] iv = this.ivGenerator.generateKey();
@SuppressWarnings("deprecation")
PaddedBufferedBlockCipher blockCipher = new PaddedBufferedBlockCipher( PaddedBufferedBlockCipher blockCipher = new PaddedBufferedBlockCipher(
new CBCBlockCipher(new AESFastEngine()), new PKCS7Padding()); new CBCBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine()), new PKCS7Padding());
blockCipher.init(true, new ParametersWithIV(secretKey, iv)); blockCipher.init(true, new ParametersWithIV(secretKey, iv));
byte[] encrypted = process(blockCipher, bytes); byte[] encrypted = process(blockCipher, bytes);
return iv != null ? concatenate(iv, encrypted) : encrypted; return iv != null ? concatenate(iv, encrypted) : encrypted;
@ -64,8 +64,9 @@ public class BouncyCastleAesCbcBytesEncryptor extends BouncyCastleAesBytesEncryp
encryptedBytes = subArray(encryptedBytes, this.ivGenerator.getKeyLength(), encryptedBytes = subArray(encryptedBytes, this.ivGenerator.getKeyLength(),
encryptedBytes.length); encryptedBytes.length);
@SuppressWarnings("deprecation")
PaddedBufferedBlockCipher blockCipher = new PaddedBufferedBlockCipher( PaddedBufferedBlockCipher blockCipher = new PaddedBufferedBlockCipher(
new CBCBlockCipher(new AESFastEngine()), new PKCS7Padding()); new CBCBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine()), new PKCS7Padding());
blockCipher.init(false, new ParametersWithIV(secretKey, iv)); blockCipher.init(false, new ParametersWithIV(secretKey, iv));
return process(blockCipher, encryptedBytes); return process(blockCipher, encryptedBytes);
} }

View File

@ -19,7 +19,6 @@ import static org.springframework.security.crypto.util.EncodingUtils.concatenate
import static org.springframework.security.crypto.util.EncodingUtils.subArray; import static org.springframework.security.crypto.util.EncodingUtils.subArray;
import org.bouncycastle.crypto.InvalidCipherTextException; import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.crypto.engines.AESFastEngine;
import org.bouncycastle.crypto.modes.AEADBlockCipher; import org.bouncycastle.crypto.modes.AEADBlockCipher;
import org.bouncycastle.crypto.modes.GCMBlockCipher; import org.bouncycastle.crypto.modes.GCMBlockCipher;
import org.bouncycastle.crypto.params.AEADParameters; import org.bouncycastle.crypto.params.AEADParameters;
@ -49,7 +48,8 @@ public class BouncyCastleAesGcmBytesEncryptor extends BouncyCastleAesBytesEncryp
public byte[] encrypt(byte[] bytes) { public byte[] encrypt(byte[] bytes) {
byte[] iv = this.ivGenerator.generateKey(); byte[] iv = this.ivGenerator.generateKey();
GCMBlockCipher blockCipher = new GCMBlockCipher(new AESFastEngine()); @SuppressWarnings("deprecation")
GCMBlockCipher blockCipher = new GCMBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine());
blockCipher.init(true, new AEADParameters(secretKey, 128, iv, null)); blockCipher.init(true, new AEADParameters(secretKey, 128, iv, null));
byte[] encrypted = process(blockCipher, bytes); byte[] encrypted = process(blockCipher, bytes);
@ -62,7 +62,8 @@ public class BouncyCastleAesGcmBytesEncryptor extends BouncyCastleAesBytesEncryp
encryptedBytes = subArray(encryptedBytes, this.ivGenerator.getKeyLength(), encryptedBytes = subArray(encryptedBytes, this.ivGenerator.getKeyLength(),
encryptedBytes.length); encryptedBytes.length);
GCMBlockCipher blockCipher = new GCMBlockCipher(new AESFastEngine()); @SuppressWarnings("deprecation")
GCMBlockCipher blockCipher = new GCMBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine());
blockCipher.init(false, new AEADParameters(secretKey, 128, iv, null)); blockCipher.init(false, new AEADParameters(secretKey, 128, iv, null));
return process(blockCipher, encryptedBytes); return process(blockCipher, encryptedBytes);
} }

View File

@ -18,13 +18,8 @@ package org.springframework.security.crypto.factory;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.DelegatingPasswordEncoder; import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
import org.springframework.security.crypto.password.LdapShaPasswordEncoder;
import org.springframework.security.crypto.password.Md4PasswordEncoder;
import org.springframework.security.crypto.password.MessageDigestPasswordEncoder;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder; import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder; import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
import java.util.HashMap; import java.util.HashMap;
@ -45,32 +40,33 @@ public class PasswordEncoderFactories {
* *
* <ul> * <ul>
* <li>bcrypt - {@link BCryptPasswordEncoder} (Also used for encoding)</li> * <li>bcrypt - {@link BCryptPasswordEncoder} (Also used for encoding)</li>
* <li>ldap - {@link LdapShaPasswordEncoder}</li> * <li>ldap - {@link org.springframework.security.crypto.password.LdapShaPasswordEncoder}</li>
* <li>MD4 - {@link Md4PasswordEncoder}</li> * <li>MD4 - {@link org.springframework.security.crypto.password.Md4PasswordEncoder}</li>
* <li>MD5 - {@code new MessageDigestPasswordEncoder("MD5")}</li> * <li>MD5 - {@code new MessageDigestPasswordEncoder("MD5")}</li>
* <li>noop - {@link NoOpPasswordEncoder}</li> * <li>noop - {@link org.springframework.security.crypto.password.NoOpPasswordEncoder}</li>
* <li>pbkdf2 - {@link Pbkdf2PasswordEncoder}</li> * <li>pbkdf2 - {@link Pbkdf2PasswordEncoder}</li>
* <li>scrypt - {@link SCryptPasswordEncoder}</li> * <li>scrypt - {@link SCryptPasswordEncoder}</li>
* <li>SHA-1 - {@code new MessageDigestPasswordEncoder("SHA-1")}</li> * <li>SHA-1 - {@code new MessageDigestPasswordEncoder("SHA-1")}</li>
* <li>SHA-256 - {@code new MessageDigestPasswordEncoder("SHA-256")}</li> * <li>SHA-256 - {@code new MessageDigestPasswordEncoder("SHA-256")}</li>
* <li>sha256 - {@link StandardPasswordEncoder}</li> * <li>sha256 - {@link org.springframework.security.crypto.password.StandardPasswordEncoder}</li>
* </ul> * </ul>
* *
* @return the {@link PasswordEncoder} to use * @return the {@link PasswordEncoder} to use
*/ */
@SuppressWarnings("deprecation")
public static PasswordEncoder createDelegatingPasswordEncoder() { public static PasswordEncoder createDelegatingPasswordEncoder() {
String encodingId = "bcrypt"; String encodingId = "bcrypt";
Map<String, PasswordEncoder> encoders = new HashMap<>(); Map<String, PasswordEncoder> encoders = new HashMap<>();
encoders.put(encodingId, new BCryptPasswordEncoder()); encoders.put(encodingId, new BCryptPasswordEncoder());
encoders.put("ldap", new LdapShaPasswordEncoder()); encoders.put("ldap", new org.springframework.security.crypto.password.LdapShaPasswordEncoder());
encoders.put("MD4", new Md4PasswordEncoder()); encoders.put("MD4", new org.springframework.security.crypto.password.Md4PasswordEncoder());
encoders.put("MD5", new MessageDigestPasswordEncoder("MD5")); encoders.put("MD5", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5"));
encoders.put("noop", NoOpPasswordEncoder.getInstance()); encoders.put("noop", org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance());
encoders.put("pbkdf2", new Pbkdf2PasswordEncoder()); encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
encoders.put("scrypt", new SCryptPasswordEncoder()); encoders.put("scrypt", new SCryptPasswordEncoder());
encoders.put("SHA-1", new MessageDigestPasswordEncoder("SHA-1")); encoders.put("SHA-1", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-1"));
encoders.put("SHA-256", new MessageDigestPasswordEncoder("SHA-256")); encoders.put("SHA-256", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-256"));
encoders.put("sha256", new StandardPasswordEncoder()); encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder());
return new DelegatingPasswordEncoder(encodingId, encoders); return new DelegatingPasswordEncoder(encodingId, encoders);
} }

View File

@ -22,6 +22,7 @@ import org.junit.*;
/** /**
* @author Luke Taylor * @author Luke Taylor
*/ */
@SuppressWarnings("deprecation")
public class Base64Tests { public class Base64Tests {
@Test @Test
@ -33,7 +34,7 @@ public class Base64Tests {
} }
@Test @Test
public void isBase64ReturnsFalseForInvalidBase64() throws Exception { public void isBase64ReturnsFalseForInvalidBase64() {
// Include invalid '`' character // Include invalid '`' character
assertThat(Base64.isBase64(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C', assertThat(Base64.isBase64(new byte[] { (byte) 'A', (byte) 'B', (byte) 'C',
(byte) '`' })).isFalse(); (byte) '`' })).isFalse();

View File

@ -26,6 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* *
* @author Luke Taylor * @author Luke Taylor
*/ */
@SuppressWarnings("deprecation")
public class LdapShaPasswordEncoderTests { public class LdapShaPasswordEncoderTests {
// ~ Instance fields // ~ Instance fields
// ================================================================================================ // ================================================================================================

View File

@ -21,7 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test; import org.junit.Test;
@SuppressWarnings("deprecation")
public class Md4PasswordEncoderTests { public class Md4PasswordEncoderTests {
@Test @Test

View File

@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Ray Krueger * @author Ray Krueger
* @author Luke Taylor * @author Luke Taylor
*/ */
@SuppressWarnings("deprecation")
public class MessageDigestPasswordEncoderTests { public class MessageDigestPasswordEncoderTests {
// ~ Methods // ~ Methods
// ======================================================================================================== // ========================================================================================================

View File

@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test; import org.junit.Test;
@SuppressWarnings("deprecation")
public class StandardPasswordEncoderTests { public class StandardPasswordEncoderTests {
private StandardPasswordEncoder encoder = new StandardPasswordEncoder("secret"); private StandardPasswordEncoder encoder = new StandardPasswordEncoder("secret");