Skip to content

Commit

Permalink
Reduced encryption to avoid issues with search queries
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaremagico committed May 8, 2024
1 parent 3e33ddd commit 744e056
Show file tree
Hide file tree
Showing 20 changed files with 25 additions and 53 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-610.5h-blueviolet.svg)]()
[![Time](https://img.shields.io/badge/development-611h-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)
Expand Down
2 changes: 1 addition & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ On the security level, you must perform the next actions to ensure that your dep

#### Update the database encryption key

The property `database.encryption.key` is used for database encryption purpose. Obviously this value must be keep in
The property `database.encryption.key` is used for personal data encryption purpose. Obviously this value must be keep in
secret. If the property is left empty, no encryption is applied on the database. Some examples of use:

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

public abstract class ElementConverter<F, T, R extends ConverterRequest<F>> implements IElementConverter<F, T, R> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void prepareTournament() {
TournamentExtraPropertyKey.LEAGUE_FIGHTS_ORDER_GENERATION, LeagueFightsOrder.FIFO.name()), null);
generateRoles(tournament1DTO);
addTeams(tournament1DTO);
List<FightDTO> fightDTOs = fightController.createFights(tournament1DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament1DTO.getId(), TeamsOrder.SORTED, 0, null));


fightDTOs.get(0).getDuels().get(0).addCompetitor1Score(Score.MEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest
Expand Down Expand Up @@ -111,7 +112,7 @@ public void prepareData() {
public void prepareTournament1() {
//Create Tournament
tournament1DTO = addTournament(TOURNAMENT1_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, 3);
List<FightDTO> fightDTOs = fightController.createFights(tournament1DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament1DTO.getId(), TeamsOrder.SORTED, 0, null));

//Woodcutter
fightDTOs.get(0).getDuels().get(0).addCompetitor1Score(Score.DO);
Expand Down Expand Up @@ -178,7 +179,7 @@ public void prepareTournament1() {
public void prepareTournament2() {
//Create Tournament
tournament2DTO = addTournament(TOURNAMENT2_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, 2);
List<FightDTO> fightDTOs = fightController.createFights(tournament2DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament2DTO.getId(), TeamsOrder.SORTED, 0, null));

//Juggernaut
fightDTOs.get(0).getDuels().get(2).addCompetitor1Score(Score.KOTE);
Expand Down Expand Up @@ -210,7 +211,7 @@ public void prepareTournament2() {
public void prepareTournament3() {
tournament3DTO = addTournament(TOURNAMENT3_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, 1);
//Create Tournament
List<FightDTO> fightDTOs = fightController.createFights(tournament3DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament3DTO.getId(), TeamsOrder.SORTED, 0, null));

//The Castle
fightDTOs.get(0).getDuels().get(0).addCompetitor1Score(Score.KOTE);
Expand Down Expand Up @@ -259,7 +260,7 @@ public void prepareTournament3() {
public void prepareTournament4() {
tournament4DTO = addTournament(TOURNAMENT4_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, 1);
//Create Tournament
List<FightDTO> fightDTOs = fightController.createFights(tournament4DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament4DTO.getId(), TeamsOrder.SORTED, 0, null));

//Team1 and Team2 no scores. Team1 has no scores neither against itself.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.testng.annotations.Test;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest
Expand Down Expand Up @@ -107,7 +108,7 @@ public void prepareData() {
public void prepareTournament1() {
//Create Tournament
tournament1DTO = addTournament(TOURNAMENT1_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TOURNAMENT1_DELAY);
List<FightDTO> fightDTOs = fightController.createFights(tournament1DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament1DTO.getId(), TeamsOrder.SORTED, 0, null));

//P1 vs P4 Win P1
//P2 vs P5 Win P2
Expand Down Expand Up @@ -160,7 +161,7 @@ public void prepareTournament1() {
public void prepareTournament2() {
//Create Tournament
tournament2DTO = addTournament(TOURNAMENT2_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TOURNAMENT2_DELAY);
List<FightDTO> fightDTOs = fightController.createFights(tournament2DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament2DTO.getId(), TeamsOrder.SORTED, 0, null));

//P1 vs P4 Win P1
//P2 vs P5 Win P2
Expand Down Expand Up @@ -212,7 +213,7 @@ public void prepareTournament2() {
public void prepareTournament3() {
//Create Tournament
tournament3DTO = addTournament(TOURNAMENT3_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TOURNAMENT3_DELAY);
List<FightDTO> fightDTOs = fightController.createFights(tournament3DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament3DTO.getId(), TeamsOrder.SORTED, 0, null));

//P1 vs P4 Win P1
//P2 vs P5 Win P2
Expand Down Expand Up @@ -264,7 +265,7 @@ public void prepareTournament3() {
public void prepareTournament4() {
tournament4DTO = addTournament(TOURNAMENT4_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TOURNAMENT4_DELAY);
//Create Tournament
List<FightDTO> fightDTOs = fightController.createFights(tournament4DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament4DTO.getId(), TeamsOrder.SORTED, 0, null));
//P1 vs P4 Win P4 <---
//P2 vs P5 Win P2
//P3 vs P6 Win P3
Expand Down Expand Up @@ -314,7 +315,7 @@ public void prepareTournament4() {
public void prepareTournament5() {
//Create Tournament
tournament5DTO = addTournament(TOURNAMENT5_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TOURNAMENT5_DELAY);
List<FightDTO> fightDTOs = fightController.createFights(tournament5DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament5DTO.getId(), TeamsOrder.SORTED, 0, null));

//P1 vs P4 Win P1
//P2 vs P5 Win P2
Expand Down Expand Up @@ -366,7 +367,7 @@ public void prepareTournament5() {
public void prepareTournament6() {
tournament6DTO = addTournament(TOURNAMENT6_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TOURNAMENT6_DELAY);
//Create Tournament
List<FightDTO> fightDTOs = fightController.createFights(tournament6DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament6DTO.getId(), TeamsOrder.SORTED, 0, null));
//P1 vs P4 Win P1
//P2 vs P5 Win P5 <---
//P3 vs P6 Win P6
Expand Down Expand Up @@ -416,7 +417,7 @@ public void prepareTournament6() {
public void prepareTournament7() {
//Create Tournament
tournament7DTO = addTournament(TOURNAMENT7_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TOURNAMENT7_DELAY);
List<FightDTO> fightDTOs = fightController.createFights(tournament7DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament7DTO.getId(), TeamsOrder.SORTED, 0, null));

//P1 vs P4 Win P1
//P2 vs P5 Win P2
Expand Down Expand Up @@ -468,7 +469,7 @@ public void prepareTournament7() {
public void prepareTournament8() {
tournament8DTO = addTournament(TOURNAMENT8_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TOURNAMENT8_DELAY);
//Create Tournament
List<FightDTO> fightDTOs = fightController.createFights(tournament8DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament8DTO.getId(), TeamsOrder.SORTED, 0, null));
//P1 vs P4 Win P4
//P2 vs P5 Win P2
//P3 vs P6 Win P6 <--
Expand Down Expand Up @@ -518,7 +519,7 @@ public void prepareTournament8() {
public void prepareTournament9() {
//Create Tournament
tournament9DTO = addTournament(TOURNAMENT9_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TOURNAMENT9_DELAY);
List<FightDTO> fightDTOs = fightController.createFights(tournament9DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament9DTO.getId(), TeamsOrder.SORTED, 0, null));

//P1 vs P4 Win P1
//P2 vs P5 Win P2
Expand Down Expand Up @@ -570,7 +571,7 @@ public void prepareTournament9() {
public void prepareTournament10() {
//Create Tournament
tournament10DTO = addTournament(TOURNAMENT10_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TOURNAMENT10_DELAY);
List<FightDTO> fightDTOs = fightController.createFights(tournament10DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament10DTO.getId(), TeamsOrder.SORTED, 0, null));

//P1 vs P4 Win P1
//P2 vs P5 Win P2
Expand Down Expand Up @@ -622,7 +623,7 @@ public void prepareTournament10() {
public void prepareTournament11() {
tournament11DTO = addTournament(TOURNAMENT11_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TOURNAMENT11_DELAY);
//Create Tournament
List<FightDTO> fightDTOs = fightController.createFights(tournament11DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament11DTO.getId(), TeamsOrder.SORTED, 0, null));
//P1 vs P4 Win P4 <-- (Again!)
//P2 vs P5 Win P5
//P3 vs P6 Win P6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest
Expand Down Expand Up @@ -93,7 +94,7 @@ public void prepareData() {
public void prepareTournament1() {
//Create Tournament
tournament1DTO = addTournament(TOURNAMENT1_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TournamentType.LOOP, 2);
List<FightDTO> fightDTOs = fightController.createFights(tournament1DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament1DTO.getId(), TeamsOrder.SORTED, 0, null));

//Winner is Participant2
fightDTOs.get(0).getDuels().get(2).addCompetitor1Score(Score.DO);
Expand Down Expand Up @@ -123,7 +124,7 @@ public void prepareTournament1() {
public void prepareTournament2() {
//Create Tournament
tournament2DTO = addTournament(TOURNAMENT2_NAME, MEMBERS, TEAMS, REFEREES, ORGANIZER, VOLUNTEER, PRESS, TournamentType.KING_OF_THE_MOUNTAIN, 1);
List<FightDTO> fightDTOs = fightController.createFights(tournament2DTO.getId(), TeamsOrder.SORTED, 0, null);
List<FightDTO> fightDTOs = new ArrayList<>(fightController.createFights(tournament2DTO.getId(), TeamsOrder.SORTED, 0, null));

//Winner is Participant2
fightDTOs.get(0).getDuels().get(2).addCompetitor1Score(Score.DO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public RoleList generateClubList(Locale locale, TournamentDTO tournamentDTO) {
}

public TeamList generateTeamList(TournamentDTO tournamentDTO) {
final List<TeamDTO> teams = teamController.getAllByTournament(tournamentDTO, null);
final List<TeamDTO> teams = new ArrayList<>(teamController.getAllByTournament(tournamentDTO, null));
teams.sort(Comparator.comparing(TeamDTO::getName));
return new TeamList(tournamentDTO, teams);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
* #L%
*/

import com.softwaremagico.kt.persistence.encryption.AchievementTypeCryptoConverter;
import com.softwaremagico.kt.persistence.values.AchievementGrade;
import com.softwaremagico.kt.persistence.values.AchievementType;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
Expand Down Expand Up @@ -58,12 +56,10 @@ public class Achievement extends Element {

@Column(name = "achievement_type", nullable = false)
@Enumerated(EnumType.STRING)
@Convert(converter = AchievementTypeCryptoConverter.class)
private AchievementType achievementType;

@Column(name = "achievement_grade", nullable = false)
@Enumerated(EnumType.STRING)
@Convert(converter = AchievementTypeCryptoConverter.class)
private AchievementGrade achievementGrade;

public Achievement() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class AuthenticatedUser implements UserDetails, IAuthenticatedUser {
private String password;

@Column(name = "username")
@Convert(converter = StringCryptoConverter.class)
private String username;

@Column(name = "username_hash", length = SHA512HashGenerator.ALGORITHM_LENGTH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*/

import com.softwaremagico.kt.persistence.encryption.IntegerCryptoConverter;
import com.softwaremagico.kt.persistence.encryption.LocalDateTimeCryptoConverter;
import com.softwaremagico.kt.persistence.encryption.StringCryptoConverter;
import com.softwaremagico.kt.persistence.values.Score;
import jakarta.persistence.Cacheable;
import jakarta.persistence.CollectionTable;
Expand Down Expand Up @@ -110,7 +108,6 @@ public class Duel extends Element {

@Column(name = "type")
@Enumerated(EnumType.STRING)
@Convert(converter = StringCryptoConverter.class)
private DuelType type;

@Column(name = "duration")
Expand All @@ -128,11 +125,9 @@ public class Duel extends Element {
private Tournament tournament;

@Column(name = "started_at")
@Convert(converter = LocalDateTimeCryptoConverter.class)
private LocalDateTime startedAt;

@Column(name = "finished_at")
@Convert(converter = LocalDateTimeCryptoConverter.class)
private LocalDateTime finishedAt;

public Duel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* #L%
*/

import com.softwaremagico.kt.persistence.encryption.LocalDateTimeCryptoConverter;
import com.softwaremagico.kt.persistence.encryption.StringCryptoConverter;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
Expand Down Expand Up @@ -50,15 +49,13 @@ public abstract class Element implements Serializable {

@CreationTimestamp
@Column(name = "created_at")
@Convert(converter = LocalDateTimeCryptoConverter.class)
private LocalDateTime createdAt;

@Column(name = "created_by")
private String createdBy;

@UpdateTimestamp
@Column(name = "updated_at")
@Convert(converter = LocalDateTimeCryptoConverter.class)
private LocalDateTime updatedAt;

@Column(name = "updated_by")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* #L%
*/

import com.softwaremagico.kt.persistence.encryption.IntegerCryptoConverter;
import com.softwaremagico.kt.persistence.encryption.LocalDateTimeCryptoConverter;
import jakarta.persistence.Cacheable;
import jakarta.persistence.CascadeType;
Expand Down Expand Up @@ -67,7 +66,6 @@ public class Fight extends Element {
private Tournament tournament;

@Column(name = "shiaijo", nullable = false)
@Convert(converter = IntegerCryptoConverter.class)
private Integer shiaijo = 0;

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
Expand All @@ -80,7 +78,6 @@ public class Fight extends Element {
private LocalDateTime finishedAt;

@Column(name = "fight_level", nullable = false)
@Convert(converter = IntegerCryptoConverter.class)
private Integer level = 0;

public Fight() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
* #L%
*/

import com.softwaremagico.kt.persistence.encryption.IntegerCryptoConverter;
import jakarta.persistence.Cacheable;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Index;
Expand Down Expand Up @@ -63,7 +61,6 @@ public class Group extends Element {
private List<Team> teams;

@Column(name = "shiaijo", nullable = false)
@Convert(converter = IntegerCryptoConverter.class)
private Integer shiaijo = 0;

@Column(name = "group_level", nullable = false)
Expand All @@ -78,7 +75,6 @@ public class Group extends Element {
private List<Fight> fights;

@Column(name = "number_of_winners", nullable = false)
@Convert(converter = IntegerCryptoConverter.class)
private int numberOfWinners = 1;

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
* #L%
*/

import com.softwaremagico.kt.persistence.encryption.IntegerCryptoConverter;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
Expand All @@ -48,7 +46,6 @@ public class GroupLink extends Element {
private Group destination;

@Column(name = "winner_index", nullable = false)
@Convert(converter = IntegerCryptoConverter.class)
private Integer winner = 0;

public Group getSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* #L%
*/

import com.softwaremagico.kt.persistence.encryption.BooleanCryptoConverter;
import com.softwaremagico.kt.persistence.encryption.IntegerCryptoConverter;
import com.softwaremagico.kt.persistence.encryption.LocalDateTimeCryptoConverter;
import com.softwaremagico.kt.persistence.encryption.StringCryptoConverter;
Expand Down Expand Up @@ -78,7 +77,6 @@ public class Tournament extends Element implements IName {
private Integer duelsDuration = DEFAULT_DURATION;

@Column(name = "locked", nullable = false)
@Convert(converter = BooleanCryptoConverter.class)
private boolean locked = false;

@Column(name = "locked_at")
Expand Down
Loading

0 comments on commit 744e056

Please sign in to comment.