diff --git a/README.md b/README.md index 5b00d892e..9b3fa38d2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![GitHub commit activity](https://img.shields.io/github/commit-activity/y/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager) [![GitHub last commit](https://img.shields.io/github/last-commit/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager) [![CircleCI](https://circleci.com/gh/softwaremagico/KendoTournamentManager.svg?style=shield)](https://circleci.com/gh/softwaremagico/KendoTournamentManager) -[![Time](https://img.shields.io/badge/development-592h-blueviolet.svg)]() +[![Time](https://img.shields.io/badge/development-593h-blueviolet.svg)]() [![Powered by](https://img.shields.io/badge/powered%20by%20java-orange.svg?logo=OpenJDK&logoColor=white)]() [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=kendo-tournament-backend&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=kendo-tournament-backend) diff --git a/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/providers/ParticipantProvider.java b/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/providers/ParticipantProvider.java index f9bf4145a..97a33b212 100644 --- a/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/providers/ParticipantProvider.java +++ b/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/providers/ParticipantProvider.java @@ -113,10 +113,16 @@ public Participant generateToken(Participant participant) { } public Optional findByTemporalToken(String token) { - return getRepository().findByTemporalToken(token); + if (token != null) { + return getRepository().findByTemporalToken(token); + } + return Optional.empty(); } public Optional findByTokenUsername(String tokenUsername) { + if (tokenUsername == null) { + return Optional.empty(); + } if (tokenUsername.contains(ParticipantProvider.TOKEN_NAME_SEPARATOR)) { final String[] fields = tokenUsername.split(ParticipantProvider.TOKEN_NAME_SEPARATOR); try { diff --git a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/BasicServices.java b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/BasicServices.java index 6a531da41..5dd49f5c1 100644 --- a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/BasicServices.java +++ b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/BasicServices.java @@ -61,6 +61,15 @@ protected CONTROLLER getController() { return controller; } + /** + * This method is done due to @PreAuthorize cannot be overriden. TournamentService need to set a GUEST permission to it. + * + * @return an array of roles. + */ + public String[] requiredRoleForEntityById() { + return new String[]{"ROLE_VIEWER", "ROLE_EDITOR", "ROLE_ADMIN"}; + } + @PreAuthorize("hasAnyRole('ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN')") @Operation(summary = "Gets all", security = @SecurityRequirement(name = "bearerAuth")) @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE) @@ -75,10 +84,10 @@ public long count(HttpServletRequest request) { return controller.count(); } - @PreAuthorize("hasAnyRole('ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN')") + @PreAuthorize("hasAnyRole(#root.this.requiredRoleForEntityById())") @Operation(summary = "Gets an entity.", security = @SecurityRequirement(name = "bearerAuth")) @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) - public DTO get(@Parameter(description = "Id of an existing application", required = true) @PathVariable("id") Integer id, + public DTO get(@Parameter(description = "Id of an existing entity", required = true) @PathVariable("id") Integer id, HttpServletRequest request) { return controller.get(id); } diff --git a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/FrontendLoggerServices.java b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/FrontendLoggerServices.java index 71d48b6c4..0ea4d28f7 100644 --- a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/FrontendLoggerServices.java +++ b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/FrontendLoggerServices.java @@ -42,7 +42,7 @@ private static String sanitize(Object parameter) { return parameter.toString().replaceAll("[\n\r\t]", "_"); } - @PreAuthorize("hasAnyRole('ROLE_GUEST', 'ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN')") + @PreAuthorize("hasAnyRole('ROLE_GUEST', 'ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN', 'ROLE_PARTICIPANT')") @Operation(summary = "Register an action that must be logged.", security = @SecurityRequirement(name = "bearerAuth")) @PostMapping(value = "/info") @ResponseStatus(HttpStatus.OK) @@ -50,7 +50,7 @@ public void info(@RequestBody LogDTO log, HttpServletRequest request) { FrontendLogger.info(this.getClass(), sanitize(log.getMessage())); } - @PreAuthorize("hasAnyRole('ROLE_GUEST', 'ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN')") + @PreAuthorize("hasAnyRole('ROLE_GUEST', 'ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN', 'ROLE_PARTICIPANT')") @Operation(summary = "Register a warning that must be logged.", security = @SecurityRequirement(name = "bearerAuth")) @PostMapping(value = "/warning") @ResponseStatus(HttpStatus.OK) @@ -58,7 +58,7 @@ public void warning(@RequestBody LogDTO log, HttpServletRequest request) { FrontendLogger.warning(this.getClass(), sanitize(log.getMessage())); } - @PreAuthorize("hasAnyRole('ROLE_GUEST', 'ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN')") + @PreAuthorize("hasAnyRole('ROLE_GUEST', 'ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN', 'ROLE_PARTICIPANT')") @Operation(summary = "Register an error that must be logged.", security = @SecurityRequirement(name = "bearerAuth")) @PostMapping(value = "/error") @ResponseStatus(HttpStatus.OK) diff --git a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/GroupLinkServices.java b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/GroupLinkServices.java index 7c25b026d..03d88fc78 100644 --- a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/GroupLinkServices.java +++ b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/GroupLinkServices.java @@ -51,7 +51,7 @@ public GroupLinkServices(GroupLinkController groupController) { } - @PreAuthorize("hasAnyRole('ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN')") + @PreAuthorize("hasAnyRole('ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN', 'ROLE_GUEST')") @Operation(summary = "Gets all groups links.", security = @SecurityRequirement(name = "bearerAuth")) @GetMapping(value = "/tournament/{tournamentId}", produces = MediaType.APPLICATION_JSON_VALUE) public List getAll(@Parameter(description = "Id of an existing tournament", required = true) diff --git a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/GroupServices.java b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/GroupServices.java index e756d96f6..b83ece3d5 100644 --- a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/GroupServices.java +++ b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/GroupServices.java @@ -71,7 +71,7 @@ public GroupServices(GroupController groupController, PdfController pdfControlle this.tournamentController = tournamentController; } - @PreAuthorize("hasAnyRole('ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN')") + @PreAuthorize("hasAnyRole('ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN', 'ROLE_GUEST')") @Operation(summary = "Gets all groups.", security = @SecurityRequirement(name = "bearerAuth")) @GetMapping(value = "/tournaments/{tournamentId}", produces = MediaType.APPLICATION_JSON_VALUE) public List getAll(@Parameter(description = "Id of an existing tournament", required = true) @PathVariable("tournamentId") Integer tournamentId, diff --git a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/ParticipantServices.java b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/ParticipantServices.java index 6cda3a0a7..5211ab57a 100644 --- a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/ParticipantServices.java +++ b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/ParticipantServices.java @@ -51,6 +51,16 @@ public ParticipantServices(ParticipantController participantController) { super(participantController); } + /** + * This method is done due to @PreAuthorize cannot be overriden. TournamentService need to set a GUEST permission to it. + * + * @return an array of roles. + */ + @Override + public String[] requiredRoleForEntityById() { + return new String[]{"ROLE_VIEWER", "ROLE_EDITOR", "ROLE_ADMIN", "ROLE_PARTICIPANT"}; + } + @PreAuthorize("hasAnyRole('ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN', 'ROLE_GUEST', 'ROLE_PARTICIPANT')") @Operation(summary = "Gets the participant data from the jwt token username.", security = @SecurityRequirement(name = "bearerAuth")) diff --git a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/TeamServices.java b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/TeamServices.java index b6564d70a..5c8fb89ed 100644 --- a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/TeamServices.java +++ b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/TeamServices.java @@ -77,7 +77,7 @@ public TeamServices(TeamController teamController, TournamentController tourname } - @PreAuthorize("hasAnyRole('ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN')") + @PreAuthorize("hasAnyRole('ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN', 'ROLE_GUEST')") @Operation(summary = "Gets all teams from a tournament.", security = @SecurityRequirement(name = "bearerAuth")) @GetMapping(value = "/tournaments/{tournamentId}", produces = MediaType.APPLICATION_JSON_VALUE) public List getAll(@Parameter(description = "Id of an existing tournament", required = true) @PathVariable("tournamentId") Integer tournamentId, diff --git a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/TournamentExtraPropertiesServices.java b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/TournamentExtraPropertiesServices.java index aa316b655..4401e9549 100644 --- a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/TournamentExtraPropertiesServices.java +++ b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/TournamentExtraPropertiesServices.java @@ -52,7 +52,7 @@ public TournamentExtraPropertiesServices(TournamentExtraPropertyController tourn this.tournamentExtraPropertyController = tournamentExtraPropertyController; } - @PreAuthorize("hasAnyRole('ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN')") + @PreAuthorize("hasAnyRole('ROLE_VIEWER', 'ROLE_EDITOR', 'ROLE_ADMIN', 'ROLE_GUEST')") @Operation(summary = "Gets tournament's properties.", security = @SecurityRequirement(name = "bearerAuth")) @GetMapping(value = "/tournaments/{tournamentId}", produces = MediaType.APPLICATION_JSON_VALUE) public List get(@Parameter(description = "Id of an existing tournament", required = true) @PathVariable("tournamentId") diff --git a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/TournamentServices.java b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/TournamentServices.java index 1e3a2b7ae..c22a6030d 100644 --- a/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/TournamentServices.java +++ b/backend/kendo-tournament-rest/src/main/java/com/softwaremagico/kt/rest/services/TournamentServices.java @@ -74,6 +74,23 @@ public TournamentServices(TournamentController tournamentController, PdfControll this.pdfController = pdfController; } + /** + * This method is done due to @PreAuthorize cannot be overriden. TournamentService need to set a GUEST permission to it. + * + * @return an array of roles. + */ + @Override + public String[] requiredRoleForEntityById() { + return new String[]{"ROLE_VIEWER", "ROLE_EDITOR", "ROLE_ADMIN", "ROLE_GUEST"}; + } + + @Operation(summary = "Gets a tournament.", security = @SecurityRequirement(name = "bearerAuth")) + @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE) + public TournamentDTO get(@Parameter(description = "Id of an existing tournament", required = true) @PathVariable("id") Integer id, + HttpServletRequest request) { + return super.get(id, request); + } + @Operation(summary = "Gets all", security = @SecurityRequirement(name = "bearerAuth")) @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE) public List getAll(HttpServletRequest request) { diff --git a/frontend/src/app/components/participant-qr-code/participant-qr-code.component.html b/frontend/src/app/components/participant-qr-code/participant-qr-code.component.html index b53b75da1..090619978 100644 --- a/frontend/src/app/components/participant-qr-code/participant-qr-code.component.html +++ b/frontend/src/app/components/participant-qr-code/participant-qr-code.component.html @@ -4,7 +4,7 @@
diff --git a/frontend/src/app/components/tournament-qr-code/tournament-qr-code.component.html b/frontend/src/app/components/tournament-qr-code/tournament-qr-code.component.html index d78499513..25b9b490b 100644 --- a/frontend/src/app/components/tournament-qr-code/tournament-qr-code.component.html +++ b/frontend/src/app/components/tournament-qr-code/tournament-qr-code.component.html @@ -4,8 +4,9 @@
QR Code - {{'orClickHere' | translate}} -