-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from quotly-eu/feature/rest-endpoints
#4: Smaller changes for the user restendpoint
- Loading branch information
Showing
5 changed files
with
89 additions
and
14 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/main/java/eu/quotly/converter/UserEntityConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package eu.quotly.converter; | ||
|
||
import eu.quotly.dto.UserDto; | ||
import eu.quotly.entity.UserEntity; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class UserEntityConverter { | ||
public UserDto toUserDto(UserEntity userEntity) { | ||
return new UserDto( | ||
userEntity.getDiscordId(), | ||
userEntity.getDisplayName(), | ||
userEntity.getEmailAddress(), | ||
userEntity.getCreationTime() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/eu/quotly/entity/listener/UserEntityListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package eu.quotly.entity.listener; | ||
|
||
import eu.quotly.config.QuotlyConfig; | ||
import eu.quotly.entity.UserEntity; | ||
import eu.quotly.service.EmailEncryptionService; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.persistence.PostLoad; | ||
import jakarta.persistence.PrePersist; | ||
import jakarta.persistence.PreUpdate; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@ApplicationScoped | ||
public class UserEntityListener { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(UserEntityListener.class); | ||
|
||
@Inject | ||
EmailEncryptionService emailEncryptionService; | ||
|
||
@Inject | ||
QuotlyConfig quotlyConfig; | ||
|
||
@PrePersist | ||
@PreUpdate | ||
public void encryptSensitiveData(UserEntity user) { | ||
if (quotlyConfig.isEmailEncryptionEnabled()) { | ||
String emailAddress = user.getEmailAddress(); | ||
try { | ||
user.setEmailAddress(emailEncryptionService.getEncryptedEmailAddress(user)); | ||
} catch (Exception exception) { | ||
LOGGER.error("Unable to encrypt email address from user {}", user.getDisplayName(), exception); | ||
user.setEmailAddress(emailAddress); | ||
} | ||
} | ||
} | ||
|
||
@PostLoad | ||
public void decryptSensitiveData(UserEntity user) { | ||
String emailAddress = user.getEmailAddress(); | ||
try { | ||
user.setEmailAddress(emailEncryptionService.getDecryptedEmailAddress(user)); | ||
} catch (Exception exception) { | ||
LOGGER.error("Unable to decrypt email address from user {}", user.getDisplayName(), exception); | ||
user.setEmailAddress(emailAddress); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters