Skip to content
Snippets Groups Projects
Commit 66c65cf5 authored by Petr Kabelka's avatar Petr Kabelka
Browse files

feat: added security info to OpenAPI annotations

parent 308f89a5
No related branches found
No related tags found
1 merge request!32Add OAuth 2
Showing
with 172 additions and 30 deletions
package com.example.pa165_project_movies.common.config;
public final class SecurityConst {
public static final String UUID5_NAMESPACE_EMAIL = "f59e7f8d-1a56-4126-9e30-39ec5749819a";
public static final String SECURITY_SCHEME_NAME = "MUNI";
}
package com.example.pa165_project_movies.movie.rest; package com.example.pa165_project_movies.movie.rest;
import com.example.pa165_project_movies.common.config.Oauth2Scope;
import com.example.pa165_project_movies.common.config.SecurityConst;
import com.example.pa165_project_movies.common.dto.MovieCategoryCreateDto; import com.example.pa165_project_movies.common.dto.MovieCategoryCreateDto;
import com.example.pa165_project_movies.common.dto.MovieCategoryDto; import com.example.pa165_project_movies.common.dto.MovieCategoryDto;
import com.example.pa165_project_movies.movie.facade.MovieCategoryFacade; import com.example.pa165_project_movies.movie.facade.MovieCategoryFacade;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springdoc.core.annotations.ParameterObject; import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -34,30 +38,63 @@ public class MovieCategoryController { ...@@ -34,30 +38,63 @@ public class MovieCategoryController {
this.movieCategoryFacade = movieCategoryFacade; this.movieCategoryFacade = movieCategoryFacade;
} }
@Operation(summary = "Paged movie categories")
@GetMapping @GetMapping
public ResponseEntity<Page<MovieCategoryDto>> getMovieCategories(@ParameterObject Pageable pageable) { public ResponseEntity<Page<MovieCategoryDto>> getMovieCategories(@ParameterObject Pageable pageable) {
return ResponseEntity.ok(movieCategoryFacade.findAll(pageable)); return ResponseEntity.ok(movieCategoryFacade.findAll(pageable));
} }
@Operation(summary = "Get movie category by id") @Operation(
summary = "Get movie category by id",
responses = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "404", description = "entity not found"),
}
)
@GetMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}") @GetMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}")
public ResponseEntity<MovieCategoryDto> getMovieCategoryById(@PathVariable UUID id) { public ResponseEntity<MovieCategoryDto> getMovieCategoryById(@PathVariable UUID id) {
return ResponseEntity.ok(movieCategoryFacade.findById(id)); return ResponseEntity.ok(movieCategoryFacade.findById(id));
} }
@Operation(summary = "Create new movie category") @Operation(
summary = "Create new movie category",
responses = {
@ApiResponse(responseCode = "201"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
@ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
)
@PostMapping @PostMapping
public ResponseEntity<MovieCategoryDto> createMovieCategory(@Valid @RequestBody MovieCategoryCreateDto movieCategoryCreateDto) { public ResponseEntity<MovieCategoryDto> createMovieCategory(@Valid @RequestBody MovieCategoryCreateDto movieCategoryCreateDto) {
return new ResponseEntity<>(movieCategoryFacade.create(movieCategoryCreateDto), HttpStatus.CREATED); return new ResponseEntity<>(movieCategoryFacade.create(movieCategoryCreateDto), HttpStatus.CREATED);
} }
@Operation(summary = "Update movie category") @Operation(
summary = "Update movie category",
responses = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
@ApiResponse(responseCode = "404", description = "entity for update not found"),
@ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
)
@PutMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}") @PutMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}")
public ResponseEntity<MovieCategoryDto> updateMovieCategory(@PathVariable UUID id, @RequestBody MovieCategoryDto movieCategory) { public ResponseEntity<MovieCategoryDto> updateMovieCategory(@PathVariable UUID id, @RequestBody MovieCategoryDto movieCategory) {
return ResponseEntity.ok(movieCategoryFacade.update(id, movieCategory)); return ResponseEntity.ok(movieCategoryFacade.update(id, movieCategory));
} }
@Operation(summary = "Delete movie category") @Operation(
summary = "Delete movie category",
responses = {
@ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400", description = "wrong id format passed"),
@ApiResponse(responseCode = "404", description = "entity for deletion not found"),
@ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
)
@DeleteMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}") @DeleteMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}")
@ResponseStatus(HttpStatus.NO_CONTENT) @ResponseStatus(HttpStatus.NO_CONTENT)
public ResponseEntity<Void> deleteMovieCategory(@PathVariable UUID id) { public ResponseEntity<Void> deleteMovieCategory(@PathVariable UUID id) {
......
package com.example.pa165_project_movies.movie.rest; package com.example.pa165_project_movies.movie.rest;
import com.example.pa165_project_movies.common.config.Oauth2Scope;
import com.example.pa165_project_movies.common.config.SecurityConst;
import com.example.pa165_project_movies.common.dto.MovieDetailDto; import com.example.pa165_project_movies.common.dto.MovieDetailDto;
import com.example.pa165_project_movies.common.dto.MovieNewDto; import com.example.pa165_project_movies.common.dto.MovieNewDto;
import com.example.pa165_project_movies.common.dto.filterDto.MovieFilterDto; import com.example.pa165_project_movies.common.dto.filterDto.MovieFilterDto;
import com.example.pa165_project_movies.movie.facade.MovieFacade; import com.example.pa165_project_movies.movie.facade.MovieFacade;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springdoc.core.annotations.ParameterObject; import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -48,7 +52,11 @@ public class MovieController { ...@@ -48,7 +52,11 @@ public class MovieController {
@Operation( @Operation(
summary = "Get movie by id" summary = "Get movie by id",
responses = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "404", description = "entity not found"),
}
) )
@GetMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}") @GetMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}")
public ResponseEntity<MovieDetailDto> getMovieById(@PathVariable UUID id) { public ResponseEntity<MovieDetailDto> getMovieById(@PathVariable UUID id) {
...@@ -56,7 +64,13 @@ public class MovieController { ...@@ -56,7 +64,13 @@ public class MovieController {
} }
@Operation( @Operation(
summary = "Create new movie" summary = "Create new movie",
responses = {
@ApiResponse(responseCode = "201"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
@ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
) )
@PostMapping @PostMapping
public ResponseEntity<MovieDetailDto> createMovie( public ResponseEntity<MovieDetailDto> createMovie(
...@@ -66,7 +80,14 @@ public class MovieController { ...@@ -66,7 +80,14 @@ public class MovieController {
} }
@Operation( @Operation(
summary = "Update movie" summary = "Update movie",
responses = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
@ApiResponse(responseCode = "404", description = "entity for update not found"),
@ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
) )
@PutMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}") @PutMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}")
public ResponseEntity<MovieDetailDto> updateMovie( public ResponseEntity<MovieDetailDto> updateMovie(
...@@ -77,7 +98,14 @@ public class MovieController { ...@@ -77,7 +98,14 @@ public class MovieController {
} }
@Operation( @Operation(
summary = "Delete movie" summary = "Delete movie",
responses = {
@ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400", description = "wrong id format passed"),
@ApiResponse(responseCode = "404", description = "entity for deletion not found"),
@ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
) )
@DeleteMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}") @DeleteMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}")
public ResponseEntity<Void> deleteMovie(@PathVariable UUID id) { public ResponseEntity<Void> deleteMovie(@PathVariable UUID id) {
......
package com.example.pa165_project_movies.movie.rest; package com.example.pa165_project_movies.movie.rest;
import com.example.pa165_project_movies.common.config.Oauth2Scope;
import com.example.pa165_project_movies.common.config.SecurityConst;
import com.example.pa165_project_movies.common.dto.PictureCreateDto; import com.example.pa165_project_movies.common.dto.PictureCreateDto;
import com.example.pa165_project_movies.common.dto.PictureDto; import com.example.pa165_project_movies.common.dto.PictureDto;
import com.example.pa165_project_movies.movie.facade.PictureFacade; import com.example.pa165_project_movies.movie.facade.PictureFacade;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import org.springdoc.core.annotations.ParameterObject; import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -38,25 +42,57 @@ public class PictureController { ...@@ -38,25 +42,57 @@ public class PictureController {
return ResponseEntity.ok(pictureFacade.findAll(pageable)); return ResponseEntity.ok(pictureFacade.findAll(pageable));
} }
@Operation(summary = "Get movie picture by id") @Operation(
summary = "Get movie picture by id",
responses = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "404", description = "entity not found"),
}
)
@GetMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}") @GetMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}")
public ResponseEntity<PictureDto> getPictureById(@PathVariable UUID id) { public ResponseEntity<PictureDto> getPictureById(@PathVariable UUID id) {
return ResponseEntity.ok(pictureFacade.findById(id)); return ResponseEntity.ok(pictureFacade.findById(id));
} }
@Operation(summary = "Create new movie picture") @Operation(
summary = "Create new movie picture",
responses = {
@ApiResponse(responseCode = "201"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
@ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
)
@PostMapping @PostMapping
public ResponseEntity<PictureDto> createPicture(@Valid @RequestBody PictureCreateDto pictureCreateDto) { public ResponseEntity<PictureDto> createPicture(@Valid @RequestBody PictureCreateDto pictureCreateDto) {
return new ResponseEntity<>(pictureFacade.create(pictureCreateDto), HttpStatus.CREATED); return new ResponseEntity<>(pictureFacade.create(pictureCreateDto), HttpStatus.CREATED);
} }
@Operation(summary = "Update movie picture") @Operation(
summary = "Update movie picture",
responses = {
@ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
@ApiResponse(responseCode = "404", description = "entity for update not found"),
@ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
)
@PutMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}") @PutMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}")
public ResponseEntity<PictureDto> updatePicture(@PathVariable UUID id, @RequestBody PictureDto picture) { public ResponseEntity<PictureDto> updatePicture(@PathVariable UUID id, @RequestBody PictureDto picture) {
return ResponseEntity.ok(pictureFacade.update(id, picture)); return ResponseEntity.ok(pictureFacade.update(id, picture));
} }
@Operation(summary = "Delete movie picture") @Operation(
summary = "Delete movie picture",
responses = {
@ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400", description = "wrong id format passed"),
@ApiResponse(responseCode = "404", description = "entity for deletion not found"),
@ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
)
@DeleteMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}") @DeleteMapping(path = "/{id:^[0-9a-fA-F]{8}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{4}\\b-[0-9a-fA-F]{12}$}")
public ResponseEntity<Void> deletePicture(@PathVariable UUID id) { public ResponseEntity<Void> deletePicture(@PathVariable UUID id) {
pictureFacade.delete(id); pictureFacade.delete(id);
......
package com.example.pa165_project_movies.personnel.rest; package com.example.pa165_project_movies.personnel.rest;
import com.example.pa165_project_movies.common.config.Oauth2Scope;
import com.example.pa165_project_movies.common.config.SecurityConst;
import com.example.pa165_project_movies.common.dto.MovieRoleCreateDto; import com.example.pa165_project_movies.common.dto.MovieRoleCreateDto;
import com.example.pa165_project_movies.common.dto.MovieRoleDto; import com.example.pa165_project_movies.common.dto.MovieRoleDto;
import com.example.pa165_project_movies.personnel.facade.MovieRoleFacade; import com.example.pa165_project_movies.personnel.facade.MovieRoleFacade;
...@@ -7,6 +9,7 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition; ...@@ -7,6 +9,7 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.servers.Server; import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.servers.ServerVariable; import io.swagger.v3.oas.annotations.servers.ServerVariable;
import jakarta.validation.Valid; import jakarta.validation.Valid;
...@@ -56,7 +59,9 @@ public class MovieRoleRestController { ...@@ -56,7 +59,9 @@ public class MovieRoleRestController {
responses = { responses = {
@ApiResponse(responseCode = "201"), @ApiResponse(responseCode = "201"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"), @ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
} @ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
) )
@PostMapping @PostMapping
public ResponseEntity<MovieRoleDto> createMovieRole(@Valid @RequestBody MovieRoleCreateDto movieRoleCreateDto) { public ResponseEntity<MovieRoleDto> createMovieRole(@Valid @RequestBody MovieRoleCreateDto movieRoleCreateDto) {
...@@ -70,7 +75,9 @@ public class MovieRoleRestController { ...@@ -70,7 +75,9 @@ public class MovieRoleRestController {
@ApiResponse(responseCode = "200"), @ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"), @ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
@ApiResponse(responseCode = "404", description = "entity for update not found"), @ApiResponse(responseCode = "404", description = "entity for update not found"),
} @ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
) )
@PutMapping(path = "/{id}") @PutMapping(path = "/{id}")
public ResponseEntity<MovieRoleDto> updateMovieRole(@PathVariable UUID id, @Valid @RequestBody MovieRoleDto movieRoleDto) { public ResponseEntity<MovieRoleDto> updateMovieRole(@PathVariable UUID id, @Valid @RequestBody MovieRoleDto movieRoleDto) {
...@@ -84,7 +91,9 @@ public class MovieRoleRestController { ...@@ -84,7 +91,9 @@ public class MovieRoleRestController {
@ApiResponse(responseCode = "204"), @ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400", description = "wrong id format passed"), @ApiResponse(responseCode = "400", description = "wrong id format passed"),
@ApiResponse(responseCode = "404", description = "entity for deletion not found"), @ApiResponse(responseCode = "404", description = "entity for deletion not found"),
} @ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
) )
@DeleteMapping(path = "/{id}") @DeleteMapping(path = "/{id}")
public ResponseEntity<Void> deleteMovieRole(@PathVariable UUID id) { public ResponseEntity<Void> deleteMovieRole(@PathVariable UUID id) {
...@@ -106,7 +115,6 @@ public class MovieRoleRestController { ...@@ -106,7 +115,6 @@ public class MovieRoleRestController {
description = "Finds a role by id and returns its information.", description = "Finds a role by id and returns its information.",
responses = { responses = {
@ApiResponse(responseCode = "200"), @ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
@ApiResponse(responseCode = "404", description = "entity for update not found"), @ApiResponse(responseCode = "404", description = "entity for update not found"),
} }
) )
......
package com.example.pa165_project_movies.personnel.rest; package com.example.pa165_project_movies.personnel.rest;
import com.example.pa165_project_movies.common.config.Oauth2Scope;
import com.example.pa165_project_movies.common.config.SecurityConst;
import com.example.pa165_project_movies.common.dto.PersonRoleCreateDto; import com.example.pa165_project_movies.common.dto.PersonRoleCreateDto;
import com.example.pa165_project_movies.common.dto.PersonRoleDto; import com.example.pa165_project_movies.common.dto.PersonRoleDto;
import com.example.pa165_project_movies.personnel.facade.PersonMovieRoleFacade; import com.example.pa165_project_movies.personnel.facade.PersonMovieRoleFacade;
...@@ -7,6 +9,7 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition; ...@@ -7,6 +9,7 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.servers.Server; import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.servers.ServerVariable; import io.swagger.v3.oas.annotations.servers.ServerVariable;
import jakarta.validation.Valid; import jakarta.validation.Valid;
...@@ -58,7 +61,9 @@ public class PersonMovieRoleRestController { ...@@ -58,7 +61,9 @@ public class PersonMovieRoleRestController {
responses = { responses = {
@ApiResponse(responseCode = "201"), @ApiResponse(responseCode = "201"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"), @ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
} @ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
) )
@PostMapping @PostMapping
public ResponseEntity<PersonRoleDto> createMovieRole(@Valid @RequestBody PersonRoleCreateDto personRoleCreateDto) { public ResponseEntity<PersonRoleDto> createMovieRole(@Valid @RequestBody PersonRoleCreateDto personRoleCreateDto) {
...@@ -72,7 +77,9 @@ public class PersonMovieRoleRestController { ...@@ -72,7 +77,9 @@ public class PersonMovieRoleRestController {
@ApiResponse(responseCode = "200"), @ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"), @ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
@ApiResponse(responseCode = "404", description = "entity for update not found"), @ApiResponse(responseCode = "404", description = "entity for update not found"),
} @ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
) )
@PutMapping @PutMapping
public ResponseEntity<PersonRoleDto> updateMovieRole(@PathVariable UUID id, @Valid @RequestBody PersonRoleDto personDto) { public ResponseEntity<PersonRoleDto> updateMovieRole(@PathVariable UUID id, @Valid @RequestBody PersonRoleDto personDto) {
...@@ -86,7 +93,9 @@ public class PersonMovieRoleRestController { ...@@ -86,7 +93,9 @@ public class PersonMovieRoleRestController {
@ApiResponse(responseCode = "204"), @ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400", description = "wrong id format passed"), @ApiResponse(responseCode = "400", description = "wrong id format passed"),
@ApiResponse(responseCode = "404", description = "entity for deletion not found"), @ApiResponse(responseCode = "404", description = "entity for deletion not found"),
} @ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
) )
@DeleteMapping(path = "/{id}") @DeleteMapping(path = "/{id}")
public ResponseEntity<Void> deleteMovieRole(@PathVariable UUID id) { public ResponseEntity<Void> deleteMovieRole(@PathVariable UUID id) {
......
package com.example.pa165_project_movies.personnel.rest; package com.example.pa165_project_movies.personnel.rest;
import com.example.pa165_project_movies.common.config.Oauth2Scope;
import com.example.pa165_project_movies.common.config.SecurityConst;
import com.example.pa165_project_movies.common.dto.PersonCreateDto; import com.example.pa165_project_movies.common.dto.PersonCreateDto;
import com.example.pa165_project_movies.common.dto.PersonDto; import com.example.pa165_project_movies.common.dto.PersonDto;
import com.example.pa165_project_movies.personnel.facade.PersonFacade; import com.example.pa165_project_movies.personnel.facade.PersonFacade;
...@@ -7,6 +9,7 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition; ...@@ -7,6 +9,7 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.servers.Server; import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.servers.ServerVariable; import io.swagger.v3.oas.annotations.servers.ServerVariable;
import jakarta.validation.Valid; import jakarta.validation.Valid;
...@@ -56,7 +59,9 @@ public class PersonRestController { ...@@ -56,7 +59,9 @@ public class PersonRestController {
responses = { responses = {
@ApiResponse(responseCode = "201"), @ApiResponse(responseCode = "201"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"), @ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
} @ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
) )
@PostMapping @PostMapping
public ResponseEntity<PersonDto> createPerson(@Valid @RequestBody PersonCreateDto personDto) { public ResponseEntity<PersonDto> createPerson(@Valid @RequestBody PersonCreateDto personDto) {
...@@ -70,7 +75,9 @@ public class PersonRestController { ...@@ -70,7 +75,9 @@ public class PersonRestController {
@ApiResponse(responseCode = "200"), @ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"), @ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
@ApiResponse(responseCode = "404", description = "entity for update not found"), @ApiResponse(responseCode = "404", description = "entity for update not found"),
} @ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
) )
@PutMapping @PutMapping
public ResponseEntity<PersonDto> updatePerson(@PathVariable UUID id, @Valid @RequestBody PersonDto personDto) { public ResponseEntity<PersonDto> updatePerson(@PathVariable UUID id, @Valid @RequestBody PersonDto personDto) {
...@@ -84,7 +91,9 @@ public class PersonRestController { ...@@ -84,7 +91,9 @@ public class PersonRestController {
@ApiResponse(responseCode = "204"), @ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400", description = "wrong id format passed"), @ApiResponse(responseCode = "400", description = "wrong id format passed"),
@ApiResponse(responseCode = "404", description = "entity for deletion not found"), @ApiResponse(responseCode = "404", description = "entity for deletion not found"),
} @ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.ADMIN + "'"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.ADMIN})
) )
@DeleteMapping(path = "/{id}") @DeleteMapping(path = "/{id}")
public ResponseEntity<Void> deletePerson(@PathVariable UUID id) { public ResponseEntity<Void> deletePerson(@PathVariable UUID id) {
......
...@@ -35,8 +35,6 @@ public class SecurityConfig { ...@@ -35,8 +35,6 @@ public class SecurityConfig {
@Value("${rest.path.movie-reviews}") @Value("${rest.path.movie-reviews}")
private URI movieReviewsRestPath; private URI movieReviewsRestPath;
public static final String UUID5_NAMESPACE_EMAIL = "f59e7f8d-1a56-4126-9e30-39ec5749819a";
@Bean @Bean
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity httpSecurity
......
package com.example.pa165_project_movies.review.rest; package com.example.pa165_project_movies.review.rest;
import com.example.pa165_project_movies.common.config.Oauth2Scope;
import com.example.pa165_project_movies.common.config.SecurityConst;
import com.example.pa165_project_movies.common.dto.ReviewCreateDto; import com.example.pa165_project_movies.common.dto.ReviewCreateDto;
import com.example.pa165_project_movies.common.dto.ReviewDto; import com.example.pa165_project_movies.common.dto.ReviewDto;
import com.example.pa165_project_movies.review.facade.ReviewFacade; import com.example.pa165_project_movies.review.facade.ReviewFacade;
...@@ -8,6 +10,7 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition; ...@@ -8,6 +10,7 @@ import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.servers.Server; import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.servers.ServerVariable; import io.swagger.v3.oas.annotations.servers.ServerVariable;
import jakarta.validation.Valid; import jakarta.validation.Valid;
...@@ -84,9 +87,11 @@ public class ReviewRestController { ...@@ -84,9 +87,11 @@ public class ReviewRestController {
responses = { responses = {
@ApiResponse(responseCode = "201"), @ApiResponse(responseCode = "201"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"), @ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
} @ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.AUTH_WRITE + "' or 'userId' field does not match the caller's ID"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.AUTH_WRITE})
) )
@PreAuthorize("hasAuthority(T(com.example.pa165_project_movies.common.config.Oauth2Scope).ADMIN) or #review.getUserId().equals(T(com.example.pa165_project_movies.common.util.UUID5).from(T(com.example.pa165_project_movies.review.config.SecurityConfig).UUID5_NAMESPACE_EMAIL, authentication.getName()))") @PreAuthorize("hasAuthority(T(com.example.pa165_project_movies.common.config.Oauth2Scope).ADMIN) or #review.getUserId().equals(T(com.example.pa165_project_movies.common.util.UUID5).from(T(com.example.pa165_project_movies.common.config.SecurityConst).UUID5_NAMESPACE_EMAIL, authentication.getName()))")
@PostMapping @PostMapping
public ResponseEntity<ReviewDto> createReview( public ResponseEntity<ReviewDto> createReview(
@Valid @RequestBody ReviewCreateDto review @Valid @RequestBody ReviewCreateDto review
...@@ -101,9 +106,11 @@ public class ReviewRestController { ...@@ -101,9 +106,11 @@ public class ReviewRestController {
@ApiResponse(responseCode = "200"), @ApiResponse(responseCode = "200"),
@ApiResponse(responseCode = "400", description = "wrong DTO data passed"), @ApiResponse(responseCode = "400", description = "wrong DTO data passed"),
@ApiResponse(responseCode = "404", description = "entity for update not found"), @ApiResponse(responseCode = "404", description = "entity for update not found"),
} @ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.AUTH_WRITE + "' or 'userId' field does not match the caller's ID"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.AUTH_WRITE})
) )
@PreAuthorize("hasAuthority(T(com.example.pa165_project_movies.common.config.Oauth2Scope).ADMIN) or #review.getUserId().equals(T(com.example.pa165_project_movies.common.util.UUID5).from(T(com.example.pa165_project_movies.review.config.SecurityConfig).UUID5_NAMESPACE_EMAIL, authentication.getName()))") @PreAuthorize("hasAuthority(T(com.example.pa165_project_movies.common.config.Oauth2Scope).ADMIN) or #review.getUserId().equals(T(com.example.pa165_project_movies.common.util.UUID5).from(T(com.example.pa165_project_movies.common.config.SecurityConst).UUID5_NAMESPACE_EMAIL, authentication.getName()))")
@PutMapping(path = "/{id}") @PutMapping(path = "/{id}")
public ResponseEntity<ReviewDto> updateReview( public ResponseEntity<ReviewDto> updateReview(
@PathVariable UUID id, @PathVariable UUID id,
...@@ -119,9 +126,11 @@ public class ReviewRestController { ...@@ -119,9 +126,11 @@ public class ReviewRestController {
@ApiResponse(responseCode = "204"), @ApiResponse(responseCode = "204"),
@ApiResponse(responseCode = "400", description = "wrong id format passed"), @ApiResponse(responseCode = "400", description = "wrong id format passed"),
@ApiResponse(responseCode = "404", description = "entity for deletion not found"), @ApiResponse(responseCode = "404", description = "entity for deletion not found"),
} @ApiResponse(responseCode = "403", description = "access token does not have scope '" + Oauth2Scope.AUTH_WRITE + "' or 'userId' field does not match the caller's ID"),
},
security = @SecurityRequirement(name = SecurityConst.SECURITY_SCHEME_NAME, scopes = {Oauth2Scope.AUTH_WRITE})
) )
@PreAuthorize("hasAuthority(T(com.example.pa165_project_movies.common.config.Oauth2Scope).ADMIN) or @reviewFacade.findById(#id).getUserId().equals(T(com.example.pa165_project_movies.common.util.UUID5).from(T(com.example.pa165_project_movies.review.config.SecurityConfig).UUID5_NAMESPACE_EMAIL, authentication.getName()))") @PreAuthorize("hasAuthority(T(com.example.pa165_project_movies.common.config.Oauth2Scope).ADMIN) or @reviewFacade.findById(#id).getUserId().equals(T(com.example.pa165_project_movies.common.util.UUID5).from(T(com.example.pa165_project_movies.common.config.SecurityConst).UUID5_NAMESPACE_EMAIL, authentication.getName()))")
@DeleteMapping(path = "/{id}") @DeleteMapping(path = "/{id}")
public ResponseEntity<Void> deleteReview(@PathVariable UUID id) { public ResponseEntity<Void> deleteReview(@PathVariable UUID id) {
reviewFacade.delete(id); reviewFacade.delete(id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment