Skip to content

Commit 859d798

Browse files
committed
refactor: inline H2_CONSOLE_PAGE and remove Url class.
Addressed to #927 No functional changes.
1 parent 638da40 commit 859d798

File tree

4 files changed

+6
-40
lines changed

4 files changed

+6
-40
lines changed

src/main/java/ru/mystamps/web/Url.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/main/java/ru/mystamps/web/support/spring/security/ContentSecurityPolicyHeaderWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import lombok.RequiredArgsConstructor;
2121
import org.springframework.security.web.header.HeaderWriter;
22-
import ru.mystamps.web.Url;
2322
import ru.mystamps.web.feature.collection.CollectionUrl;
2423
import ru.mystamps.web.feature.series.SeriesUrl;
2524

@@ -42,7 +41,8 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
4241

4342
private static final String ADD_IMAGE_PAGE_PATTERN = "/series/(add|\\d+|\\d+/(ask|image))";
4443

45-
private static final String H2_CONSOLE_PATTERN = Url.H2_CONSOLE_PAGE + '/';
44+
// see also spring.h2.console.path in application-test.properties and SecurityConfig
45+
private static final String H2_CONSOLE_PATTERN = "/console/";
4646

4747
// default policy prevents loading resources from any source
4848
private static final String DEFAULT_SRC = "default-src 'none'";

src/main/java/ru/mystamps/web/support/spring/security/SecurityConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.springframework.security.crypto.password.PasswordEncoder;
4242
import org.springframework.security.web.access.AccessDeniedHandler;
4343
import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint;
44-
import ru.mystamps.web.Url;
4544
import ru.mystamps.web.feature.account.AccountUrl;
4645
import ru.mystamps.web.feature.account.UserService;
4746
import ru.mystamps.web.feature.category.CategoryUrl;
@@ -133,7 +132,9 @@ protected void configure(HttpSecurity http) throws Exception {
133132
.and()
134133
.csrf()
135134
// Allow unsecured requests to H2 consoles.
136-
.ignoringAntMatchers(Url.H2_CONSOLE_PAGE + "/**")
135+
// See also spring.h2.console.path in application-test.properties and
136+
// ContentSecurityPolicyHeaderWriter.H2_CONSOLE_PATTERN
137+
.ignoringAntMatchers("/console/**")
137138
.and()
138139
.rememberMe()
139140
// FIXME: GH #27

src/main/resources/application-test.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spring.datasource.driver-class-name: org.h2.Driver
77
spring.datasource.initialize: false
88

99
spring.h2.console.enabled: true
10-
# see also ru.mystamps.web.Url.H2_CONSOLE_PAGE constant
10+
# see also SecurityConfig and ContentSecurityPolicyHeaderWriter.H2_CONSOLE_PATTERN
1111
spring.h2.console.path: /console
1212
security.basic.enabled: false
1313
# required for using /console with CSP because we have many hashes as a workaround

0 commit comments

Comments
 (0)