Skip to content

Commit 585e6fa

Browse files
committed
Add Spring Security's authority for adding additional images.
1 parent ffe5715 commit 585e6fa

File tree

5 files changed

+6
-3
lines changed

5 files changed

+6
-3
lines changed

src/main/java/ru/mystamps/web/service/SeriesServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public Integer add(AddSeriesDto dto, User user, boolean userCanAddComments) {
125125

126126
@Override
127127
@Transactional
128+
@PreAuthorize("hasAuthority('ADD_IMAGES_TO_SERIES')")
128129
public void addImageToSeries(AddImageDto dto, Series series) {
129130
Validate.isTrue(dto != null, "DTO must be non null");
130131
Validate.isTrue(series != null, "DTO must be non null");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ private static Collection<? extends GrantedAuthority> getAuthorities(User user)
7070
List<SimpleGrantedAuthority> authorities = new LinkedList<>();
7171
authorities.add(new SimpleGrantedAuthority("CREATE_SERIES"));
7272
authorities.add(new SimpleGrantedAuthority("UPDATE_COLLECTION"));
73+
authorities.add(new SimpleGrantedAuthority("ADD_IMAGES_TO_SERIES"));
7374

7475
if (user.isAdmin()) {
7576
authorities.add(new SimpleGrantedAuthority("CREATE_CATEGORY"));

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ protected void configure(HttpSecurity http) throws Exception {
6868
.antMatchers(Url.ADD_CATEGORY_PAGE).hasAuthority("CREATE_CATEGORY")
6969
.antMatchers(Url.ADD_COUNTRY_PAGE).hasAuthority("CREATE_COUNTRY")
7070
.antMatchers(Url.ADD_SERIES_PAGE).hasAuthority("CREATE_SERIES")
71-
.regexMatchers(HttpMethod.POST, "/series/[0-9]+").hasAuthority("UPDATE_COLLECTION")
71+
.regexMatchers(HttpMethod.POST, "/series/[0-9]+")
72+
.hasAnyAuthority("UPDATE_COLLECTION", "ADD_IMAGES_TO_SERIES")
7273
.anyRequest().permitAll()
7374
.and()
7475
.formLogin()

src/main/webapp/WEB-INF/views/series/add.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ <h3 th:text="#{t_add_series_ucfirst}">
379379
</label>
380380
<div class="col-sm-7">
381381
<input type="file" id="image" class="form-control" style="box-shadow: none; border: 0px;" required="required" accept="image/png,image/jpeg" th:field="*{image}" />
382-
<small togglz:active="ADD_ADDITIONAL_IMAGES_TO_SERIES">
382+
<small togglz:active="ADD_ADDITIONAL_IMAGES_TO_SERIES" sec:authorize="hasAuthority('ADD_IMAGES_TO_SERIES')">
383383
<span class="hint-block" th:text="#{t_add_more_images_hint}">
384384
You will be able to add additional images on the series page
385385
</span>

src/main/webapp/WEB-INF/views/series/info.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<img src="../../../../../test/resources/test.png" class="img-responsive series-images" th:src="@{${GET_IMAGE_PAGE}(id=${image.id})}" />
5757
</div>
5858
</div>
59-
<div class="row" togglz:active="ADD_ADDITIONAL_IMAGES_TO_SERIES">
59+
<div class="row" togglz:active="ADD_ADDITIONAL_IMAGES_TO_SERIES" sec:authorize="hasAuthority('ADD_IMAGES_TO_SERIES')">
6060
<div class="col-sm-6 col-sm-offset-3">
6161
<form method="post" class="form-horizontal" enctype="multipart/form-data" th:action="@{${INFO_SERIES_PAGE}(id=${series.id})} + '?' + ${_csrf.parameterName} + '=' + ${_csrf.token}" th:object="${addImageForm}">
6262
<div class="form-group" th:classappend="${#fields.hasErrors('image') ? 'has-error' : ''}">

0 commit comments

Comments
 (0)