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); } }