-
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.
Fix #194: Missing decryption on fetch
- Loading branch information
1 parent
2c8267a
commit 93b0599
Showing
6 changed files
with
16 additions
and
111 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -19,57 +19,21 @@ | |
|
||
import com.wultra.security.userdatastore.client.model.dto.AttachmentDto; | ||
import com.wultra.security.userdatastore.model.entity.AttachmentEntity; | ||
import com.wultra.security.userdatastore.model.entity.DocumentEntity; | ||
import com.wultra.security.userdatastore.model.repository.DocumentRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import com.wultra.security.userdatastore.service.EncryptionService; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Converter for attachments. | ||
* | ||
* @author Roman Strobl, [email protected] | ||
*/ | ||
@Component | ||
@AllArgsConstructor | ||
public class AttachmentConverter { | ||
|
||
private final DocumentRepository documentRepository; | ||
|
||
/** | ||
* Converter constructor. | ||
* @param documentRepository Document repository. | ||
*/ | ||
@Autowired | ||
public AttachmentConverter(DocumentRepository documentRepository) { | ||
this.documentRepository = documentRepository; | ||
} | ||
|
||
/** | ||
* Convert {@link AttachmentDto} to {@link AttachmentEntity}. | ||
* @param attachment Attachment DTO. | ||
* @return Attachment entity. | ||
*/ | ||
public AttachmentEntity toAttachmentEntity(final AttachmentDto attachment) { | ||
if (attachment == null) { | ||
return null; | ||
} | ||
|
||
final Optional<DocumentEntity> documentEntityOptional = documentRepository.findById(attachment.documentId()); | ||
if (documentEntityOptional.isEmpty()) { | ||
return null; | ||
} | ||
|
||
final AttachmentEntity entity = new AttachmentEntity(); | ||
entity.setId(attachment.id()); | ||
entity.setDocument(documentEntityOptional.get()); | ||
entity.setAttachmentData(attachment.attachmentData()); | ||
entity.setAttachmentType(attachment.attachmentType()); | ||
entity.setExternalId(attachment.externalId()); | ||
entity.setTimestampCreated(attachment.timestampCreated()); | ||
entity.setTimestampLastUpdated(attachment.timestampLastUpdated()); | ||
return entity; | ||
} | ||
private final EncryptionService encryptionService; | ||
|
||
/** | ||
* Convert {@link AttachmentEntity} to {@link AttachmentDto}. | ||
|
@@ -84,7 +48,7 @@ public AttachmentDto toAttachment(final AttachmentEntity entity) { | |
return AttachmentDto.builder() | ||
.id(entity.getId()) | ||
.documentId(entity.getDocument().getId()) | ||
.attachmentData(entity.getAttachmentData()) | ||
.attachmentData(encryptionService.decryptAttachment(entity)) | ||
.attachmentType(entity.getAttachmentType()) | ||
.externalId(entity.getExternalId()) | ||
.timestampCreated(entity.getTimestampCreated()) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,58 +18,22 @@ | |
package com.wultra.security.userdatastore.converter; | ||
|
||
import com.wultra.security.userdatastore.client.model.dto.PhotoDto; | ||
import com.wultra.security.userdatastore.model.entity.DocumentEntity; | ||
import com.wultra.security.userdatastore.model.entity.PhotoEntity; | ||
import com.wultra.security.userdatastore.model.repository.DocumentRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import com.wultra.security.userdatastore.service.EncryptionService; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Converter for photos. | ||
* | ||
* @author Roman Strobl, [email protected] | ||
*/ | ||
@Component | ||
@AllArgsConstructor | ||
public class PhotoConverter { | ||
|
||
private final DocumentRepository documentRepository; | ||
|
||
/** | ||
* Converter constructor. | ||
* @param documentRepository Document repository. | ||
*/ | ||
@Autowired | ||
public PhotoConverter(DocumentRepository documentRepository) { | ||
this.documentRepository = documentRepository; | ||
} | ||
|
||
/** | ||
* Convert {@link PhotoDto} to {@link PhotoEntity}. | ||
* @param photo Photo DTO. | ||
* @return Photo entity. | ||
*/ | ||
public PhotoEntity toPhotoEntity(final PhotoDto photo) { | ||
if (photo == null) { | ||
return null; | ||
} | ||
|
||
final Optional<DocumentEntity> documentEntityOptional = documentRepository.findById(photo.documentId()); | ||
if (documentEntityOptional.isEmpty()) { | ||
return null; | ||
} | ||
|
||
final PhotoEntity entity = new PhotoEntity(); | ||
entity.setId(photo.id()); | ||
entity.setDocument(documentEntityOptional.get()); | ||
entity.setPhotoData(photo.photoData()); | ||
entity.setPhotoType(photo.photoType()); | ||
entity.setExternalId(photo.externalId()); | ||
entity.setTimestampCreated(photo.timestampCreated()); | ||
entity.setTimestampLastUpdated(photo.timestampLastUpdated()); | ||
return entity; | ||
} | ||
private final EncryptionService encryptionService; | ||
|
||
/** | ||
* Convert {@link PhotoEntity} to {@link PhotoDto}. | ||
|
@@ -84,7 +48,7 @@ public PhotoDto toPhoto(final PhotoEntity entity) { | |
return PhotoDto.builder() | ||
.id(entity.getId()) | ||
.documentId(entity.getDocument().getId()) | ||
.photoData(entity.getPhotoData()) | ||
.photoData(encryptionService.decryptPhoto(entity)) | ||
.photoType(entity.getPhotoType()) | ||
.externalId(entity.getExternalId()) | ||
.timestampCreated(entity.getTimestampCreated()) | ||
|
@@ -93,4 +57,3 @@ public PhotoDto toPhoto(final PhotoEntity entity) { | |
} | ||
|
||
} | ||
|
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
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