Skip to content

Commit cd71782

Browse files
committed
refactor: don't use chaining and reduce an indentation level
Part of #1149
1 parent 55d5d97 commit cd71782

File tree

1 file changed

+66
-61
lines changed

1 file changed

+66
-61
lines changed

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

+66-61
Original file line numberDiff line numberDiff line change
@@ -105,67 +105,72 @@ protected void configure(HttpSecurity http) throws Exception {
105105
ContentSecurityPolicyHeaderWriter cspWriter =
106106
new ContentSecurityPolicyHeaderWriter(useCdn, useSingleHost, hostname, h2ConsolePath);
107107

108-
http
109-
.authorizeRequests(authorizeRequests -> authorizeRequests
110-
.mvcMatchers(CategoryUrl.ADD_CATEGORY_PAGE).hasAuthority(StringAuthority.CREATE_CATEGORY)
111-
.mvcMatchers(CountryUrl.ADD_COUNTRY_PAGE).hasAuthority(StringAuthority.CREATE_COUNTRY)
112-
.mvcMatchers(ParticipantUrl.ADD_PARTICIPANT_PAGE).hasAuthority(StringAuthority.ADD_PARTICIPANT)
113-
.mvcMatchers(SeriesUrl.ADD_SERIES_PAGE).hasAuthority(StringAuthority.CREATE_SERIES)
114-
.mvcMatchers(HttpMethod.PATCH, SeriesUrl.INFO_SERIES_PAGE)
115-
.hasAnyAuthority(StringAuthority.CREATE_SERIES, StringAuthority.ADD_COMMENTS_TO_SERIES)
116-
.mvcMatchers(SeriesImportUrl.REQUEST_IMPORT_SERIES_PAGE).hasAuthority(StringAuthority.IMPORT_SERIES)
117-
.mvcMatchers(SiteUrl.SITE_EVENTS_PAGE).hasAuthority(StringAuthority.VIEW_SITE_EVENTS)
118-
.mvcMatchers(CategoryUrl.SUGGEST_SERIES_CATEGORY).hasAuthority(StringAuthority.CREATE_SERIES)
119-
.mvcMatchers(CountryUrl.SUGGEST_SERIES_COUNTRY).hasAuthority(StringAuthority.CREATE_SERIES)
120-
.mvcMatchers(ReportUrl.DAILY_STATISTICS).hasAuthority(StringAuthority.VIEW_DAILY_STATS)
121-
.mvcMatchers(CollectionUrl.ESTIMATION_COLLECTION_PAGE)
122-
.access(HasAuthority.ADD_SERIES_PRICE_AND_COLLECTION_OWNER_OR_VIEW_ANY_ESTIMATION)
123-
.regexMatchers(HttpMethod.POST, "/series/[0-9]+")
124-
.hasAnyAuthority(
125-
StringAuthority.UPDATE_COLLECTION,
126-
StringAuthority.ADD_IMAGES_TO_SERIES
127-
)
128-
.regexMatchers(HttpMethod.POST, SeriesUrl.ADD_SERIES_ASK_PAGE.replace("{id}", "[0-9]+"))
129-
.hasAuthority(StringAuthority.ADD_SERIES_SALES)
130-
.mvcMatchers(HttpMethod.POST, SeriesUrl.MARK_SIMILAR_SERIES)
131-
.hasAnyAuthority(StringAuthority.MARK_SIMILAR_SERIES)
132-
.mvcMatchers(HttpMethod.POST, SeriesSalesImportUrl.IMPORT_SERIES_SALES)
133-
.hasAuthority(StringAuthority.IMPORT_SERIES_SALES)
134-
.anyRequest().permitAll()
135-
)
136-
.formLogin(formLogin -> formLogin
137-
.loginPage(AccountUrl.AUTHENTICATION_PAGE)
138-
.usernameParameter("login")
139-
.passwordParameter("password")
140-
.loginProcessingUrl(AccountUrl.LOGIN_PAGE)
141-
.failureUrl(AccountUrl.AUTHENTICATION_PAGE + "?failed")
142-
.defaultSuccessUrl(SiteUrl.INDEX_PAGE, true)
143-
.permitAll()
144-
)
145-
.logout(logout -> logout
146-
.logoutUrl(AccountUrl.LOGOUT_PAGE)
147-
.logoutSuccessUrl(SiteUrl.INDEX_PAGE)
148-
.invalidateHttpSession(true)
149-
.permitAll()
150-
)
151-
.exceptionHandling(exceptionHandling -> exceptionHandling
152-
.accessDeniedHandler(getAccessDeniedHandler())
153-
// This entry point handles when you request a protected page and you are
154-
// not yet authenticated
155-
.authenticationEntryPoint(new Http403ForbiddenEntryPoint())
156-
)
157-
.csrf(csrf -> csrf
158-
.ignoringAntMatchers(pathsToIgnore)
159-
)
160-
.rememberMe(rememberMe -> rememberMe
161-
// FIXME: GH #27
162-
.disable()
163-
)
164-
.headers(headers -> headers
165-
.defaultsDisabled() // FIXME
166-
// @todo #1161 Add Feature-Policy header
167-
.addHeaderWriter(cspWriter)
168-
);
108+
http.authorizeRequests(authorizeRequests -> authorizeRequests
109+
.mvcMatchers(CategoryUrl.ADD_CATEGORY_PAGE).hasAuthority(StringAuthority.CREATE_CATEGORY)
110+
.mvcMatchers(CountryUrl.ADD_COUNTRY_PAGE).hasAuthority(StringAuthority.CREATE_COUNTRY)
111+
.mvcMatchers(ParticipantUrl.ADD_PARTICIPANT_PAGE).hasAuthority(StringAuthority.ADD_PARTICIPANT)
112+
.mvcMatchers(SeriesUrl.ADD_SERIES_PAGE).hasAuthority(StringAuthority.CREATE_SERIES)
113+
.mvcMatchers(HttpMethod.PATCH, SeriesUrl.INFO_SERIES_PAGE)
114+
.hasAnyAuthority(StringAuthority.CREATE_SERIES, StringAuthority.ADD_COMMENTS_TO_SERIES)
115+
.mvcMatchers(SeriesImportUrl.REQUEST_IMPORT_SERIES_PAGE).hasAuthority(StringAuthority.IMPORT_SERIES)
116+
.mvcMatchers(SiteUrl.SITE_EVENTS_PAGE).hasAuthority(StringAuthority.VIEW_SITE_EVENTS)
117+
.mvcMatchers(CategoryUrl.SUGGEST_SERIES_CATEGORY).hasAuthority(StringAuthority.CREATE_SERIES)
118+
.mvcMatchers(CountryUrl.SUGGEST_SERIES_COUNTRY).hasAuthority(StringAuthority.CREATE_SERIES)
119+
.mvcMatchers(ReportUrl.DAILY_STATISTICS).hasAuthority(StringAuthority.VIEW_DAILY_STATS)
120+
.mvcMatchers(CollectionUrl.ESTIMATION_COLLECTION_PAGE)
121+
.access(HasAuthority.ADD_SERIES_PRICE_AND_COLLECTION_OWNER_OR_VIEW_ANY_ESTIMATION)
122+
.regexMatchers(HttpMethod.POST, "/series/[0-9]+")
123+
.hasAnyAuthority(
124+
StringAuthority.UPDATE_COLLECTION,
125+
StringAuthority.ADD_IMAGES_TO_SERIES
126+
)
127+
.regexMatchers(HttpMethod.POST, SeriesUrl.ADD_SERIES_ASK_PAGE.replace("{id}", "[0-9]+"))
128+
.hasAuthority(StringAuthority.ADD_SERIES_SALES)
129+
.mvcMatchers(HttpMethod.POST, SeriesUrl.MARK_SIMILAR_SERIES)
130+
.hasAnyAuthority(StringAuthority.MARK_SIMILAR_SERIES)
131+
.mvcMatchers(HttpMethod.POST, SeriesSalesImportUrl.IMPORT_SERIES_SALES)
132+
.hasAuthority(StringAuthority.IMPORT_SERIES_SALES)
133+
.anyRequest().permitAll()
134+
);
135+
136+
http.formLogin(formLogin -> formLogin
137+
.loginPage(AccountUrl.AUTHENTICATION_PAGE)
138+
.usernameParameter("login")
139+
.passwordParameter("password")
140+
.loginProcessingUrl(AccountUrl.LOGIN_PAGE)
141+
.failureUrl(AccountUrl.AUTHENTICATION_PAGE + "?failed")
142+
.defaultSuccessUrl(SiteUrl.INDEX_PAGE, true)
143+
.permitAll()
144+
);
145+
146+
http .logout(logout -> logout
147+
.logoutUrl(AccountUrl.LOGOUT_PAGE)
148+
.logoutSuccessUrl(SiteUrl.INDEX_PAGE)
149+
.invalidateHttpSession(true)
150+
.permitAll()
151+
);
152+
153+
http.exceptionHandling(exceptionHandling -> exceptionHandling
154+
.accessDeniedHandler(getAccessDeniedHandler())
155+
// This entry point handles when you request a protected page and you are
156+
// not yet authenticated
157+
.authenticationEntryPoint(new Http403ForbiddenEntryPoint())
158+
);
159+
160+
http.csrf(csrf -> csrf
161+
.ignoringAntMatchers(pathsToIgnore)
162+
);
163+
164+
http.rememberMe(rememberMe -> rememberMe
165+
// FIXME: GH #27
166+
.disable()
167+
);
168+
169+
http.headers(headers -> headers
170+
.defaultsDisabled() // FIXME
171+
// @todo #1161 Add Feature-Policy header
172+
.addHeaderWriter(cspWriter)
173+
);
169174
}
170175

171176
// Used in AccountConfig.Services.userService()

0 commit comments

Comments
 (0)