Skip to content

Commit

Permalink
Merge pull request #111 from wultra/issues/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream
  • Loading branch information
banterCZ authored May 18, 2023
2 parents 6f374cc + 9ef2e8b commit 3a70e54
Show file tree
Hide file tree
Showing 6 changed files with 591 additions and 26 deletions.
6 changes: 6 additions & 0 deletions enrollment-server-onboarding/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>

<!-- Documentation -->
<dependency>
<groupId>org.springdoc</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
*/
package com.wultra.app.onboardingserver.docverify.zenid.config;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.wultra.app.onboardingserver.docverify.zenid.model.deserializer.CustomOffsetDateTimeDeserializer;
import com.wultra.core.rest.client.base.DefaultRestClient;
Expand All @@ -32,9 +30,9 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;

import java.time.OffsetDateTime;
import java.util.Map;

/**
* ZenID configuration.
Expand All @@ -46,27 +44,20 @@
@Configuration
public class ZenidConfig {

public static final Map<SerializationFeature, Boolean> SERIALIZATION_FEATURES = Map.of(
SerializationFeature.FAIL_ON_EMPTY_BEANS, false,
SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false,
SerializationFeature.WRITE_DATES_WITH_ZONE_ID, true
);

public static final Map<DeserializationFeature, Boolean> DESERIALIZATION_FEATURES = Map.of(
DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false
);

/**
* @param configProps Configuration properties
* @return Object mapper bean specific to ZenID json format
*/
@Bean("objectMapperZenid")
public ObjectMapper objectMapperZenid() {
public ObjectMapper objectMapperZenid(final ZenidConfigProps configProps) {
final JavaTimeModule javaTimeModule = createJavaTimeModule();

final ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(javaTimeModule);
DESERIALIZATION_FEATURES.forEach(mapper::configure);
SERIALIZATION_FEATURES.forEach(mapper::configure);
final RestClientConfiguration.JacksonConfiguration jacksonConfiguration = configProps.getRestClientConfig().getJacksonConfiguration();
Assert.state(jacksonConfiguration != null, "Jackson configuration is expected to ZenId working properly");
jacksonConfiguration.getDeserialization().forEach(mapper::configure);
jacksonConfiguration.getSerialization().forEach(mapper::configure);
return mapper;
}

Expand All @@ -83,20 +74,15 @@ private static JavaTimeModule createJavaTimeModule() {
* @return REST client for ZenID service API calls
*/
@Bean("restClientZenid")
public RestClient restClientZenid(ZenidConfigProps configProps) throws RestClientException {
HttpHeaders headers = new HttpHeaders();
public RestClient restClientZenid(final ZenidConfigProps configProps) throws RestClientException {
final HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE);
headers.add(HttpHeaders.AUTHORIZATION, "api_key " + configProps.getApiKey());
headers.add(HttpHeaders.USER_AGENT, configProps.getServiceUserAgent());

final RestClientConfiguration.JacksonConfiguration jacksonConfiguration = new RestClientConfiguration.JacksonConfiguration();
jacksonConfiguration.getSerialization().putAll(SERIALIZATION_FEATURES);
jacksonConfiguration.getDeserialization().putAll(DESERIALIZATION_FEATURES);

final RestClientConfiguration restClientConfiguration = configProps.getRestClientConfig();
restClientConfiguration.setBaseUrl(configProps.getServiceBaseUrl());
restClientConfiguration.setDefaultHttpHeaders(headers);
restClientConfiguration.setJacksonConfiguration(jacksonConfiguration);
return new DefaultRestClient(restClientConfiguration, createJavaTimeModule());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public Image upscaleImage(final OwnerId ownerId, final Image sourceImage, final

try {
final BufferedImage bufferedSourceImage = ImageIO.read(new ByteArrayInputStream(sourceImage.getData()));
if (bufferedSourceImage == null) {
throw new PresenceCheckException("Unable to read image " + filename);
}
final int currentWidth = bufferedSourceImage.getWidth();
final int currentHeight = bufferedSourceImage.getHeight();
logger.info("Processing image: {}, resolution: {} x {} px, size: {} KB, {}", filename, currentWidth, currentHeight, sourceImage.getData().length / KILOBYTE, ownerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,17 @@ public String createOtpCodeForResend(OnboardingProcessEntity process, OtpType ot
*/
public void cancelOtp(OnboardingProcessEntity process, OtpType otpType) {
final String processId = process.getId();
// Fail current OTP, if it is present
// Fail current OTP, if it is present and in ACTIVE state
onboardingOtpRepository.findNewestByProcessIdAndType(processId, otpType).ifPresent(otp -> {
final Date now = new Date();
if (otp.getStatus() != OtpStatus.FAILED) {
if (otp.getStatus() == OtpStatus.ACTIVE) {
otp.setStatus(OtpStatus.FAILED);
otp.setTimestampLastUpdated(now);
otp.setTimestampFailed(now);
otp.setErrorDetail(OnboardingOtpEntity.ERROR_CANCELED);
otp.setErrorOrigin(ErrorOrigin.OTP_VERIFICATION);
onboardingOtpRepository.save(otp);
auditService.audit(otp, "OTP canceled for user: {}", process.getUserId());
auditService.audit(otp, "OTP canceled for process ID: {}, user ID: {}, otp type: {}", process.getId(), process.getUserId(), otpType);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ enrollment-server-onboarding.document-verification.zenid.restClientConfig.proxyU
enrollment-server-onboarding.document-verification.zenid.restClientConfig.proxyPassword=
enrollment-server-onboarding.document-verification.zenid.restClientConfig.connectionTimeout=10000
enrollment-server-onboarding.document-verification.zenid.restClientConfig.responseTimeout=60000
enrollment-server-onboarding.document-verification.zenid.restClientConfig.jacksonConfiguration.serialization.FAIL_ON_EMPTY_BEANS=false
enrollment-server-onboarding.document-verification.zenid.restClientConfig.jacksonConfiguration.serialization.WRITE_DATES_AS_TIMESTAMPS=false
enrollment-server-onboarding.document-verification.zenid.restClientConfig.jacksonConfiguration.serialization.WRITE_DATES_WITH_ZONE_ID=true
enrollment-server-onboarding.document-verification.zenid.restClientConfig.jacksonConfiguration.deserialization.ADJUST_DATES_TO_CONTEXT_TIME_ZONE=false
enrollment-server-onboarding.document-verification.zenid.restClientConfig.jacksonConfiguration.deserialization.FAIL_ON_UNKNOWN_PROPERTIES=false

# iProov configuration
enrollment-server-onboarding.presence-check.iproov.apiKey=${IPROOV_API_KEY}
Expand Down
Loading

0 comments on commit 3a70e54

Please sign in to comment.