spring.turbo.core.env.BouncyCastleInstallingEnvironmentPostProcessor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-turbo Show documentation
Show all versions of spring-turbo Show documentation
Another enhancement library of SpringBoot/SpringFramework. Have fun.
The newest version!
package spring.turbo.core.env;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import java.security.Provider;
import java.security.Security;
import static org.springframework.util.ClassUtils.forName;
import static org.springframework.util.ClassUtils.getDefaultClassLoader;
/**
* @author 应卓
* @since 3.3.2
*/
public class BouncyCastleInstallingEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
private static final String BOUNCY_CASTLE_PROVIDER_CLASS = "org.bouncycastle.jce.provider.BouncyCastleProvider";
/**
* {@inheritDoc}
*/
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
try {
var cls = forName(BOUNCY_CASTLE_PROVIDER_CLASS, getDefaultClassLoader());
var ctor = cls.getConstructor();
var provider = ctor.newInstance();
Security.addProvider((Provider) provider);
} catch (Throwable ignored) {
// noop
}
}
/**
* {@inheritDoc}
*/
@Override
public int getOrder() {
return LOWEST_PRECEDENCE;
}
}