Make classes final where possible

Update classes that have private constructors so that they are also
declared final. In a few cases, inner-classes used private constructors
but were subclassed. These have now been changed to have package-private
constructors.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-24 19:03:31 -07:00
committed by Rob Winch
parent b5d499e2eb
commit 6894ff5d12
58 changed files with 229 additions and 226 deletions

View File

@@ -36,7 +36,10 @@ import javax.crypto.spec.PBEParameterSpec;
*
* @author Keith Donald
*/
class CipherUtils {
final class CipherUtils {
private CipherUtils() {
}
/**
* Generates a SecretKey.
@@ -138,7 +141,4 @@ class CipherUtils {
}
}
private CipherUtils() {
}
}

View File

@@ -24,7 +24,10 @@ import org.springframework.security.crypto.keygen.KeyGenerators;
*
* @author Keith Donald
*/
public class Encryptors {
public final class Encryptors {
private Encryptors() {
}
/**
* Creates a standard password-based bytes encryptor using 256 bit AES encryption with
@@ -112,9 +115,6 @@ public class Encryptors {
return NO_OP_TEXT_INSTANCE;
}
private Encryptors() {
}
private static final TextEncryptor NO_OP_TEXT_INSTANCE = new NoOpTextEncryptor();
private static final class NoOpTextEncryptor implements TextEncryptor {

View File

@@ -32,7 +32,10 @@ import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
* @author Rob Winch
* @since 5.0
*/
public class PasswordEncoderFactories {
public final class PasswordEncoderFactories {
private PasswordEncoderFactories() {
}
/**
* Creates a {@link DelegatingPasswordEncoder} with default mappings. Additional
@@ -79,7 +82,4 @@ public class PasswordEncoderFactories {
return new DelegatingPasswordEncoder(encodingId, encoders);
}
private PasswordEncoderFactories() {
}
}

View File

@@ -23,7 +23,10 @@ import java.security.SecureRandom;
*
* @author Keith Donald
*/
public class KeyGenerators {
public final class KeyGenerators {
private KeyGenerators() {
}
/**
* Create a {@link BytesKeyGenerator} that uses a {@link SecureRandom} to generate
@@ -59,9 +62,4 @@ public class KeyGenerators {
return new HexEncodingStringKeyGenerator(secureRandom());
}
// internal helpers
private KeyGenerators() {
}
}

View File

@@ -24,7 +24,10 @@ import org.springframework.security.crypto.codec.Utf8;
*
* @author Rob Winch
*/
class PasswordEncoderUtils {
final class PasswordEncoderUtils {
private PasswordEncoderUtils() {
}
/**
* Constant time comparison to prevent against timing attacks.
@@ -43,12 +46,9 @@ class PasswordEncoderUtils {
if (s == null) {
return null;
}
return Utf8.encode(s); // need to check if Utf8.encode() runs in constant time
// (probably not). This may leak length of string.
}
private PasswordEncoderUtils() {
// need to check if Utf8.encode() runs in constant time (probably not).
// This may leak length of string.
return Utf8.encode(s);
}
}

View File

@@ -22,7 +22,10 @@ package org.springframework.security.crypto.util;
*
* @author Keith Donald
*/
public class EncodingUtils {
public final class EncodingUtils {
private EncodingUtils() {
}
/**
* Combine the individual byte arrays into one array.
@@ -54,7 +57,4 @@ public class EncodingUtils {
return subarray;
}
private EncodingUtils() {
}
}