Compare commits

...
Author SHA1 Message Date
jieun 96ab5e2588 Finalize Chapter 08 security configuration 2026-11-05 23:44:27 +09:00
jieun a707f6ccde Enforce admin and user authorization relues 2026-11-05 23:39:06 +09:00
2 changed files with 18 additions and 0 deletions

No files matched your search

@@ -65,6 +65,20 @@ public class SecurityConfiguration {
.requestMatchers("/api/account/reset-password/init").permitAll()
.requestMatchers("/api/account/reset-password/finish").permitAll()
.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("/v3/api-docs/**").hasAuthority(AuthoritiesConstants.ADMIN)
.requestMatchers("/management/health").permitAll()
@@ -1,6 +1,7 @@
package com.example.questionbank.web.rest;
import com.example.questionbank.repository.ExamAttemptRepository;
import com.example.questionbank.security.AuthoritiesConstants;
import com.example.questionbank.service.ExamAttemptService;
import com.example.questionbank.service.dto.ExamAttemptDTO;
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.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
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.
* @throws URISyntaxException if the Location URI syntax is incorrect.
*/
@PreAuthorize("hasAuthority('" + AuthoritiesConstants.ADMIN + "')")
@PostMapping("")
public ResponseEntity<ExamAttemptDTO> createExamAttempt(@Valid @RequestBody ExamAttemptDTO examAttemptDTO) throws URISyntaxException {
LOG.debug("REST request to save ExamAttempt : {}", examAttemptDTO);
@@ -158,6 +161,7 @@ public class ExamAttemptResource {
* @param eagerload flag to eager load entities from relationships (This is applicable for many-to-many).
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of Exam Attempts in body.
*/
@PreAuthorize("hasAuthority('" + AuthoritiesConstants.ADMIN + "')")
@GetMapping("")
public ResponseEntity<List<ExamAttemptDTO>> getAllExamAttempts(
@org.springdoc.core.annotations.ParameterObject Pageable pageable,