Skip to content

Commit ecd2fdd

Browse files
committed
refactor: Refactored to remove hasH2Console boolean flag and replace it with a check on the H2 console properties/path.
Fix #1307
1 parent 98c17a3 commit ecd2fdd

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ class ContentSecurityPolicyHeaderWriter implements HeaderWriter {
151151

152152
private final boolean useCdn;
153153
private final boolean useSingleHost;
154-
private final boolean hasH2Console;
155154
private final String host;
156155
private final String h2ConsolePath;
157156

@@ -167,7 +166,7 @@ public void writeHeaders(HttpServletRequest request, HttpServletResponse respons
167166
protected String constructDirectives(String uri) {
168167
boolean onCollectionInfoPage = uri.startsWith(COLLECTION_INFO_PAGE_PATTERN);
169168
boolean onAddSeriesPage = uri.equals(SeriesUrl.ADD_SERIES_PAGE);
170-
boolean onH2ConsolePage = hasH2Console && uri.startsWith(h2ConsolePath);
169+
boolean onH2ConsolePage = h2ConsolePath != null && uri.startsWith(h2ConsolePath);
171170

172171
StringBuilder sb = new StringBuilder();
173172

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,21 @@ public void configure(WebSecurity web) throws Exception {
8787
protected void configure(HttpSecurity http) throws Exception {
8888
boolean useSingleHost = !environment.acceptsProfiles("prod");
8989
boolean useCdn = environment.getProperty("app.use-cdn", Boolean.class, Boolean.TRUE);
90-
boolean hasH2Console = environment.acceptsProfiles("test");
9190

9291
// @todo #226 Introduce app.use-public-hostname property
9392
boolean usePublicHostname = environment.acceptsProfiles("prod");
9493
String hostname = usePublicHostname ? SiteUrl.PUBLIC_URL : SiteUrl.SITE;
9594

96-
String h2ConsolePath = hasH2Console ? h2ConsoleProperties.getPath() : null;
95+
String h2ConsolePath = h2ConsoleProperties != null ? h2ConsoleProperties.getPath() : null;
9796

9897
// Allow unsecured requests to H2 consoles if available.
9998
// See also spring.h2.console.path in application-test.properties
10099
String[] pathsToIgnore =
101-
hasH2Console ? new String[]{h2ConsolePath + "/**", SiteUrl.CSP_REPORTS_HANDLER}
102-
: new String[]{SiteUrl.CSP_REPORTS_HANDLER};
100+
h2ConsolePath != null ? new String[]{h2ConsolePath + "/**", SiteUrl.CSP_REPORTS_HANDLER}
101+
: new String[]{SiteUrl.CSP_REPORTS_HANDLER};
103102

104103
ContentSecurityPolicyHeaderWriter cspWriter =
105-
new ContentSecurityPolicyHeaderWriter(useCdn, useSingleHost, hasH2Console, hostname, h2ConsolePath);
104+
new ContentSecurityPolicyHeaderWriter(useCdn, useSingleHost, hostname, h2ConsolePath);
106105

107106
http
108107
.authorizeRequests()

0 commit comments

Comments
 (0)