parent
7fe72c76ac
commit
c565668c5f
@ -0,0 +1,75 @@
|
||||
package kr.xit.core.spring.config.support;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.connector.Connector;
|
||||
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
|
||||
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* description : Http, Https(SSL) 적용 - 내장 톰캣 SSL use
|
||||
* server.ssl.redirect : false인 경우 HTTP와 SSL 동시 사용
|
||||
* application-https.ymlㅡㄷ 선언 사용
|
||||
* - server.ssl.enabled: true인 경우 활성화(적용)
|
||||
* - server.port : SSL port
|
||||
* - server.http : http port
|
||||
* - server.ssl.redirect : true|false
|
||||
* packageName : kr.xit.core.spring.config.support
|
||||
* fileName : HttpsConnectorConfig
|
||||
* author : julim
|
||||
* date : 2023-11-08
|
||||
* ======================================================================
|
||||
* 변경일 변경자 변경 내용
|
||||
* ----------------------------------------------------------------------
|
||||
* 2023-11-08 julim 최초 생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
@ConditionalOnProperty(value = "server.ssl.enabled", havingValue = "true", matchIfMissing = false)
|
||||
@Configuration
|
||||
public class HttpsConnectorConfig {
|
||||
@Value("${server.port}")
|
||||
private int SSL_PORT;
|
||||
@Value("${server.http}")
|
||||
private int HTTP_PORT;
|
||||
@Value("${server.ssl.redirect}")
|
||||
private boolean SSL_REDIRECT;
|
||||
@Bean
|
||||
public ServletWebServerFactory servletContainer() {
|
||||
|
||||
TomcatServletWebServerFactory tomcat = null;
|
||||
|
||||
if(SSL_REDIRECT){
|
||||
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);
|
||||
}
|
||||
};
|
||||
}else{
|
||||
tomcat = new TomcatServletWebServerFactory();
|
||||
}
|
||||
tomcat.addAdditionalTomcatConnectors(createSslConnector());
|
||||
return tomcat;
|
||||
}
|
||||
|
||||
private Connector createSslConnector() {
|
||||
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
|
||||
connector.setScheme("http");
|
||||
connector.setSecure(false);
|
||||
connector.setPort(HTTP_PORT);
|
||||
if(SSL_REDIRECT) connector.setRedirectPort(SSL_PORT);
|
||||
return connector;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#-----------------------------------------------------------------------
|
||||
# application Https SSL 설정
|
||||
# port가 다른 경우 프로파일 별로 server.port와 server.http 선언
|
||||
#-----------------------------------------------------------------------
|
||||
server:
|
||||
port: 8443
|
||||
ssl:
|
||||
enabled: true
|
||||
key-alias: tomcat
|
||||
key-store-provider: SUN
|
||||
key-store-type: PKCS12
|
||||
key-store-password: xit5811807
|
||||
key-store: classpath:tomcat.p12
|
||||
redirect: false
|
||||
http: 8081
|
||||
http2:
|
||||
enabled: true
|
Binary file not shown.
Loading…
Reference in New Issue