simbro:
私は春のブートアプリケーションの外部サービスへのHTTPリクエストを行うために証明書をインポートする必要があります。
どのように私はこれを行うために、春のブートを設定するのですか?
そこに多くの情報が出てありますが、私はすべてのビットが混乱し、それを見つけることです。私はちょうど「truststore.jks」キーストアのようなものを作成して、正しい証明書をインポートし、そして、私のapplication.propertiesにいくつかのエントリを追加する必要がありますかのように思えます。
ISlimani:
使用して自己署名証明書を生成することから始め
端末を開きますか、
あなたが既に持っている場合は、証明書は、
あなたにこのファイルをコピーします。
あなたに以下の行を追加し
作成し
今、あなたのアプリケーションが持つアクセス可能です
使用して自己署名証明書を生成することから始めkeytool
ますが、まだお持ちでない場合
端末を開きますか、 cmd
keytool -genkeypair -alias tomcat -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore keystore.p12 -validity 3650
すべての質問に答えます。最初の質問には:あなたの姓と名の何プットlocalhost
。
あなたが既に持っている場合は、証明書は、yourcertificate.crt
これを行います
keytool -import -alias tomcat -file yourcertificate.crt -keystore keystore.p12 -storepass password
あなたはと呼ばれるファイルを取得しますkeystore.p12
。
あなたにこのファイルをコピーします。 resources folder
あなたに以下の行を追加しproperties
たファイル
# Define a custom port instead of the default 8080
server.port=8443
# Tell Spring Security (if used) to require requests over HTTPS
security.require-ssl=true
# The format used for the keystore
server.ssl.key-store-type=PKCS12
# The path to the keystore containing the certificate
server.ssl.key-store=classpath:keystore.p12
# The password used to generate the certificate
server.ssl.key-store-password= {your password here}
# The alias mapped to the certificate
server.ssl.key-alias=tomcat
作成しConfig
、次のようにクラスを
@Configuration
public class ConnectorConfig {
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(getHttpConnector());
return tomcat;
}
private Connector getHttpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(8080);
connector.setSecure(false);
connector.setRedirectPort(8443);
return connector;
}
}
今、あなたのアプリケーションが持つアクセス可能です https://localhost:8443
今、あなたは、SSL認証をお願いしますあなたの第三のサービスにアクセスすることができます