Removes spring-security-rsa (#1399)

In favor of merging into spring-security-crypto

Fixes gh-1398
This commit is contained in:
Spencer Gibb
2024-09-24 16:10:20 -04:00
committed by GitHub
parent d55734e8cf
commit d87c755c92
15 changed files with 37 additions and 49 deletions

View File

@@ -38,7 +38,12 @@ public class TextEncryptorConfigBootstrapper implements BootstrapRegistryInitial
* RsaSecretEncryptor present.
*/
public static final boolean RSA_IS_PRESENT = ClassUtils
.isPresent("org.springframework.security.rsa.crypto.RsaSecretEncryptor", null);
.isPresent("org.springframework.security.crypto.encrypt.RsaSecretEncryptor", null);
/**
* RsaSecretEncryptor present.
*/
public static final boolean BCPROV_IS_PRESENT = ClassUtils.isPresent("org.bouncycastle.asn1.ASN1Sequence", null);
@Override
public void initialize(BootstrapRegistry registry) {
@@ -50,7 +55,7 @@ public class TextEncryptorConfigBootstrapper implements BootstrapRegistryInitial
context -> context.get(Binder.class)
.bind(KeyProperties.PREFIX, KeyProperties.class)
.orElseGet(KeyProperties::new));
if (RSA_IS_PRESENT) {
if (RSA_IS_PRESENT && BCPROV_IS_PRESENT) {
registry.registerIfAbsent(RsaProperties.class,
context -> context.get(Binder.class)
.bind(RsaProperties.PREFIX, RsaProperties.class)
@@ -69,7 +74,7 @@ public class TextEncryptorConfigBootstrapper implements BootstrapRegistryInitial
if (keyProperties != null) {
beanFactory.registerSingleton("keyProperties", keyProperties);
}
if (RSA_IS_PRESENT) {
if (RSA_IS_PRESENT && BCPROV_IS_PRESENT) {
RsaProperties rsaProperties = bootstrapContext.get(RsaProperties.class);
if (rsaProperties != null) {
beanFactory.registerSingleton("rsaProperties", rsaProperties);

View File

@@ -16,6 +16,8 @@
package org.springframework.cloud.bootstrap.encrypt;
import org.bouncycastle.asn1.ASN1Sequence;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
@@ -32,8 +34,8 @@ import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.security.crypto.encrypt.RsaSecretEncryptor;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import org.springframework.security.rsa.crypto.RsaSecretEncryptor;
import org.springframework.util.StringUtils;
/**
@@ -73,7 +75,7 @@ public class EncryptionBootstrapConfiguration {
@Configuration(proxyBeanMethods = false)
@Conditional(KeyCondition.class)
@ConditionalOnClass(RsaSecretEncryptor.class)
@ConditionalOnClass({ RsaSecretEncryptor.class, ASN1Sequence.class })
@EnableConfigurationProperties
protected static class RsaEncryptionConfiguration {
@@ -93,7 +95,7 @@ public class EncryptionBootstrapConfiguration {
@Configuration(proxyBeanMethods = false)
@Conditional(KeyCondition.class)
@ConditionalOnMissingClass("org.springframework.security.rsa.crypto.RsaSecretEncryptor")
@ConditionalOnMissingClass("org.bouncycastle.asn1.ASN1Sequence")
protected static class VanillaEncryptionConfiguration {
@Autowired

View File

@@ -30,7 +30,7 @@ class EncryptionRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints.reflection()
.registerTypeIfPresent(classLoader, "org.springframework.security.rsa.crypto.RsaSecretEncryptor",
.registerTypeIfPresent(classLoader, "org.springframework.security.crypto.encrypt.RsaSecretEncryptor",
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
}

View File

@@ -18,7 +18,7 @@ package org.springframework.cloud.bootstrap.encrypt;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.security.rsa.crypto.RsaAlgorithm;
import org.springframework.security.crypto.encrypt.RsaAlgorithm;
/**
* @author Ryan Baxter

View File

@@ -31,12 +31,14 @@ import org.springframework.context.ApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.security.crypto.encrypt.KeyStoreKeyFactory;
import org.springframework.security.crypto.encrypt.RsaSecretEncryptor;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import org.springframework.security.rsa.crypto.KeyStoreKeyFactory;
import org.springframework.security.rsa.crypto.RsaSecretEncryptor;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import static org.springframework.cloud.bootstrap.TextEncryptorConfigBootstrapper.BCPROV_IS_PRESENT;
public abstract class TextEncryptorUtils {
/**
@@ -58,7 +60,7 @@ public abstract class TextEncryptorUtils {
.orElseGet(KeyProperties::new);
if (TextEncryptorUtils.keysConfigured(keyProperties)) {
decryptor.setFailOnError(keyProperties.isFailOnError());
if (ClassUtils.isPresent("org.springframework.security.rsa.crypto.RsaSecretEncryptor", null)) {
if (ClassUtils.isPresent("org.springframework.security.crypto.encrypt.RsaSecretEncryptor", null)) {
RsaProperties rsaProperties = binder.bind(RsaProperties.PREFIX, RsaProperties.class)
.orElseGet(RsaProperties::new);
return TextEncryptorUtils.createTextEncryptor(keyProperties, rsaProperties);
@@ -78,7 +80,7 @@ public abstract class TextEncryptorUtils {
registry.registerIfAbsent(TextEncryptor.class, context -> {
KeyProperties keyProperties = context.get(KeyProperties.class);
if (TextEncryptorConfigBootstrapper.keysConfigured(keyProperties)) {
if (TextEncryptorConfigBootstrapper.RSA_IS_PRESENT) {
if (TextEncryptorConfigBootstrapper.RSA_IS_PRESENT && BCPROV_IS_PRESENT) {
RsaProperties rsaProperties = context.get(RsaProperties.class);
return createTextEncryptor(keyProperties, rsaProperties);
}

View File

@@ -17,8 +17,8 @@
package org.springframework.cloud.context.encrypt;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.security.crypto.encrypt.RsaSecretEncryptor;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import org.springframework.security.rsa.crypto.RsaSecretEncryptor;
/**
* @author Dave Syer

View File

@@ -21,8 +21,8 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.security.crypto.encrypt.RsaAlgorithm;
import org.springframework.security.crypto.encrypt.TextEncryptor;
import org.springframework.security.rsa.crypto.RsaAlgorithm;
import static org.assertj.core.api.BDDAssertions.then;

View File

@@ -24,7 +24,7 @@ import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.security.rsa.crypto.RsaSecretEncryptor;
import org.springframework.security.crypto.encrypt.RsaSecretEncryptor;
import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -32,7 +32,7 @@ import static org.assertj.core.api.BDDAssertions.then;
/**
* @author Ryan Baxter
*/
@ClassPathExclusions({ "spring-security-rsa*.jar" })
@ClassPathExclusions({ "bcprov-jdk*.jar" })
public class RsaDisabledTests {
private ConfigurableApplicationContext context;
@@ -54,7 +54,7 @@ public class RsaDisabledTests {
}
@Test
public void testLoadBalancedRetryFactoryBean() throws Exception {
public void testNoRsaProperites() throws Exception {
Map<String, RsaProperties> properties = this.context.getBeansOfType(RsaProperties.class);
then(properties.values()).hasSize(0);
}