From 0b357e857c9b89f5cc9f1a8735f2bbab701677f5 Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Thu, 24 Aug 2023 15:45:43 +0200 Subject: [PATCH 01/14] Fix #971: Add column for signature metadata - Add new column signature_metadata, remove merged columns signature_data_method and signature_data_uri_id, document it in liquibase - Edit entity class, introduce new converter --- ...0824-update-signature-metadata-columns.xml | 53 +++++++++++++ .../1.5.x/db.changelog-version.xml | 1 + .../database/model/SignatureMetadata.java | 11 +++ .../converter/SignatureMetadataConverter.java | 78 +++++++++++++++++++ .../model/entity/SignatureEntity.java | 66 +++++----------- 5 files changed, 164 insertions(+), 45 deletions(-) create mode 100644 docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230824-update-signature-metadata-columns.xml create mode 100644 powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java create mode 100644 powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java diff --git a/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230824-update-signature-metadata-columns.xml b/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230824-update-signature-metadata-columns.xml new file mode 100644 index 000000000..dd4cf7441 --- /dev/null +++ b/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230824-update-signature-metadata-columns.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + Add signature_metadata column of type JSON + + + + + + + + + + + + + + Migrate data from signature_data_method and signature_data_uri_id to signature_metadata + + UPDATE pa_signature_audit + SET signature_metadata = jsonb_build_object( + 'signature_data_method', signature_data_method, + 'signature_data_uri_id', signature_data_uri_id + ); + + + + + + + + + + + + Drop old columns signature_data_method and signature_data_uri_id + + + + + diff --git a/docs/db/changelog/changesets/powerauth-java-server/1.5.x/db.changelog-version.xml b/docs/db/changelog/changesets/powerauth-java-server/1.5.x/db.changelog-version.xml index 20cffd003..40250a102 100644 --- a/docs/db/changelog/changesets/powerauth-java-server/1.5.x/db.changelog-version.xml +++ b/docs/db/changelog/changesets/powerauth-java-server/1.5.x/db.changelog-version.xml @@ -6,5 +6,6 @@ + \ No newline at end of file diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java new file mode 100644 index 000000000..ea526919b --- /dev/null +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java @@ -0,0 +1,11 @@ +package io.getlime.security.powerauth.app.server.database.model; + +import lombok.Data; + +@Data +public class SignatureMetadata { + + private String signatureDataMethod; + + private String signatureDataUriId; +} diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java new file mode 100644 index 000000000..78a3fe588 --- /dev/null +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java @@ -0,0 +1,78 @@ +/* + * PowerAuth Server and related software components + * Copyright (C) 2023 Wultra s.r.o. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package io.getlime.security.powerauth.app.server.database.model.converter; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.getlime.security.powerauth.app.server.database.model.SignatureMetadata; +import jakarta.persistence.AttributeConverter; +import jakarta.persistence.Converter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * Converts between SignatureMetadata object and JSON serialized + * storage in database column. + * + * @author Your Name + */ +@Converter +@Component +public class SignatureMetadataConverter implements AttributeConverter { + + private static final Logger logger = LoggerFactory.getLogger(SignatureMetadataConverter.class); + + private final ObjectMapper objectMapper; + + /** + * Converter constructor. + * @param objectMapper Object mapper. + */ + public SignatureMetadataConverter(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + + @Override + public String convertToDatabaseColumn(SignatureMetadata signatureMetadata) { + if (signatureMetadata == null) { + return "{}"; + } + try { + return objectMapper.writeValueAsString(signatureMetadata); + } catch (JsonProcessingException ex) { + logger.warn("Conversion failed for SignatureMetadata, error: " + ex.getMessage(), ex); + return "{}"; + } + } + + @Override + public SignatureMetadata convertToEntityAttribute(String s) { + if (s == null || s.isEmpty()) { + return new SignatureMetadata(); + } + try { + return objectMapper.readValue(s, SignatureMetadata.class); + } catch (JsonProcessingException ex) { + logger.warn("Conversion failed for SignatureMetadata, error: " + ex.getMessage(), ex); + return new SignatureMetadata(); + } + } + +} diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/entity/SignatureEntity.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/entity/SignatureEntity.java index 7b410035c..9f3688ae3 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/entity/SignatureEntity.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/entity/SignatureEntity.java @@ -17,7 +17,9 @@ */ package io.getlime.security.powerauth.app.server.database.model.entity; +import io.getlime.security.powerauth.app.server.database.model.SignatureMetadata; import io.getlime.security.powerauth.app.server.database.model.converter.ActivationStatusConverter; +import io.getlime.security.powerauth.app.server.database.model.converter.SignatureMetadataConverter; import io.getlime.security.powerauth.app.server.database.model.enumeration.ActivationStatus; import jakarta.persistence.*; @@ -73,11 +75,9 @@ public class SignatureEntity implements Serializable { @Column(name = "signature", nullable = false, updatable = false) private String signature; - @Column(name = "signature_data_method", updatable = false) - private String signatureDataMethod; - - @Column(name = "signature_data_uri_id", updatable = false) - private String signatureDataUriId; + @Column(name = "signature_metadata") + @Convert(converter = SignatureMetadataConverter.class) + private SignatureMetadata signatureMetadata; @Column(name = "signature_data_body", updatable = false) private String signatureDataBody; @@ -104,7 +104,7 @@ public SignatureEntity() { * Constructor with all properties. * * @param id Signature audit item record ID. - * @param activation Associated activation, or null of no related activation was found. + * @param activation Associated activation, or null if no related activation was found. * @param activationCounter Activation counter at the time of signature computation attempt, or 0 if activation is null. * @param activationCtrDataBase64 Activation counter data at the time of signature computation attempt, or null if only numeric counter is used. * @param activationStatus Activation status at the time of signature computation attempt. @@ -112,13 +112,13 @@ public SignatureEntity() { * @param signatureVersion Requested signature version. * @param signatureType Requested signature type. * @param signature Signature value. - * @param signatureDataMethod Signature data method. - * @param signatureDataUriId Signature data URI identifier. + * @param signatureMetadata Metadata related to the signature. * @param signatureDataBody Signature data body. * @param additionalInfo Additional information related to this signature. * @param note Signature audit log note, with more information about the log reason. * @param valid True if the signature was valid, false otherwise. - * @param timestampCreated Created timestapm. + * @param timestampCreated Created timestamp. + * @param version Version of the signature entity. */ public SignatureEntity( Long id, @@ -130,8 +130,7 @@ public SignatureEntity( String signatureVersion, String signatureType, String signature, - String signatureDataMethod, - String signatureDataUriId, + SignatureMetadata signatureMetadata, String signatureDataBody, String additionalInfo, String note, @@ -148,8 +147,7 @@ public SignatureEntity( this.signatureVersion = signatureVersion; this.signatureType = signatureType; this.signature = signature; - this.signatureDataMethod = signatureDataMethod; - this.signatureDataUriId = signatureDataUriId; + this.signatureMetadata = signatureMetadata; this.signatureDataBody = signatureDataBody; this.additionalInfo = additionalInfo; this.note = note; @@ -337,39 +335,21 @@ public void setSignature(String signature) { } /** - * Get signature data HTTP method. + * Get the signature metadata associated with this signature. * - * @return Signature data HTTP method. + * @return Signature metadata. */ - public String getSignatureDataMethod() { - return signatureDataMethod; + public SignatureMetadata getSignatureMetadata() { + return signatureMetadata; } /** - * Set signature data HTTP method. + * Set the signature metadata associated with this signature. * - * @param signatureDataMethod Signature data HTTP method. + * @param signatureMetadata Metadata related to the signature. */ - public void setSignatureDataMethod(String signatureDataMethod) { - this.signatureDataMethod = signatureDataMethod; - } - - /** - * Get signature data resource URI identifier. - * - * @return Signature data resource URI identifier. - */ - public String getSignatureDataUriId() { - return signatureDataUriId; - } - - /** - * Set signature data resource URI identifier. - * - * @param signatureDataUriId Signature data URI identifier. - */ - public void setSignatureDataUriId(String signatureDataUriId) { - this.signatureDataUriId = signatureDataUriId; + public void setSignatureMetadata(SignatureMetadata signatureMetadata) { + this.signatureMetadata = signatureMetadata; } /** @@ -468,8 +448,7 @@ public int hashCode() { hash = 23 * hash + Objects.hashCode(this.dataBase64); hash = 23 * hash + Objects.hashCode(this.signatureType); hash = 23 * hash + Objects.hashCode(this.signature); - hash = 23 * hash + Objects.hashCode(this.signatureDataMethod); - hash = 23 * hash + Objects.hashCode(this.signatureDataUriId); + hash = 23 * hash + Objects.hashCode(this.signatureMetadata); hash = 23 * hash + Objects.hashCode(this.signatureDataBody); hash = 23 * hash + Objects.hashCode(this.additionalInfo); hash = 23 * hash + Objects.hashCode(this.note); @@ -500,10 +479,7 @@ public boolean equals(Object obj) { if (!Objects.equals(this.signature, other.signature)) { return false; } - if (!Objects.equals(this.signatureDataMethod, other.signatureDataMethod)) { - return false; - } - if (!Objects.equals(this.signatureDataUriId, other.signatureDataUriId)) { + if (!Objects.equals(this.signatureMetadata, other.signatureMetadata)) { return false; } if (!Objects.equals(this.signatureDataBody, other.signatureDataBody)) { From 1f1c3edab3f0bbaf0503669331284fb9df85c60d Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Thu, 24 Aug 2023 15:58:55 +0200 Subject: [PATCH 02/14] Fix #971: Add column for signature metadata - Propagate changes --- .../app/server/database/model/SignatureMetadata.java | 2 ++ .../service/behavior/tasks/AuditingServiceBehavior.java | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java index ea526919b..11b9a6259 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java @@ -1,8 +1,10 @@ package io.getlime.security.powerauth.app.server.database.model; +import lombok.AllArgsConstructor; import lombok.Data; @Data +@AllArgsConstructor public class SignatureMetadata { private String signatureDataMethod; diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/AuditingServiceBehavior.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/AuditingServiceBehavior.java index e0c8f29b9..173dc88eb 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/AuditingServiceBehavior.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/AuditingServiceBehavior.java @@ -26,6 +26,7 @@ import io.getlime.security.powerauth.app.server.converter.ActivationStatusConverter; import io.getlime.security.powerauth.app.server.converter.KeyValueMapConverter; import io.getlime.security.powerauth.app.server.converter.SignatureTypeConverter; +import io.getlime.security.powerauth.app.server.database.model.SignatureMetadata; import io.getlime.security.powerauth.app.server.database.model.entity.ActivationRecordEntity; import io.getlime.security.powerauth.app.server.database.model.entity.SignatureEntity; import io.getlime.security.powerauth.app.server.database.model.enumeration.ActivationStatus; @@ -157,6 +158,7 @@ public void logSignatureAuditRecord(ActivationRecordDto activation, SignatureDat // Audit the signature final SignatureEntity signatureAuditRecord = new SignatureEntity(); + final SignatureMetadata signatureMetadata = new SignatureMetadata(signatureData.getRequestMethod(), signatureData.getRequestUriId()); signatureAuditRecord.setActivation(activationRepository.getReferenceById(activation.getActivationId())); signatureAuditRecord.setActivationCounter(activation.getCounter()); signatureAuditRecord.setActivationCtrDataBase64(activation.getCtrDataBase64()); @@ -164,8 +166,7 @@ public void logSignatureAuditRecord(ActivationRecordDto activation, SignatureDat signatureAuditRecord.setAdditionalInfo(additionalInfo); signatureAuditRecord.setDataBase64(data); signatureAuditRecord.setSignature(signatureData.getSignature()); - signatureAuditRecord.setSignatureDataMethod(signatureData.getRequestMethod()); - signatureAuditRecord.setSignatureDataUriId(signatureData.getRequestUriId()); + signatureAuditRecord.setSignatureMetadata(signatureMetadata); signatureAuditRecord.setSignatureDataBody(signatureData.getRequestBody()); signatureAuditRecord.setSignatureType(signatureType.name()); signatureAuditRecord.setSignatureVersion(signatureData.getSignatureVersion()); From 4c19310f0c52b2de099a64e39ecededbece6a98f Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Tue, 29 Aug 2023 00:45:55 +0200 Subject: [PATCH 03/14] Fix #971: Add column for signature metadata - Add NoArgsConstructor --- .../powerauth/app/server/database/model/SignatureMetadata.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java index 11b9a6259..98db73ed8 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java @@ -2,9 +2,11 @@ import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; @Data @AllArgsConstructor +@NoArgsConstructor public class SignatureMetadata { private String signatureDataMethod; From fe2e837b2701e04f72e188b658f943f196aa6f91 Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Tue, 29 Aug 2023 13:21:33 +0200 Subject: [PATCH 04/14] Fix #971: Add column for signature metadata - Make the change retrospective in terms of liquibase --- ...20230323-add-column-signature-metadata.xml | 18 +++++++ .../20230323-add-columns-signature-data.xml | 42 --------------- ...0824-update-signature-metadata-columns.xml | 53 ------------------- .../1.5.x/db.changelog-version.xml | 3 +- .../converter/SignatureMetadataConverter.java | 2 + 5 files changed, 21 insertions(+), 97 deletions(-) create mode 100644 docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230323-add-column-signature-metadata.xml delete mode 100644 docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230323-add-columns-signature-data.xml delete mode 100644 docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230824-update-signature-metadata-columns.xml diff --git a/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230323-add-column-signature-metadata.xml b/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230323-add-column-signature-metadata.xml new file mode 100644 index 000000000..37c630a44 --- /dev/null +++ b/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230323-add-column-signature-metadata.xml @@ -0,0 +1,18 @@ + + + + + + + + + + Add signature_metadata column of type JSONB + + + + + + diff --git a/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230323-add-columns-signature-data.xml b/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230323-add-columns-signature-data.xml deleted file mode 100644 index b99f2b623..000000000 --- a/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230323-add-columns-signature-data.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - Add signature_data_method column - - - - - - - - - - - - Add signature_data_uri_id column - - - - - - - - - - - - Add signature_data_body column - - - - - - diff --git a/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230824-update-signature-metadata-columns.xml b/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230824-update-signature-metadata-columns.xml deleted file mode 100644 index dd4cf7441..000000000 --- a/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230824-update-signature-metadata-columns.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - Add signature_metadata column of type JSON - - - - - - - - - - - - - - Migrate data from signature_data_method and signature_data_uri_id to signature_metadata - - UPDATE pa_signature_audit - SET signature_metadata = jsonb_build_object( - 'signature_data_method', signature_data_method, - 'signature_data_uri_id', signature_data_uri_id - ); - - - - - - - - - - - - Drop old columns signature_data_method and signature_data_uri_id - - - - - diff --git a/docs/db/changelog/changesets/powerauth-java-server/1.5.x/db.changelog-version.xml b/docs/db/changelog/changesets/powerauth-java-server/1.5.x/db.changelog-version.xml index 40250a102..cbb1867c5 100644 --- a/docs/db/changelog/changesets/powerauth-java-server/1.5.x/db.changelog-version.xml +++ b/docs/db/changelog/changesets/powerauth-java-server/1.5.x/db.changelog-version.xml @@ -3,9 +3,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd"> - + - \ No newline at end of file diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java index 78a3fe588..779b2d50a 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java @@ -25,6 +25,7 @@ import jakarta.persistence.Converter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -45,6 +46,7 @@ public class SignatureMetadataConverter implements AttributeConverter Date: Wed, 30 Aug 2023 22:26:38 +0200 Subject: [PATCH 05/14] Fix #971: Add column for signature metadata - Introduce abstraction for SignatureMetadata --- .../model/PowerAuthSignatureMetadata.java | 34 +++++++++++++++++++ .../database/model/SignatureMetadata.java | 17 +++++----- .../converter/SignatureMetadataConverter.java | 27 +++++++-------- .../model/entity/SignatureEntity.java | 10 +++--- .../tasks/AuditingServiceBehavior.java | 4 +-- 5 files changed, 61 insertions(+), 31 deletions(-) create mode 100644 powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java new file mode 100644 index 000000000..717bb2309 --- /dev/null +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java @@ -0,0 +1,34 @@ +package io.getlime.security.powerauth.app.server.database.model; + +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@NoArgsConstructor +public class PowerAuthSignatureMetadata implements SignatureMetadata { + + private String signatureDataMethod; + + private String signatureDataUriId; + + + @Override + public String getMetadataParam1() { + return signatureDataMethod; + } + + @Override + public void setMetadataParam1(String metadataParam1) { + this.signatureDataMethod = metadataParam1; + } + + @Override + public String getMetadataParam2() { + return signatureDataUriId; + } + + @Override + public void setMetadataParam2(String metadataParam2) { + this.signatureDataUriId = metadataParam2; + } +} diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java index 98db73ed8..c01e64f01 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java @@ -1,15 +1,14 @@ package io.getlime.security.powerauth.app.server.database.model; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -@Data -@AllArgsConstructor -@NoArgsConstructor -public class SignatureMetadata { +public interface SignatureMetadata { - private String signatureDataMethod; + T1 getMetadataParam1(); + + void setMetadataParam1(T1 metadataParam1); + + T2 getMetadataParam2(); + + void setMetadataParam2(T2 metadataParam2); - private String signatureDataUriId; } diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java index 779b2d50a..7fc5ad126 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java @@ -19,6 +19,7 @@ package io.getlime.security.powerauth.app.server.database.model.converter; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import io.getlime.security.powerauth.app.server.database.model.SignatureMetadata; import jakarta.persistence.AttributeConverter; @@ -32,49 +33,45 @@ * Converts between SignatureMetadata object and JSON serialized * storage in database column. * - * @author Your Name + * @author Jan Dusil */ @Converter @Component -public class SignatureMetadataConverter implements AttributeConverter { +public class SignatureMetadataConverter> implements AttributeConverter { private static final Logger logger = LoggerFactory.getLogger(SignatureMetadataConverter.class); private final ObjectMapper objectMapper; - /** - * Converter constructor. - * @param objectMapper Object mapper. - */ @Autowired public SignatureMetadataConverter(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } @Override - public String convertToDatabaseColumn(SignatureMetadata signatureMetadata) { - if (signatureMetadata == null) { + public String convertToDatabaseColumn(T attribute) { + if (attribute == null) { return "{}"; } try { - return objectMapper.writeValueAsString(signatureMetadata); + return objectMapper.writeValueAsString(attribute); } catch (JsonProcessingException ex) { - logger.warn("Conversion failed for SignatureMetadata, error: " + ex.getMessage(), ex); + logger.warn("JSON writing error", ex); return "{}"; } } @Override - public SignatureMetadata convertToEntityAttribute(String s) { + public T convertToEntityAttribute(String s) { if (s == null || s.isEmpty()) { - return new SignatureMetadata(); + return null; } try { - return objectMapper.readValue(s, SignatureMetadata.class); + return objectMapper.readValue(s, new TypeReference<>() { + }); } catch (JsonProcessingException ex) { logger.warn("Conversion failed for SignatureMetadata, error: " + ex.getMessage(), ex); - return new SignatureMetadata(); + return null; } } - } diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/entity/SignatureEntity.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/entity/SignatureEntity.java index 9f3688ae3..7ff86b51a 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/entity/SignatureEntity.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/entity/SignatureEntity.java @@ -17,7 +17,7 @@ */ package io.getlime.security.powerauth.app.server.database.model.entity; -import io.getlime.security.powerauth.app.server.database.model.SignatureMetadata; +import io.getlime.security.powerauth.app.server.database.model.PowerAuthSignatureMetadata; import io.getlime.security.powerauth.app.server.database.model.converter.ActivationStatusConverter; import io.getlime.security.powerauth.app.server.database.model.converter.SignatureMetadataConverter; import io.getlime.security.powerauth.app.server.database.model.enumeration.ActivationStatus; @@ -77,7 +77,7 @@ public class SignatureEntity implements Serializable { @Column(name = "signature_metadata") @Convert(converter = SignatureMetadataConverter.class) - private SignatureMetadata signatureMetadata; + private PowerAuthSignatureMetadata signatureMetadata; @Column(name = "signature_data_body", updatable = false) private String signatureDataBody; @@ -130,7 +130,7 @@ public SignatureEntity( String signatureVersion, String signatureType, String signature, - SignatureMetadata signatureMetadata, + PowerAuthSignatureMetadata signatureMetadata, String signatureDataBody, String additionalInfo, String note, @@ -339,7 +339,7 @@ public void setSignature(String signature) { * * @return Signature metadata. */ - public SignatureMetadata getSignatureMetadata() { + public PowerAuthSignatureMetadata getSignatureMetadata() { return signatureMetadata; } @@ -348,7 +348,7 @@ public SignatureMetadata getSignatureMetadata() { * * @param signatureMetadata Metadata related to the signature. */ - public void setSignatureMetadata(SignatureMetadata signatureMetadata) { + public void setSignatureMetadata(PowerAuthSignatureMetadata signatureMetadata) { this.signatureMetadata = signatureMetadata; } diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/AuditingServiceBehavior.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/AuditingServiceBehavior.java index 173dc88eb..32de72a10 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/AuditingServiceBehavior.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/AuditingServiceBehavior.java @@ -26,7 +26,7 @@ import io.getlime.security.powerauth.app.server.converter.ActivationStatusConverter; import io.getlime.security.powerauth.app.server.converter.KeyValueMapConverter; import io.getlime.security.powerauth.app.server.converter.SignatureTypeConverter; -import io.getlime.security.powerauth.app.server.database.model.SignatureMetadata; +import io.getlime.security.powerauth.app.server.database.model.PowerAuthSignatureMetadata; import io.getlime.security.powerauth.app.server.database.model.entity.ActivationRecordEntity; import io.getlime.security.powerauth.app.server.database.model.entity.SignatureEntity; import io.getlime.security.powerauth.app.server.database.model.enumeration.ActivationStatus; @@ -158,7 +158,7 @@ public void logSignatureAuditRecord(ActivationRecordDto activation, SignatureDat // Audit the signature final SignatureEntity signatureAuditRecord = new SignatureEntity(); - final SignatureMetadata signatureMetadata = new SignatureMetadata(signatureData.getRequestMethod(), signatureData.getRequestUriId()); + final PowerAuthSignatureMetadata signatureMetadata = new PowerAuthSignatureMetadata(signatureData.getRequestMethod(), signatureData.getRequestUriId()); signatureAuditRecord.setActivation(activationRepository.getReferenceById(activation.getActivationId())); signatureAuditRecord.setActivationCounter(activation.getCounter()); signatureAuditRecord.setActivationCtrDataBase64(activation.getCtrDataBase64()); From a9a480f70a6a60443dcf5ebb2ff95917d4907551 Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Thu, 31 Aug 2023 00:26:00 +0200 Subject: [PATCH 06/14] Fix #971: Add column for signature metadata - Add a test - Introduce more generic approach --- .../model/PowerAuthSignatureMetadata.java | 50 +++++++++- .../database/model/SignatureMetadata.java | 61 +++++++++++- .../converter/SignatureMetadataConverter.java | 29 ++++-- .../enumeration/SignatureMetadataType.java | 39 ++++++++ .../SignatureMetadataConverterTest.java | 99 +++++++++++++++++++ 5 files changed, 269 insertions(+), 9 deletions(-) create mode 100644 powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/enumeration/SignatureMetadataType.java create mode 100644 powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java index 717bb2309..72f26c49c 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java @@ -1,32 +1,78 @@ +/* + * PowerAuth Server and related software components + * Copyright (C) 2023 Wultra s.r.o. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package io.getlime.security.powerauth.app.server.database.model; import lombok.AllArgsConstructor; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.NoArgsConstructor; + +/** + * Concrete implementation of the SignatureMetadata interface for PowerAuth. + * Contains metadata parameters specific to PowerAuth Signature. + * + * @author Jan Dusil + */ @AllArgsConstructor @NoArgsConstructor public class PowerAuthSignatureMetadata implements SignatureMetadata { + @JsonProperty("signatureDataMethod") private String signatureDataMethod; - + @JsonProperty("signatureDataUriId") private String signatureDataUriId; - + /** + * Retrieves the signature method. + * + * @return The signature method. + */ @Override public String getMetadataParam1() { return signatureDataMethod; } + /** + * Sets the value for the signature method. + * + * @param metadataParam1 The value to set. + */ @Override public void setMetadataParam1(String metadataParam1) { this.signatureDataMethod = metadataParam1; } + /** + * Retrieves the URI ID related to the signature. + * + * @return The URI ID. + */ @Override public String getMetadataParam2() { return signatureDataUriId; } + /** + * Sets the value for the URI ID related to the signature. + * + * @param metadataParam2 The value to set. + */ @Override public void setMetadataParam2(String metadataParam2) { this.signatureDataUriId = metadataParam2; diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java index c01e64f01..1f7e37fe3 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java @@ -1,14 +1,73 @@ +/* + * PowerAuth Server and related software components + * Copyright (C) 2023 Wultra s.r.o. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package io.getlime.security.powerauth.app.server.database.model; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import io.getlime.security.powerauth.app.server.database.model.enumeration.SignatureMetadataType; +/** + * Represents a generic interface for metadata related to different types of signatures. + * The interface allows for defining various metadata attributes as type parameters T1 and T2. + * + * @param The type of the first metadata parameter. + * @param The type of the second metadata parameter. + * @author Jan Dusil + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +@JsonSubTypes({ + @JsonSubTypes.Type(value = PowerAuthSignatureMetadata.class, + name = SignatureMetadataType.POWER_AUTH) +}) public interface SignatureMetadata { + /** + * Retrieves the first metadata parameter. + * + * @return The first metadata parameter. + */ + @JsonIgnore T1 getMetadataParam1(); + /** + * Sets the value for the first metadata parameter. + * + * @param metadataParam1 The value to set. + */ + @JsonIgnore void setMetadataParam1(T1 metadataParam1); + /** + * Retrieves the second metadata parameter. + * + * @return The second metadata parameter. + */ + @JsonIgnore T2 getMetadataParam2(); + /** + * Sets the value for the second metadata parameter. + * + * @param metadataParam2 The value to set. + */ + @JsonIgnore void setMetadataParam2(T2 metadataParam2); - } + diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java index 7fc5ad126..e47b793c3 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java @@ -30,26 +30,37 @@ import org.springframework.stereotype.Component; /** - * Converts between SignatureMetadata object and JSON serialized - * storage in database column. + * A JPA attribute converter for converting SignatureMetadata objects to and from JSON representations. + * This class enables storing SignatureMetadata in the database as a JSON column. * * @author Jan Dusil */ @Converter @Component -public class SignatureMetadataConverter> implements AttributeConverter { +public class SignatureMetadataConverter implements AttributeConverter, String> { private static final Logger logger = LoggerFactory.getLogger(SignatureMetadataConverter.class); private final ObjectMapper objectMapper; + /** + * Constructor that initializes the ObjectMapper. + * + * @param objectMapper The Jackson ObjectMapper. + */ @Autowired public SignatureMetadataConverter(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } + /** + * Converts a SignatureMetadata object to its JSON string representation. + * + * @param attribute The SignatureMetadata object to convert. + * @return The JSON string representation of the object. + */ @Override - public String convertToDatabaseColumn(T attribute) { + public String convertToDatabaseColumn(SignatureMetadata attribute) { if (attribute == null) { return "{}"; } @@ -61,8 +72,14 @@ public String convertToDatabaseColumn(T attribute) { } } + /** + * Converts a JSON string representation to a SignatureMetadata object. + * + * @param s The JSON string to convert. + * @return The converted SignatureMetadata object. + */ @Override - public T convertToEntityAttribute(String s) { + public SignatureMetadata convertToEntityAttribute(String s) { if (s == null || s.isEmpty()) { return null; } @@ -74,4 +91,4 @@ public T convertToEntityAttribute(String s) { return null; } } -} +} \ No newline at end of file diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/enumeration/SignatureMetadataType.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/enumeration/SignatureMetadataType.java new file mode 100644 index 000000000..54e53458f --- /dev/null +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/enumeration/SignatureMetadataType.java @@ -0,0 +1,39 @@ +/* + * PowerAuth Server and related software components + * Copyright (C) 2023 Wultra s.r.o. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package io.getlime.security.powerauth.app.server.database.model.enumeration; + +/** + * Enumeration constants representing the types of signature metadata supported in the application. + * These constants are used as names in JSON subtypes and therefore must be kept in sync. + *

+ * Note: Although it is represented as a class with static final String fields, it serves + * the purpose of an enum type for specific use cases that require constant String values. + *

+ * + * @author Jan Dusil + */ +public class SignatureMetadataType { + + /** + * Represents PowerAuth signature metadata. + * This value is used for identifying the type of metadata in JSON serialization/deserialization. + */ + public static final String POWER_AUTH = "PowerAuthSignatureMetadata"; +} + diff --git a/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java new file mode 100644 index 000000000..10fb1f211 --- /dev/null +++ b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java @@ -0,0 +1,99 @@ +/* + * PowerAuth Server and related software components + * Copyright (C) 2023 Wultra s.r.o. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package io.getlime.security.powerauth.app.server.service.model.signature; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.getlime.security.powerauth.app.server.database.model.PowerAuthSignatureMetadata; +import io.getlime.security.powerauth.app.server.database.model.SignatureMetadata; +import io.getlime.security.powerauth.app.server.database.model.converter.SignatureMetadataConverter; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * Test class for SignatureMetadataConverter. + * This class tests various aspects of converting SignatureMetadata to and from its serialized JSON form. + * + * @author Your Name + */ +public class SignatureMetadataConverterTest { + + /** + * Converter object to be used for tests. + */ + private SignatureMetadataConverter converter; + + /** + * Initializes the SignatureMetadataConverter object and any other necessary objects. + */ + @BeforeEach + public void setUp() { + ObjectMapper objectMapper = new ObjectMapper(); + converter = new SignatureMetadataConverter(objectMapper); + } + + /** + * Tests the conversion of a PowerAuthSignatureMetadata object to its serialized JSON form. + */ + @Test + public void convertToDatabaseColumnTest() { + PowerAuthSignatureMetadata metadata = new PowerAuthSignatureMetadata("POST", "123"); + String jsonStr = converter.convertToDatabaseColumn(metadata); + + assertNotNull(jsonStr); + assertEquals("{\"type\":\"PowerAuthSignatureMetadata\",\"signatureDataMethod\":\"POST\",\"signatureDataUriId\":\"123\"}", jsonStr); + } + + /** + * Tests the conversion of a serialized JSON string back to a SignatureMetadata object. + */ + @Test + public void convertToEntityAttributeTest() { + String jsonStr = "{\"type\":\"PowerAuthSignatureMetadata\",\"signatureDataMethod\":\"POST\",\"signatureDataUriId\":\"123\"}"; + SignatureMetadata metadata = converter.convertToEntityAttribute(jsonStr); + + assertNotNull(metadata); + assertEquals("POST", metadata.getMetadataParam1()); + assertEquals("123", metadata.getMetadataParam2()); + } + + /** + * Tests a round-trip conversion, from object to JSON string and back to object, to ensure consistency. + */ + @Test + public void testRoundTripConversion() { + PowerAuthSignatureMetadata originalMetadata = new PowerAuthSignatureMetadata("POST", "123"); + String jsonStr = converter.convertToDatabaseColumn(originalMetadata); + PowerAuthSignatureMetadata convertedMetadata = (PowerAuthSignatureMetadata) converter.convertToEntityAttribute(jsonStr); + + assertNotNull(convertedMetadata); + assertEquals(originalMetadata.getMetadataParam1(), convertedMetadata.getMetadataParam1()); + assertEquals(originalMetadata.getMetadataParam2(), convertedMetadata.getMetadataParam2()); + } + + /** + * Tests the converter's behavior when provided with an invalid JSON string. + */ + @Test + public void testInvalidJsonInput() { + String invalidJson = "{\"invalidField\":\"someValue\"}"; + SignatureMetadata metadata = converter.convertToEntityAttribute(invalidJson); + assertNull(metadata); + } +} From 417d148142555d20dcf6c88e28317f7c4a2b406e Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Thu, 31 Aug 2023 00:31:36 +0200 Subject: [PATCH 07/14] Fix #971: Add column for signature metadata - Add a test - Introduce more generic approach --- .../service/model/signature/SignatureMetadataConverterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java index 10fb1f211..4597a410d 100644 --- a/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java +++ b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java @@ -30,7 +30,7 @@ * Test class for SignatureMetadataConverter. * This class tests various aspects of converting SignatureMetadata to and from its serialized JSON form. * - * @author Your Name + * @author Jan Dusil */ public class SignatureMetadataConverterTest { From afd9adc994753ced93a0d439f5862825e9b4a7ad Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Tue, 5 Sep 2023 11:26:47 +0200 Subject: [PATCH 08/14] Fix #971: Add column for signature metadata - Change type of signature_metadata to clob - Incorporate code review comments --- .../20230323-add-column-signature-metadata.xml | 4 ++-- .../model/PowerAuthSignatureMetadata.java | 2 +- .../converter/SignatureMetadataConverter.java | 3 ++- .../SignatureMetadataConverterTest.java | 18 ++++++++++-------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230323-add-column-signature-metadata.xml b/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230323-add-column-signature-metadata.xml index 37c630a44..421ee377d 100644 --- a/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230323-add-column-signature-metadata.xml +++ b/docs/db/changelog/changesets/powerauth-java-server/1.5.x/20230323-add-column-signature-metadata.xml @@ -9,9 +9,9 @@ - Add signature_metadata column of type JSONB + Add signature_metadata column of type Clob - + diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java index 72f26c49c..2f3a72300 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java @@ -24,7 +24,7 @@ /** - * Concrete implementation of the SignatureMetadata interface for PowerAuth. + * Concrete implementation of the {@link SignatureMetadata} interface for PowerAuth. * Contains metadata parameters specific to PowerAuth Signature. * * @author Jan Dusil diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java index e47b793c3..04af78f25 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java @@ -24,6 +24,7 @@ import io.getlime.security.powerauth.app.server.database.model.SignatureMetadata; import jakarta.persistence.AttributeConverter; import jakarta.persistence.Converter; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -80,7 +81,7 @@ public String convertToDatabaseColumn(SignatureMetadata attribute) { */ @Override public SignatureMetadata convertToEntityAttribute(String s) { - if (s == null || s.isEmpty()) { + if (StringUtils.isBlank(s)) { return null; } try { diff --git a/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java index 4597a410d..a63438665 100644 --- a/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java +++ b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java @@ -24,7 +24,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; /** * Test class for SignatureMetadataConverter. @@ -43,7 +45,7 @@ public class SignatureMetadataConverterTest { * Initializes the SignatureMetadataConverter object and any other necessary objects. */ @BeforeEach - public void setUp() { + void setUp() { ObjectMapper objectMapper = new ObjectMapper(); converter = new SignatureMetadataConverter(objectMapper); } @@ -52,7 +54,7 @@ public void setUp() { * Tests the conversion of a PowerAuthSignatureMetadata object to its serialized JSON form. */ @Test - public void convertToDatabaseColumnTest() { + void convertToDatabaseColumnTest() { PowerAuthSignatureMetadata metadata = new PowerAuthSignatureMetadata("POST", "123"); String jsonStr = converter.convertToDatabaseColumn(metadata); @@ -64,9 +66,9 @@ public void convertToDatabaseColumnTest() { * Tests the conversion of a serialized JSON string back to a SignatureMetadata object. */ @Test - public void convertToEntityAttributeTest() { + void convertToEntityAttributeTest() { String jsonStr = "{\"type\":\"PowerAuthSignatureMetadata\",\"signatureDataMethod\":\"POST\",\"signatureDataUriId\":\"123\"}"; - SignatureMetadata metadata = converter.convertToEntityAttribute(jsonStr); + SignatureMetadata metadata = (PowerAuthSignatureMetadata) converter.convertToEntityAttribute(jsonStr); assertNotNull(metadata); assertEquals("POST", metadata.getMetadataParam1()); @@ -77,7 +79,7 @@ public void convertToEntityAttributeTest() { * Tests a round-trip conversion, from object to JSON string and back to object, to ensure consistency. */ @Test - public void testRoundTripConversion() { + void testRoundTripConversion() { PowerAuthSignatureMetadata originalMetadata = new PowerAuthSignatureMetadata("POST", "123"); String jsonStr = converter.convertToDatabaseColumn(originalMetadata); PowerAuthSignatureMetadata convertedMetadata = (PowerAuthSignatureMetadata) converter.convertToEntityAttribute(jsonStr); @@ -91,9 +93,9 @@ public void testRoundTripConversion() { * Tests the converter's behavior when provided with an invalid JSON string. */ @Test - public void testInvalidJsonInput() { + void testInvalidJsonInput() { String invalidJson = "{\"invalidField\":\"someValue\"}"; - SignatureMetadata metadata = converter.convertToEntityAttribute(invalidJson); + SignatureMetadata metadata = (PowerAuthSignatureMetadata) converter.convertToEntityAttribute(invalidJson); assertNull(metadata); } } From 6f89a1b6cec3400135d4298f12eef22a6f01469a Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Tue, 5 Sep 2023 11:43:42 +0200 Subject: [PATCH 09/14] Fix #971: Add column for signature metadata - Incorporate code review comments --- .../model/PowerAuthSignatureMetadata.java | 49 ++++++------------- .../database/model/SignatureMetadata.java | 36 ++------------ .../converter/SignatureMetadataConverter.java | 6 +-- .../SignatureMetadataConverterTest.java | 10 ++-- 4 files changed, 24 insertions(+), 77 deletions(-) diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java index 2f3a72300..7b05c5111 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java @@ -20,8 +20,12 @@ import lombok.AllArgsConstructor; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; import lombok.NoArgsConstructor; +import java.io.Serializable; +import java.util.Objects; + /** * Concrete implementation of the {@link SignatureMetadata} interface for PowerAuth. @@ -31,50 +35,25 @@ */ @AllArgsConstructor @NoArgsConstructor -public class PowerAuthSignatureMetadata implements SignatureMetadata { +@Data +public class PowerAuthSignatureMetadata implements SignatureMetadata, Serializable { @JsonProperty("signatureDataMethod") private String signatureDataMethod; @JsonProperty("signatureDataUriId") private String signatureDataUriId; - /** - * Retrieves the signature method. - * - * @return The signature method. - */ - @Override - public String getMetadataParam1() { - return signatureDataMethod; - } - - /** - * Sets the value for the signature method. - * - * @param metadataParam1 The value to set. - */ - @Override - public void setMetadataParam1(String metadataParam1) { - this.signatureDataMethod = metadataParam1; - } - - /** - * Retrieves the URI ID related to the signature. - * - * @return The URI ID. - */ @Override - public String getMetadataParam2() { - return signatureDataUriId; + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PowerAuthSignatureMetadata that = (PowerAuthSignatureMetadata) o; + return Objects.equals(signatureDataMethod, that.signatureDataMethod) && + Objects.equals(signatureDataUriId, that.signatureDataUriId); } - /** - * Sets the value for the URI ID related to the signature. - * - * @param metadataParam2 The value to set. - */ @Override - public void setMetadataParam2(String metadataParam2) { - this.signatureDataUriId = metadataParam2; + public int hashCode() { + return Objects.hash(signatureDataMethod, signatureDataUriId); } } diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java index 1f7e37fe3..07692dd30 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java @@ -18,11 +18,12 @@ package io.getlime.security.powerauth.app.server.database.model; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import io.getlime.security.powerauth.app.server.database.model.enumeration.SignatureMetadataType; +import java.io.Serializable; + /** * Represents a generic interface for metadata related to different types of signatures. * The interface allows for defining various metadata attributes as type parameters T1 and T2. @@ -36,38 +37,7 @@ @JsonSubTypes.Type(value = PowerAuthSignatureMetadata.class, name = SignatureMetadataType.POWER_AUTH) }) -public interface SignatureMetadata { - - /** - * Retrieves the first metadata parameter. - * - * @return The first metadata parameter. - */ - @JsonIgnore - T1 getMetadataParam1(); - - /** - * Sets the value for the first metadata parameter. - * - * @param metadataParam1 The value to set. - */ - @JsonIgnore - void setMetadataParam1(T1 metadataParam1); - - /** - * Retrieves the second metadata parameter. - * - * @return The second metadata parameter. - */ - @JsonIgnore - T2 getMetadataParam2(); +public interface SignatureMetadata extends Serializable { - /** - * Sets the value for the second metadata parameter. - * - * @param metadataParam2 The value to set. - */ - @JsonIgnore - void setMetadataParam2(T2 metadataParam2); } diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java index 04af78f25..b685c3ed6 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java @@ -24,9 +24,8 @@ import io.getlime.security.powerauth.app.server.database.model.SignatureMetadata; import jakarta.persistence.AttributeConverter; import jakarta.persistence.Converter; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -38,10 +37,9 @@ */ @Converter @Component +@Slf4j public class SignatureMetadataConverter implements AttributeConverter, String> { - private static final Logger logger = LoggerFactory.getLogger(SignatureMetadataConverter.class); - private final ObjectMapper objectMapper; /** diff --git a/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java index a63438665..476d8a506 100644 --- a/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java +++ b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java @@ -68,11 +68,11 @@ void convertToDatabaseColumnTest() { @Test void convertToEntityAttributeTest() { String jsonStr = "{\"type\":\"PowerAuthSignatureMetadata\",\"signatureDataMethod\":\"POST\",\"signatureDataUriId\":\"123\"}"; - SignatureMetadata metadata = (PowerAuthSignatureMetadata) converter.convertToEntityAttribute(jsonStr); + PowerAuthSignatureMetadata metadata = (PowerAuthSignatureMetadata) converter.convertToEntityAttribute(jsonStr); assertNotNull(metadata); - assertEquals("POST", metadata.getMetadataParam1()); - assertEquals("123", metadata.getMetadataParam2()); + assertEquals("POST", metadata.getSignatureDataMethod()); + assertEquals("123", metadata.getSignatureDataUriId()); } /** @@ -85,8 +85,8 @@ void testRoundTripConversion() { PowerAuthSignatureMetadata convertedMetadata = (PowerAuthSignatureMetadata) converter.convertToEntityAttribute(jsonStr); assertNotNull(convertedMetadata); - assertEquals(originalMetadata.getMetadataParam1(), convertedMetadata.getMetadataParam1()); - assertEquals(originalMetadata.getMetadataParam2(), convertedMetadata.getMetadataParam2()); + assertEquals(originalMetadata.getSignatureDataMethod(), convertedMetadata.getSignatureDataMethod()); + assertEquals(originalMetadata.getSignatureDataUriId(), convertedMetadata.getSignatureDataUriId()); } /** From e2cca7a7a6c1285a5fdaa8cad1670b6440f7a62c Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Tue, 5 Sep 2023 16:53:38 +0200 Subject: [PATCH 10/14] Fix #971: Add column for signature metadata - Incorporate code review comments --- .../powerauth/app/server/database/model/SignatureMetadata.java | 2 +- .../database/model/enumeration/SignatureMetadataType.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java index 07692dd30..addafbca6 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java @@ -35,7 +35,7 @@ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") @JsonSubTypes({ @JsonSubTypes.Type(value = PowerAuthSignatureMetadata.class, - name = SignatureMetadataType.POWER_AUTH) + name = SignatureMetadataType.POWERAUTH) }) public interface SignatureMetadata extends Serializable { diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/enumeration/SignatureMetadataType.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/enumeration/SignatureMetadataType.java index 54e53458f..e8f7f7eff 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/enumeration/SignatureMetadataType.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/enumeration/SignatureMetadataType.java @@ -34,6 +34,6 @@ public class SignatureMetadataType { * Represents PowerAuth signature metadata. * This value is used for identifying the type of metadata in JSON serialization/deserialization. */ - public static final String POWER_AUTH = "PowerAuthSignatureMetadata"; + public static final String POWERAUTH = "PowerAuthSignatureMetadata"; } From 2406b59d699b4cc2c06140a21a0c98f7aae82d6e Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Wed, 6 Sep 2023 12:25:52 +0200 Subject: [PATCH 11/14] Fix #971: Add column for signature metadata - Incorporate code review comments --- .../database/model/PowerAuthSignatureMetadata.java | 2 +- .../server/database/model/SignatureMetadata.java | 12 +++++++----- .../model/converter/SignatureMetadataConverter.java | 13 ++++++++++--- .../model/enumeration/SignatureMetadataType.java | 2 +- .../behavior/tasks/AuditingServiceBehavior.java | 6 ++++-- .../signature/SignatureMetadataConverterTest.java | 9 ++++----- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java index 7b05c5111..a15e4218c 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java @@ -36,7 +36,7 @@ @AllArgsConstructor @NoArgsConstructor @Data -public class PowerAuthSignatureMetadata implements SignatureMetadata, Serializable { +public class PowerAuthSignatureMetadata implements SignatureMetadata, Serializable { @JsonProperty("signatureDataMethod") private String signatureDataMethod; diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java index addafbca6..30df2abcd 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java @@ -25,11 +25,12 @@ import java.io.Serializable; /** - * Represents a generic interface for metadata related to different types of signatures. - * The interface allows for defining various metadata attributes as type parameters T1 and T2. + * Represents an interface for metadata related to different types of signatures. + * The interface is designed to work specifically with metadata attributes of type + * String for the first parameter and Object for the second parameter. This allows + * the flexibility to capture various metadata details according to the specific + * requirements of different signature algorithms or methods. * - * @param The type of the first metadata parameter. - * @param The type of the second metadata parameter. * @author Jan Dusil */ @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") @@ -37,7 +38,8 @@ @JsonSubTypes.Type(value = PowerAuthSignatureMetadata.class, name = SignatureMetadataType.POWERAUTH) }) -public interface SignatureMetadata extends Serializable { +public interface SignatureMetadata extends Serializable { } + diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java index b685c3ed6..afa31d6a8 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java @@ -38,10 +38,17 @@ @Converter @Component @Slf4j -public class SignatureMetadataConverter implements AttributeConverter, String> { +public class SignatureMetadataConverter implements AttributeConverter, String> { private final ObjectMapper objectMapper; + /** + * Default constructor that initializes a default ObjectMapper. + */ + public SignatureMetadataConverter() { + this.objectMapper = new ObjectMapper(); + } + /** * Constructor that initializes the ObjectMapper. * @@ -59,7 +66,7 @@ public SignatureMetadataConverter(ObjectMapper objectMapper) { * @return The JSON string representation of the object. */ @Override - public String convertToDatabaseColumn(SignatureMetadata attribute) { + public String convertToDatabaseColumn(SignatureMetadata attribute) { if (attribute == null) { return "{}"; } @@ -78,7 +85,7 @@ public String convertToDatabaseColumn(SignatureMetadata attribute) { * @return The converted SignatureMetadata object. */ @Override - public SignatureMetadata convertToEntityAttribute(String s) { + public SignatureMetadata convertToEntityAttribute(String s) { if (StringUtils.isBlank(s)) { return null; } diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/enumeration/SignatureMetadataType.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/enumeration/SignatureMetadataType.java index e8f7f7eff..220ff5f37 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/enumeration/SignatureMetadataType.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/enumeration/SignatureMetadataType.java @@ -34,6 +34,6 @@ public class SignatureMetadataType { * Represents PowerAuth signature metadata. * This value is used for identifying the type of metadata in JSON serialization/deserialization. */ - public static final String POWERAUTH = "PowerAuthSignatureMetadata"; + public static final String POWERAUTH = "POWERAUTH"; } diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/AuditingServiceBehavior.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/AuditingServiceBehavior.java index 32de72a10..515f493bc 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/AuditingServiceBehavior.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/behavior/tasks/AuditingServiceBehavior.java @@ -27,6 +27,7 @@ import io.getlime.security.powerauth.app.server.converter.KeyValueMapConverter; import io.getlime.security.powerauth.app.server.converter.SignatureTypeConverter; import io.getlime.security.powerauth.app.server.database.model.PowerAuthSignatureMetadata; +import io.getlime.security.powerauth.app.server.database.model.converter.SignatureMetadataConverter; import io.getlime.security.powerauth.app.server.database.model.entity.ActivationRecordEntity; import io.getlime.security.powerauth.app.server.database.model.entity.SignatureEntity; import io.getlime.security.powerauth.app.server.database.model.enumeration.ActivationStatus; @@ -58,6 +59,8 @@ public class AuditingServiceBehavior { // Prepare converters private final ActivationStatusConverter activationStatusConverter = new ActivationStatusConverter(); private final SignatureTypeConverter signatureTypeConverter = new SignatureTypeConverter(); + + private final SignatureMetadataConverter signatureMetadataConverter = new SignatureMetadataConverter(); private final KeyValueMapConverter keyValueMapConverter; // Generic auditing capability @@ -188,8 +191,7 @@ public void logSignatureAuditRecord(ActivationRecordDto activation, SignatureDat .param("additionalInfo", additionalInfo) .param("data", data) .param("signature", signatureData.getSignature()) - .param("signatureDataMethod", signatureData.getRequestMethod()) - .param("signatureDataUriId", signatureData.getRequestUriId()) + .param("signatureMetadata", signatureMetadataConverter.convertToDatabaseColumn(signatureMetadata)) .param("signatureDataBody", signatureData.getRequestBody()) .param("signatureType", signatureType.name()) .param("signatureVersion", signatureData.getSignatureVersion()) diff --git a/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java index 476d8a506..4db5e0f90 100644 --- a/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java +++ b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java @@ -46,8 +46,7 @@ public class SignatureMetadataConverterTest { */ @BeforeEach void setUp() { - ObjectMapper objectMapper = new ObjectMapper(); - converter = new SignatureMetadataConverter(objectMapper); + converter = new SignatureMetadataConverter(); } /** @@ -59,7 +58,7 @@ void convertToDatabaseColumnTest() { String jsonStr = converter.convertToDatabaseColumn(metadata); assertNotNull(jsonStr); - assertEquals("{\"type\":\"PowerAuthSignatureMetadata\",\"signatureDataMethod\":\"POST\",\"signatureDataUriId\":\"123\"}", jsonStr); + assertEquals("{\"type\":\"POWERAUTH\",\"signatureDataMethod\":\"POST\",\"signatureDataUriId\":\"123\"}", jsonStr); } /** @@ -67,7 +66,7 @@ void convertToDatabaseColumnTest() { */ @Test void convertToEntityAttributeTest() { - String jsonStr = "{\"type\":\"PowerAuthSignatureMetadata\",\"signatureDataMethod\":\"POST\",\"signatureDataUriId\":\"123\"}"; + String jsonStr = "{\"type\":\"POWERAUTH\",\"signatureDataMethod\":\"POST\",\"signatureDataUriId\":\"123\"}"; PowerAuthSignatureMetadata metadata = (PowerAuthSignatureMetadata) converter.convertToEntityAttribute(jsonStr); assertNotNull(metadata); @@ -95,7 +94,7 @@ void testRoundTripConversion() { @Test void testInvalidJsonInput() { String invalidJson = "{\"invalidField\":\"someValue\"}"; - SignatureMetadata metadata = (PowerAuthSignatureMetadata) converter.convertToEntityAttribute(invalidJson); + SignatureMetadata metadata = (PowerAuthSignatureMetadata) converter.convertToEntityAttribute(invalidJson); assertNull(metadata); } } From 41941acdb621bb738347de6b3277f8b1b02b7f9c Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Wed, 6 Sep 2023 13:14:48 +0200 Subject: [PATCH 12/14] Fix #971: Add column for signature metadata - Remove generics --- .../server/database/model/PowerAuthSignatureMetadata.java | 2 +- .../app/server/database/model/SignatureMetadata.java | 2 +- .../model/converter/SignatureMetadataConverter.java | 6 +++--- .../model/signature/SignatureMetadataConverterTest.java | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java index a15e4218c..ae7eb31ea 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java @@ -36,7 +36,7 @@ @AllArgsConstructor @NoArgsConstructor @Data -public class PowerAuthSignatureMetadata implements SignatureMetadata, Serializable { +public class PowerAuthSignatureMetadata implements SignatureMetadata, Serializable { @JsonProperty("signatureDataMethod") private String signatureDataMethod; diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java index 30df2abcd..4d40a4001 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/SignatureMetadata.java @@ -38,7 +38,7 @@ @JsonSubTypes.Type(value = PowerAuthSignatureMetadata.class, name = SignatureMetadataType.POWERAUTH) }) -public interface SignatureMetadata extends Serializable { +public interface SignatureMetadata extends Serializable { } diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java index afa31d6a8..817b927ca 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/converter/SignatureMetadataConverter.java @@ -38,7 +38,7 @@ @Converter @Component @Slf4j -public class SignatureMetadataConverter implements AttributeConverter, String> { +public class SignatureMetadataConverter implements AttributeConverter { private final ObjectMapper objectMapper; @@ -66,7 +66,7 @@ public SignatureMetadataConverter(ObjectMapper objectMapper) { * @return The JSON string representation of the object. */ @Override - public String convertToDatabaseColumn(SignatureMetadata attribute) { + public String convertToDatabaseColumn(SignatureMetadata attribute) { if (attribute == null) { return "{}"; } @@ -85,7 +85,7 @@ public String convertToDatabaseColumn(SignatureMetadata attribut * @return The converted SignatureMetadata object. */ @Override - public SignatureMetadata convertToEntityAttribute(String s) { + public SignatureMetadata convertToEntityAttribute(String s) { if (StringUtils.isBlank(s)) { return null; } diff --git a/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java index 4db5e0f90..0b72eec44 100644 --- a/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java +++ b/powerauth-java-server/src/test/java/io/getlime/security/powerauth/app/server/service/model/signature/SignatureMetadataConverterTest.java @@ -17,7 +17,6 @@ */ package io.getlime.security.powerauth.app.server.service.model.signature; -import com.fasterxml.jackson.databind.ObjectMapper; import io.getlime.security.powerauth.app.server.database.model.PowerAuthSignatureMetadata; import io.getlime.security.powerauth.app.server.database.model.SignatureMetadata; import io.getlime.security.powerauth.app.server.database.model.converter.SignatureMetadataConverter; @@ -94,7 +93,7 @@ void testRoundTripConversion() { @Test void testInvalidJsonInput() { String invalidJson = "{\"invalidField\":\"someValue\"}"; - SignatureMetadata metadata = (PowerAuthSignatureMetadata) converter.convertToEntityAttribute(invalidJson); + SignatureMetadata metadata = converter.convertToEntityAttribute(invalidJson); assertNull(metadata); } } From 77979c99213bae9b566d6c787753485ae9acd3a9 Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Wed, 6 Sep 2023 13:16:08 +0200 Subject: [PATCH 13/14] Fix #971: Add column for signature metadata - Remove redundant extension --- .../app/server/database/model/PowerAuthSignatureMetadata.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java index ae7eb31ea..ffae1d8c1 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java @@ -23,7 +23,6 @@ import lombok.Data; import lombok.NoArgsConstructor; -import java.io.Serializable; import java.util.Objects; @@ -36,7 +35,7 @@ @AllArgsConstructor @NoArgsConstructor @Data -public class PowerAuthSignatureMetadata implements SignatureMetadata, Serializable { +public class PowerAuthSignatureMetadata implements SignatureMetadata { @JsonProperty("signatureDataMethod") private String signatureDataMethod; From 8775a9d21538498a80ffa1e40e32d409618d119f Mon Sep 17 00:00:00 2001 From: Jan Dusil Date: Wed, 6 Sep 2023 13:52:06 +0200 Subject: [PATCH 14/14] Fix #971: Add column for signature metadata - Add serialVersionUID --- .../app/server/database/model/PowerAuthSignatureMetadata.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java index ffae1d8c1..37d606503 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/database/model/PowerAuthSignatureMetadata.java @@ -23,6 +23,7 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.io.Serial; import java.util.Objects; @@ -37,6 +38,9 @@ @Data public class PowerAuthSignatureMetadata implements SignatureMetadata { + @Serial + private static final long serialVersionUID = -5167321997819747483L; + @JsonProperty("signatureDataMethod") private String signatureDataMethod; @JsonProperty("signatureDataUriId")