mirror of
https://gitee.com/dcren/initializr.git
synced 2026-09-19 06:17:42 +08:00
Redirect browsers to https when forceSsl is set
This commit extends the forceSsl support to redirect any HTML content to https. Practically speaking, this allows to redirect all browsers to https when they land on the main page using https. Serving traffic via http is still allowed as preventing this would break a lot of existing clients. To allow to easily run the app locally, forceSsl is false and must be enabled for any production environment. Closes gh-473
This commit is contained in:
+3
-2
@@ -197,9 +197,10 @@ public class InitializrConfiguration {
|
||||
Collections.singletonList("org.springframework"));
|
||||
|
||||
/**
|
||||
* Force SSL support. When enabled, any access using http generate https links.
|
||||
* Force SSL support. When enabled, any access using http generate https links and
|
||||
* browsers are redirected to https for html content.
|
||||
*/
|
||||
private boolean forceSsl = true;
|
||||
private boolean forceSsl;
|
||||
|
||||
/**
|
||||
* The "BillOfMaterials" that are referenced in this instance, identified by an
|
||||
|
||||
+15
-1
@@ -81,7 +81,7 @@ public class InitializrMetadataBuilderTests {
|
||||
.withInitializrMetadata(
|
||||
new ClassPathResource("metadata/config/test-min.json"))
|
||||
.build();
|
||||
assertThat(metadata.getConfiguration().getEnv().isForceSsl()).isEqualTo(false);
|
||||
assertThat(metadata.getConfiguration().getEnv().isForceSsl()).isEqualTo(true);
|
||||
assertThat(metadata.getDependencies().getContent()).hasSize(1);
|
||||
Dependency dependency = metadata.getDependencies().get("test");
|
||||
assertThat(dependency).isNotNull();
|
||||
@@ -187,6 +187,20 @@ public class InitializrMetadataBuilderTests {
|
||||
.isEqualTo("1.0.0-beta-2423");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeSslConfiguration() {
|
||||
InitializrProperties config = load(
|
||||
new ClassPathResource("application-test-default.yml"));
|
||||
InitializrProperties forceSslConfig = load(
|
||||
new ClassPathResource("application-test-ssl.yml"));
|
||||
InitializrMetadata metadata = InitializrMetadataBuilder
|
||||
.fromInitializrProperties(config)
|
||||
.withInitializrProperties(forceSslConfig, true).build();
|
||||
InitializrConfiguration.Env defaultEnv = new InitializrConfiguration().getEnv();
|
||||
InitializrConfiguration.Env actualEnv = metadata.getConfiguration().getEnv();
|
||||
assertThat(actualEnv.isForceSsl()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addDependencyInCustomizer() {
|
||||
DependencyGroup group = DependencyGroup.create("Extra");
|
||||
|
||||
@@ -2,7 +2,6 @@ initializr:
|
||||
env:
|
||||
artifactRepository: https://repo.spring.io/lib-release
|
||||
google-analytics-tracking-code: UA-1234567-89
|
||||
forceSsl: false
|
||||
fallbackApplicationName: FooBarApplication
|
||||
invalidApplicationNames:
|
||||
- InvalidApplication
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
initializr:
|
||||
env:
|
||||
forceSsl: true
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"configuration": {
|
||||
"env": {
|
||||
"forceSsl": false
|
||||
"forceSsl": true
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
Reference in New Issue
Block a user