-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/frodez/config/security/settings/UndertowConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package frodez.config.security.settings; | ||
|
||
import io.undertow.UndertowOptions; | ||
import io.undertow.servlet.api.SecurityConstraint; | ||
import io.undertow.servlet.api.SecurityInfo; | ||
import io.undertow.servlet.api.TransportGuaranteeType; | ||
import io.undertow.servlet.api.WebResourceCollection; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.web.ServerProperties; | ||
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory; | ||
import org.springframework.boot.web.server.WebServerFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Undertow配置 | ||
* @author Frodez | ||
* @date 2019-05-10 | ||
*/ | ||
@Configuration | ||
public class UndertowConfig { | ||
|
||
@Autowired | ||
private SecurityProperties securityProperties; | ||
|
||
@Autowired | ||
private ServerProperties serverProperties; | ||
|
||
/** | ||
* 配置HTTPS和HTTP2 | ||
* @author Frodez | ||
* @date 2019-05-10 | ||
*/ | ||
@Bean | ||
public WebServerFactory serverFactory() { | ||
UndertowServletWebServerFactory factory = new UndertowServletWebServerFactory(); | ||
factory.addBuilderCustomizers(builder -> builder.addHttpListener(serverProperties.getPort(), "0.0.0.0")); | ||
//开启HTTP2 | ||
factory.addBuilderCustomizers(builder -> { | ||
builder.setServerOption(UndertowOptions.ENABLE_HTTP2, serverProperties.getHttp2().isEnabled()) | ||
.setServerOption(UndertowOptions.HTTP2_SETTINGS_ENABLE_PUSH, serverProperties.getHttp2().isEnabled()); | ||
}); | ||
//开启HTTP自动跳转至HTTPS | ||
factory.addDeploymentInfoCustomizers(deploymentInfo -> { | ||
deploymentInfo.addSecurityConstraint(new SecurityConstraint().addWebResourceCollection( | ||
new WebResourceCollection().addUrlPattern("/*")).setTransportGuaranteeType( | ||
TransportGuaranteeType.CONFIDENTIAL).setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.PERMIT)) | ||
.setConfidentialPortManager(exchange -> securityProperties.getHttpsPort()); | ||
}); | ||
return factory; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters