Pull request #569: RED-5563 - SMTP migration
Merge in RED/persistence-service from RED-5563 to master * commit 'ff3fb03f2936e85a50b00431a57390864e440232': RED-5563 - SMTP migration
This commit is contained in:
commit
5c5c3f9cc3
@ -40,16 +40,22 @@ public class SMTPConfigurationService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void encryptPasswordIfNecessary() {
|
public void encryptPasswordIfNecessary() {
|
||||||
var smtpConfiguration = getConfiguration();
|
var smtpConfigurationOptional = smtpRepository.findById(SMTPConfigurationEntity.ID);
|
||||||
try {
|
|
||||||
// this makes the migration idempotent, since an exception will be thrown if the password can't be decrypted
|
|
||||||
// this prevents double encryption if the migration runs more than once
|
|
||||||
|
|
||||||
encryptionDecryptionService.decrypt(smtpConfiguration.getPassword());
|
if(smtpConfigurationOptional.isPresent()) {
|
||||||
log.info("SMTP Password for id {} is already encrypted", smtpConfiguration.getId());
|
var smtpConfiguration = smtpConfigurationOptional.get();
|
||||||
} catch (Exception e) {
|
try {
|
||||||
log.info("Encrypting SMTP Password for id {}", smtpConfiguration.getId());
|
// this makes the migration idempotent, since an exception will be thrown if the password can't be decrypted
|
||||||
smtpConfiguration.setPassword(encryptionDecryptionService.encrypt(smtpConfiguration.getPassword()));
|
// this prevents double encryption if the migration runs more than once
|
||||||
|
|
||||||
|
encryptionDecryptionService.decrypt(smtpConfiguration.getPassword());
|
||||||
|
log.info("SMTP Password for id {} is already encrypted", smtpConfiguration.getId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("Encrypting SMTP Password for id {}", smtpConfiguration.getId());
|
||||||
|
smtpConfiguration.setPassword(encryptionDecryptionService.encrypt(smtpConfiguration.getPassword()));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
log.info("NO SMPT Configuration present for migration!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user