diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/converter/CallbackAuthenticationConverter.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/converter/CallbackAuthenticationConverter.java index ac888aab9..59078a20e 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/converter/CallbackAuthenticationConverter.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/converter/CallbackAuthenticationConverter.java @@ -26,6 +26,7 @@ import org.springframework.stereotype.Component; import java.io.IOException; +import java.util.Objects; /** * Converter for callback request authentication. @@ -48,17 +49,13 @@ public CallbackAuthenticationConverter(ObjectMapper objectMapper) { } @Override - public String convertToDatabaseColumn(CallbackUrlAuthentication authentication) { + public String convertToDatabaseColumn(final CallbackUrlAuthentication authentication) { try { - if (authentication == null) { - authentication = new CallbackUrlAuthentication(); - } - return objectMapper.writeValueAsString(authentication); + return objectMapper.writeValueAsString(Objects.requireNonNullElse(authentication, new CallbackUrlAuthentication())); } catch (JsonProcessingException ex) { logger.error("Unable to serialize JSON payload", ex); return null; } - } @Override diff --git a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/encryption/EncryptionService.java b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/encryption/EncryptionService.java index 0da9b5ccb..91dd8771d 100644 --- a/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/encryption/EncryptionService.java +++ b/powerauth-java-server/src/main/java/io/getlime/security/powerauth/app/server/service/encryption/EncryptionService.java @@ -151,6 +151,10 @@ public byte[] decrypt(final byte[] data, final EncryptionMode encryptionMode, fi * @throws GenericServiceException Thrown when encryption fails. */ public EncryptableString encrypt(final String data, final Supplier> encryptionKeyProvider) throws GenericServiceException { + if (data == null) { + throw new GenericServiceException(ServiceError.ENCRYPTION_FAILED, "Data must not be null"); + } + final byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8); final EncryptableData result = encrypt(dataBytes, encryptionKeyProvider); return new EncryptableString(result.encryptionMode(), convert(result)); @@ -166,6 +170,10 @@ public EncryptableString encrypt(final String data, final Supplier> * @throws GenericServiceException Thrown when encryption fails. */ public EncryptableData encrypt(final byte[] data, final Supplier> encryptionKeyProvider) throws GenericServiceException { + if (data == null) { + throw new GenericServiceException(ServiceError.ENCRYPTION_FAILED, "Data must not be null"); + } + final String masterDbEncryptionKeyBase64 = powerAuthServiceConfiguration.getMasterDbEncryptionKey(); // In case master DB encryption key does not exist, do not encrypt the value