Skip to content

Commit

Permalink
Encrypting createdBy and updatedBy
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaremagico committed May 9, 2024
1 parent 0e48280 commit 5917091
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 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-613h-blueviolet.svg)]()
[![Time](https://img.shields.io/badge/development-613.5h-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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public TournamentExtraProperty getByTournamentAndProperty(Tournament tournament,
}

public List<TournamentExtraProperty> getLatestPropertiesByCreatedBy(String createdBy) {
return getRepository().findDistinctPropertyKeyByCreatedByOrderByCreatedAtDesc(createdBy);
return getRepository().findDistinctPropertyKeyByCreatedByHashOrderByCreatedAtDesc(createdBy);
}

public int delete(Tournament tournament) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public Tournament save(String name, Integer shiaijos, Integer teamSize, Tourname
}

private void setDefaultProperties(Tournament tournament, String username) {
final List<TournamentExtraProperty> properties = tournamentExtraPropertyRepository.findDistinctPropertyKeyByCreatedByOrderByCreatedAtDesc(username);
final List<TournamentExtraProperty> properties = tournamentExtraPropertyRepository.findDistinctPropertyKeyByCreatedByHashOrderByCreatedAtDesc(username);
properties.removeIf(tournamentExtraProperty -> Objects.equals(tournamentExtraProperty.getTournament().getId(), tournament.getId()));
final List<TournamentExtraProperty> newProperties = new ArrayList<>();
properties.forEach(tournamentExtraProperty -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.softwaremagico.kt.persistence.encryption.SHA512HashGenerator;
import com.softwaremagico.kt.persistence.encryption.StringCryptoConverter;
import com.softwaremagico.kt.security.AvailableRole;
import jakarta.persistence.Access;
import jakarta.persistence.AccessType;
import jakarta.persistence.Cacheable;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
Expand Down Expand Up @@ -61,6 +63,7 @@ public class AuthenticatedUser implements UserDetails, IAuthenticatedUser {
@Convert(converter = BCryptPasswordConverter.class)
private String password;

@Access(AccessType.PROPERTY)
@Column(name = "username")
@Convert(converter = StringCryptoConverter.class)
private String username;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
* #L%
*/

import com.softwaremagico.kt.persistence.encryption.SHA512HashGenerator;
import com.softwaremagico.kt.persistence.encryption.StringCryptoConverter;
import jakarta.persistence.Access;
import jakarta.persistence.AccessType;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.GeneratedValue;
Expand Down Expand Up @@ -51,17 +54,28 @@ public abstract class Element implements Serializable {
@Column(name = "created_at")
private LocalDateTime createdAt;

@Access(AccessType.PROPERTY)
@Column(name = "created_by")
@Convert(converter = StringCryptoConverter.class)
private String createdBy;

@Column(name = "created_by_hash", length = SHA512HashGenerator.ALGORITHM_LENGTH)
@Convert(converter = SHA512HashGenerator.class)
private String createdByHash;

@UpdateTimestamp
@Column(name = "updated_at")
private LocalDateTime updatedAt;

@Access(AccessType.PROPERTY)
@Column(name = "updated_by")
@Convert(converter = StringCryptoConverter.class)
private String updatedBy;

@Column(name = "updated_by_hash", length = SHA512HashGenerator.ALGORITHM_LENGTH)
@Convert(converter = SHA512HashGenerator.class)
private String updatedByHash;

@Version
private Integer version;

Expand Down Expand Up @@ -95,6 +109,15 @@ public String getCreatedBy() {

public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
this.createdByHash = createdBy;
}

public String getCreatedByHash() {
return createdByHash;
}

public void setCreatedByHash(String createdByHash) {
this.createdByHash = createdByHash;
}

public String getUpdatedBy() {
Expand All @@ -103,6 +126,15 @@ public String getUpdatedBy() {

public void setUpdatedBy(String updatedBy) {
this.updatedBy = updatedBy;
this.updatedByHash = updatedBy;
}

public String getUpdatedByHash() {
return updatedByHash;
}

public void setUpdatedByHash(String updatedByHash) {
this.updatedByHash = updatedByHash;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public interface TournamentExtraPropertyRepository extends JpaRepository<Tournam
@Query("""
Select p from TournamentExtraProperty p WHERE
p.id IN (SELECT max(p2.id) FROM TournamentExtraProperty p2 WHERE
(:createdBy IS NULL OR p2.createdBy=:createdBy) GROUP BY p2.propertyKey)
(:createdBy IS NULL OR p2.createdByHash=:createdBy) GROUP BY p2.propertyKey)
""")
List<TournamentExtraProperty> findDistinctPropertyKeyByCreatedByOrderByCreatedAtDesc(@Param("createdBy") String createdBy);
List<TournamentExtraProperty> findDistinctPropertyKeyByCreatedByHashOrderByCreatedAtDesc(@Param("createdBy") String createdBy);

}

0 comments on commit 5917091

Please sign in to comment.