Enforce admin and user authorization relues
This commit is contained in:
1 parent
f042861fcd
commit
a707f6ccde
2 files changed
+17
No files matched your search
@@ -65,6 +65,20 @@ public class SecurityConfiguration {
|
|||||||
.requestMatchers("/api/account/reset-password/init").permitAll()
|
.requestMatchers("/api/account/reset-password/init").permitAll()
|
||||||
.requestMatchers("/api/account/reset-password/finish").permitAll()
|
.requestMatchers("/api/account/reset-password/finish").permitAll()
|
||||||
.requestMatchers("/api/admin/**").hasAuthority(AuthoritiesConstants.ADMIN)
|
.requestMatchers("/api/admin/**").hasAuthority(AuthoritiesConstants.ADMIN)
|
||||||
|
|
||||||
|
|
||||||
|
.requestMatchers(HttpMethod.GET, "/api/subjects", "/api/subjects/**")
|
||||||
|
.hasAnyAuthority(AuthoritiesConstants.ADMIN, AuthoritiesConstants.USER)
|
||||||
|
.requestMatchers("/api/subjects", "/api/subjects/**")
|
||||||
|
.hasAuthority(AuthoritiesConstants.ADMIN)
|
||||||
|
.requestMatchers("/api/questions", "/api/questions/**")
|
||||||
|
.hasAuthority(AuthoritiesConstants.ADMIN)
|
||||||
|
.requestMatchers("/api/choices", "/api/choices/**")
|
||||||
|
.hasAuthority(AuthoritiesConstants.ADMIN)
|
||||||
|
.requestMatchers("/api/exam-answers", "/api/exam-answers/**")
|
||||||
|
.hasAuthority(AuthoritiesConstants.ADMIN)
|
||||||
|
|
||||||
|
|
||||||
.requestMatchers("/api/**").authenticated()
|
.requestMatchers("/api/**").authenticated()
|
||||||
.requestMatchers("/v3/api-docs/**").hasAuthority(AuthoritiesConstants.ADMIN)
|
.requestMatchers("/v3/api-docs/**").hasAuthority(AuthoritiesConstants.ADMIN)
|
||||||
.requestMatchers("/management/health").permitAll()
|
.requestMatchers("/management/health").permitAll()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.example.questionbank.web.rest;
|
package com.example.questionbank.web.rest;
|
||||||
|
|
||||||
import com.example.questionbank.repository.ExamAttemptRepository;
|
import com.example.questionbank.repository.ExamAttemptRepository;
|
||||||
|
import com.example.questionbank.security.AuthoritiesConstants;
|
||||||
import com.example.questionbank.service.ExamAttemptService;
|
import com.example.questionbank.service.ExamAttemptService;
|
||||||
import com.example.questionbank.service.dto.ExamAttemptDTO;
|
import com.example.questionbank.service.dto.ExamAttemptDTO;
|
||||||
import com.example.questionbank.service.quiz.QuizAttemptService;
|
import com.example.questionbank.service.quiz.QuizAttemptService;
|
||||||
@@ -26,6 +27,7 @@ import org.springframework.data.domain.Pageable;
|
|||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||||
@@ -70,6 +72,7 @@ public class ExamAttemptResource {
|
|||||||
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new examAttemptDTO, or with status {@code 400 (Bad Request)} if the examAttempt has already an ID.
|
* @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new examAttemptDTO, or with status {@code 400 (Bad Request)} if the examAttempt has already an ID.
|
||||||
* @throws URISyntaxException if the Location URI syntax is incorrect.
|
* @throws URISyntaxException if the Location URI syntax is incorrect.
|
||||||
*/
|
*/
|
||||||
|
@PreAuthorize("hasAuthority('" + AuthoritiesConstants.ADMIN + "')")
|
||||||
@PostMapping("")
|
@PostMapping("")
|
||||||
public ResponseEntity<ExamAttemptDTO> createExamAttempt(@Valid @RequestBody ExamAttemptDTO examAttemptDTO) throws URISyntaxException {
|
public ResponseEntity<ExamAttemptDTO> createExamAttempt(@Valid @RequestBody ExamAttemptDTO examAttemptDTO) throws URISyntaxException {
|
||||||
LOG.debug("REST request to save ExamAttempt : {}", examAttemptDTO);
|
LOG.debug("REST request to save ExamAttempt : {}", examAttemptDTO);
|
||||||
|
|||||||
Reference in new issue
Block a user