Skip to content

Commit

Permalink
Merge pull request #410 from softwaremagico/393-encryption-not-workin…
Browse files Browse the repository at this point in the history
…g-after-restarting-the-server

393 encryption not working after restarting the server
  • Loading branch information
softwaremagico authored May 8, 2024
2 parents 2eddc04 + 744e056 commit a91f34c
Show file tree
Hide file tree
Showing 34 changed files with 160 additions and 99 deletions.
6 changes: 4 additions & 2 deletions 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-608.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 All @@ -28,7 +28,9 @@ kendo club. Including experience from several fighting structures that we had ex
of the previous version of this software. The goal is to have enough flexibility to be at the service of your club, and
not the other way around.

<img align="middle" src="https://github.com/softwaremagico/KendoTournamentManager/wiki/images/Scores-Example.png" width="500" alt="Scores example">
<p align="center">
<img src="https://github.com/softwaremagico/KendoTournamentManager/wiki/images/Scores-Example.png" width="500" alt="Scores example">
</p>p>

This tool is a complete rebuild from the old
tool Kendo Tournament Generator [[1]](https://sourceforge.net/projects/kendotournament/files/) [[2]](https://github.com/softwaremagico/KendoTournament) with the
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 @@ -1969,7 +1969,6 @@ private List<Achievement> generateStormtrooperSyndromeAchievement(Tournament tou
* Somebody wins a fight despite the opponent has scored first.
*
* @param tournament
* @return
*/
private List<Achievement> generateVendettaAchievement(Tournament tournament) {
final List<Participant> participants = new ArrayList<>();
Expand All @@ -1995,7 +1994,6 @@ private List<Achievement> generateVendettaAchievement(Tournament tournament) {
* Somebody wins a fight against other participant that is always winning him.
*
* @param tournament
* @return
*/
private List<Achievement> generateSithApprenticesAlwaysKillTheirMasterAchievement(Tournament tournament) {
final List<Achievement> achievements = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
@Controller
public class CacheController {

@Autowired(required = false)
private CacheManager cacheManager;
private final CacheManager cacheManager;

public CacheController(@Autowired(required = false) CacheManager cacheManager) {
this.cacheManager = cacheManager;
}


public void deleteAllCache() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void validate(DuelDTO dto) throws ValidateBadRequestException {
}
}

@Override
@CacheEvict(allEntries = true, value = {"ranking", "competitors-ranking"})
public DuelDTO update(DuelDTO duel, String username) {
try {
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 All @@ -44,14 +43,14 @@ public List<T> convertAll(Collection<R> from) {
if (from == null) {
return new ArrayList<>();
}
return from.stream().map(this::convert).collect(Collectors.toList());
return from.stream().map(this::convert).toList();
}

@Override
public List<F> reverseAll(Collection<T> to) {
if (to == null) {
return new ArrayList<>();
}
return to.stream().map(this::reverse).collect(Collectors.toList());
return to.stream().map(this::reverse).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ public Optional<IAuthenticatedUser> findByUsername(String username) {
guest.setRoles(Collections.singleton(GUEST_ROLE));
return Optional.of(guest);
}
final Optional<AuthenticatedUser> authenticatedUser = authenticatedUserRepository.findByUsername(username);
final Optional<AuthenticatedUser> authenticatedUser = authenticatedUserRepository
.findByUsernameHash(username);
if (authenticatedUser.isPresent()) {
authenticatedUser.get().setUsernameHash(authenticatedUser.get().getUsername());
return Optional.of(authenticatedUser.get());
}
final Optional<Participant> participant = participantProvider.findByTokenUsername(username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
public class ParticipantFightStatisticsProvider extends CrudProvider<ParticipantFightStatistics, Integer, ParticipantFightStatisticsRepository> {
Expand Down Expand Up @@ -161,7 +160,7 @@ public ParticipantFightStatistics get(Participant participant) {

private void populateScores(ParticipantFightStatistics participantFightStatistics, List<Score> scores) {
//Remove null values
scores = scores.parallelStream().filter(Objects::nonNull).collect(Collectors.toList());
scores = scores.parallelStream().filter(Objects::nonNull).toList();
for (final Score score : scores) {
switch (score) {
case MEN -> participantFightStatistics.setMenNumber(participantFightStatistics.getMenNumber() + 1);
Expand All @@ -181,7 +180,7 @@ private void populateScores(ParticipantFightStatistics participantFightStatistic

private void populateReceivedScores(ParticipantFightStatistics participantFightStatistics, List<Score> scores) {
//Remove null values
scores = scores.parallelStream().filter(Objects::nonNull).collect(Collectors.toList());
scores = scores.parallelStream().filter(Objects::nonNull).toList();
for (final Score score : scores) {
switch (score) {
case MEN ->
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 @@ -62,7 +62,7 @@ public void checkDefaultProperties() {
//Another tournament
Tournament tournament2 = new Tournament("Tournament2", 1, 3, TournamentType.LEAGUE, USER);
tournament2 = tournamentProvider.save(tournament2);
//Has a default one.
//Has a default one, copied from previous one.
Assert.assertEquals(tournamentExtraPropertyProvider.getAll(tournament2).size(), 1);
Assert.assertEquals(tournamentExtraPropertyProvider.getAll(tournament2).get(0).getPropertyValue(), "2");

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
Loading

0 comments on commit a91f34c

Please sign in to comment.