Skip to content

Commit

Permalink
Fix #978: Remove Guava dependency (#980)
Browse files Browse the repository at this point in the history
* Fix #978: Remove Guava dependency
  • Loading branch information
banterCZ authored Jan 12, 2024
1 parent f1c86b9 commit 8bb870a
Show file tree
Hide file tree
Showing 21 changed files with 203 additions and 116 deletions.
13 changes: 13 additions & 0 deletions enrollment-server-onboarding-domain-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@
<groupId>io.getlime.security</groupId>
<artifactId>powerauth-java-crypto</artifactId>
</dependency>

<!-- Bouncy Castle -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
*/
package com.wultra.app.enrollmentserver.model.integration;

import com.google.common.io.BaseEncoding;
import io.getlime.security.powerauth.crypto.lib.util.Hash;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Setter;
import lombok.ToString;
import org.bouncycastle.util.encoders.Base32;

import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
Expand Down Expand Up @@ -73,9 +74,8 @@ public String getUserIdSecured() {
throw new IllegalStateException("Missing userId value");
}
if (userIdSecured == null) {
userIdSecured = BaseEncoding.base32()
.omitPadding()
.encode(Hash.sha256(userId));
userIdSecured = new String(Base32.encode(Hash.sha256(userId)), StandardCharsets.UTF_8)
.replace("=", "");
if (userIdSecured.length() > USER_ID_MAX_LENGTH) {
userIdSecured = userIdSecured.substring(0, USER_ID_MAX_LENGTH);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* PowerAuth Enrollment Server
* Copyright (C) 2024 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 <http://www.gnu.org/licenses/>.
*/
package com.wultra.app.enrollmentserver.model.integration;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Test for {@link OwnerId}.
*
* @author Lubos Racansky, [email protected]
*/
class OwnerIdTest {

@Test
void testUserIdSecured() {
final OwnerId tested = new OwnerId();
tested.setUserId("Joe");

final String result = tested.getUserIdSecured();

assertEquals("NXMLPV6TYXCGRGZT4UNZ6EF4NKN6RH7I7IVBE7EMNQB42BOWRLHA", result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.wultra.app.enrollmentserver.model.enumeration.DocumentType;
import com.wultra.app.enrollmentserver.model.enumeration.DocumentVerificationStatus;
import com.wultra.app.enrollmentserver.model.integration.*;
import com.wultra.app.enrollmentserver.model.integration.Image;
import com.wultra.app.enrollmentserver.model.integration.*;
import com.wultra.app.onboardingserver.api.errorhandling.DocumentVerificationException;
import com.wultra.app.onboardingserver.api.provider.DocumentVerificationProvider;
import com.wultra.app.onboardingserver.common.database.entity.DocumentResultEntity;
Expand All @@ -33,10 +32,10 @@
import com.wultra.app.onboardingserver.provider.innovatrics.model.api.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -99,7 +98,7 @@ public DocumentsSubmitResult submitDocuments(OwnerId id, List<SubmittedDocument>
}

final Optional<DocumentSubmitResult> primaryPage = results.getResults().stream()
.filter(result -> Strings.isNullOrEmpty(result.getRejectReason()) && Strings.isNullOrEmpty(result.getErrorDetail()))
.filter(result -> StringUtils.isBlank(result.getRejectReason()) && StringUtils.isBlank(result.getErrorDetail()))
.findFirst();

if (primaryPage.isPresent()) {
Expand Down Expand Up @@ -132,9 +131,9 @@ public DocumentsVerificationResult verifyDocuments(OwnerId id, List<String> uplo

final String rejectReasons = results.getResults().stream()
.map(DocumentVerificationResult::getRejectReason)
.filter(StringUtils::hasText)
.filter(StringUtils::isNotBlank)
.collect(Collectors.joining(";"));
if (StringUtils.hasText(rejectReasons)) {
if (StringUtils.isNotBlank(rejectReasons)) {
logger.debug("Some documents were rejected: rejectReasons={}, {}", rejectReasons, id);
results.setStatus(DocumentVerificationStatus.REJECTED);
results.setRejectReason(rejectReasons);
Expand Down Expand Up @@ -172,7 +171,7 @@ public void cleanupDocuments(OwnerId id, List<String> uploadIds) throws RemoteCo
public List<String> parseRejectionReasons(DocumentResultEntity docResult) throws DocumentVerificationException {
logger.debug("Parsing rejection reasons of {}", docResult);
final String rejectionReasons = docResult.getRejectReason();
if (!StringUtils.hasText(rejectionReasons)) {
if (StringUtils.isBlank(rejectionReasons)) {
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.wultra.app.enrollmentserver.model.integration.OwnerId;
import com.wultra.app.enrollmentserver.model.integration.SessionInfo;
import com.wultra.app.onboardingserver.common.database.IdentityVerificationRepository;
Expand Down Expand Up @@ -125,7 +124,7 @@ private static String fetchCustomerId(final OwnerId id, final IdentityVerificati
}

final String customerId = (String) sessionInfo.getSessionAttributes().get(SessionInfo.ATTRIBUTE_PRIMARY_DOCUMENT_REFERENCE);
if (Strings.isNullOrEmpty(customerId)) {
if (StringUtils.isBlank(customerId)) {
throw new IdentityVerificationException("Missing a customer ID value for calling Innovatrics, " + id);
}
return customerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.wultra.app.onboardingserver.provider.innovatrics;

import com.google.common.base.Strings;
import com.wultra.app.enrollmentserver.model.enumeration.PresenceCheckStatus;
import com.wultra.app.enrollmentserver.model.integration.Image;
import com.wultra.app.enrollmentserver.model.integration.OwnerId;
Expand All @@ -31,6 +30,7 @@
import com.wultra.app.onboardingserver.provider.innovatrics.model.api.SelfieSimilarityWith;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -151,7 +151,7 @@ private static Optional<PresenceCheckError> fail(final String errorDetail) {

private static String fetchCustomerId(final OwnerId id, final SessionInfo sessionInfo) throws PresenceCheckException {
final String customerId = (String) sessionInfo.getSessionAttributes().get(SessionInfo.ATTRIBUTE_PRIMARY_DOCUMENT_REFERENCE);
if (Strings.isNullOrEmpty(customerId)) {
if (StringUtils.isBlank(customerId)) {
throw new PresenceCheckException("Missing a customer ID value for calling Innovatrics, " + id);
}
return customerId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.wultra.app.enrollmentserver.model.enumeration.PresenceCheckStatus;
import com.wultra.app.enrollmentserver.model.integration.Image;
import com.wultra.app.enrollmentserver.model.integration.OwnerId;
Expand All @@ -34,6 +33,7 @@
import com.wultra.app.onboardingserver.provider.iproov.model.api.EnrolResponse;
import com.wultra.core.rest.client.base.RestClientException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand Down Expand Up @@ -161,7 +161,7 @@ public SessionInfo startPresenceCheck(OwnerId id) throws PresenceCheckException,
@Override
public PresenceCheckResult getResult(OwnerId id, SessionInfo sessionInfo) throws PresenceCheckException, RemoteCommunicationException {
final String token = (String) sessionInfo.getSessionAttributes().get(VERIFICATION_TOKEN);
if (Strings.isNullOrEmpty(token)) {
if (StringUtils.isBlank(token)) {
throw new PresenceCheckException("Missing a token value for verification validation in iProov, " + id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Preconditions;
import com.wultra.app.enrollmentserver.model.enumeration.CardSide;
import com.wultra.app.enrollmentserver.model.enumeration.DocumentType;
import com.wultra.app.enrollmentserver.model.enumeration.DocumentVerificationStatus;
import com.wultra.app.enrollmentserver.model.integration.*;
import com.wultra.app.onboardingserver.api.errorhandling.DocumentVerificationException;
import com.wultra.app.onboardingserver.api.provider.DocumentVerificationProvider;
import com.wultra.app.onboardingserver.common.database.DocumentVerificationRepository;
import com.wultra.app.onboardingserver.common.database.entity.DocumentResultEntity;
import com.wultra.app.onboardingserver.common.database.entity.DocumentVerificationEntity;
import com.wultra.app.onboardingserver.common.errorhandling.RemoteCommunicationException;
import com.wultra.app.onboardingserver.provider.zenid.model.api.*;
import com.wultra.app.onboardingserver.api.errorhandling.DocumentVerificationException;
import com.wultra.app.onboardingserver.api.provider.DocumentVerificationProvider;
import com.wultra.core.rest.client.base.RestClientException;
import jakarta.annotation.Nullable;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand Down Expand Up @@ -336,7 +336,7 @@ public List<String> parseRejectionReasons(DocumentResultEntity docResult) throws

@Override
public VerificationSdkInfo initVerificationSdk(OwnerId id, Map<String, String> initAttributes) throws RemoteCommunicationException, DocumentVerificationException {
Preconditions.checkArgument(initAttributes.containsKey(SDK_INIT_TOKEN), "Missing initialization token for ZenID SDK");
Validate.isTrue(initAttributes.containsKey(SDK_INIT_TOKEN), "Missing initialization token for ZenID SDK");
String token = initAttributes.get(SDK_INIT_TOKEN);

ResponseEntity<ZenidWebInitSdkResponse> responseEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.wultra.app.onboardingserver.provider.zenid;

import com.google.common.base.Preconditions;
import com.wultra.app.enrollmentserver.model.enumeration.CardSide;
import com.wultra.app.enrollmentserver.model.enumeration.DocumentType;
import com.wultra.app.enrollmentserver.model.integration.OwnerId;
Expand All @@ -27,6 +26,7 @@
import com.wultra.core.rest.client.base.RestClientException;
import jakarta.annotation.Nullable;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand Down Expand Up @@ -104,7 +104,7 @@ public ZenidRestApiService(
*/
public ResponseEntity<ZenidWebUploadSampleResponse> uploadSample(OwnerId ownerId, SubmittedDocument document)
throws RestClientException {
Preconditions.checkNotNull(document.getPhoto(), "Missing photo in " + document);
Validate.notNull(document.getPhoto(), "Missing photo in " + document);

final MultiValueMap<String, String> queryParams = buildQueryParams(ownerId, document);

Expand Down Expand Up @@ -148,9 +148,8 @@ public ResponseEntity<ZenidWebUploadSampleResponse> syncSample(String documentId
* @param sampleIds Ids of previously uploaded samples.
* @return Response entity with the investigation result
*/
public ResponseEntity<ZenidWebInvestigateResponse> investigateSamples(List<String> sampleIds)
throws RestClientException {
Preconditions.checkArgument(sampleIds.size() > 0, "Missing sample ids for investigation");
public ResponseEntity<ZenidWebInvestigateResponse> investigateSamples(List<String> sampleIds) throws RestClientException {
Validate.notEmpty(sampleIds, "Missing sample ids for investigation");

MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>();
sampleIds.forEach(sampleId -> queryParams.add("sampleIDs", sampleId));
Expand Down
5 changes: 5 additions & 0 deletions enrollment-server-onboarding/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>

<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
*/
package com.wultra.app.onboardingserver.docverify.mock.provider;

import com.google.common.base.Ascii;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.wultra.app.enrollmentserver.model.enumeration.DocumentType;
import com.wultra.app.enrollmentserver.model.enumeration.DocumentVerificationStatus;
import com.wultra.app.enrollmentserver.model.integration.*;
import com.wultra.app.onboardingserver.api.errorhandling.DocumentVerificationException;
import com.wultra.app.onboardingserver.api.provider.DocumentVerificationProvider;
import com.wultra.app.onboardingserver.common.database.entity.DocumentResultEntity;
import com.wultra.app.onboardingserver.common.database.entity.DocumentVerificationEntity;
import com.wultra.app.onboardingserver.docverify.mock.MockConst;
import com.wultra.app.onboardingserver.api.errorhandling.DocumentVerificationException;
import com.wultra.app.onboardingserver.api.provider.DocumentVerificationProvider;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -65,11 +65,12 @@ public class WultraMockDocumentVerificationProvider implements DocumentVerificat
public WultraMockDocumentVerificationProvider() {
logger.warn("Using mocked version of {}", DocumentVerificationProvider.class.getName());

submittedDocs = CacheBuilder.newBuilder()
// TODO (racansky, 2024-01-04) consider removing Caffeine dependency and replace it by simple LinkedHashMap#removeEldestEntry
submittedDocs = Caffeine.newBuilder()
.expireAfterWrite(Duration.ofHours(1))
.build();

verificationUploadIds = CacheBuilder.newBuilder()
verificationUploadIds = Caffeine.newBuilder()
.expireAfterWrite(Duration.ofHours(1))
.build();
}
Expand Down Expand Up @@ -242,7 +243,7 @@ private DocumentSubmitResult toDocumentSubmitResult(final SubmittedDocument docu
if (docId.startsWith("upload")) {
uploadedDocId = docId;
} else {
uploadedDocId = Ascii.truncate("uploaded-" + docId, 36, "...");
uploadedDocId = StringUtils.truncate("uploaded-" + docId, 33) + "...";
}
submitResult.setUploadId(uploadedDocId);
submitResult.setValidationResult("{\"validationResult\": { \"data\": \"" + docId + "\" } }");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.wultra.app.onboardingserver.impl.service;

import com.google.common.io.Files;
import com.wultra.app.enrollmentserver.model.integration.Image;
import com.wultra.app.enrollmentserver.model.integration.OwnerId;
import com.wultra.app.onboardingserver.api.errorhandling.PresenceCheckException;
Expand Down Expand Up @@ -74,7 +73,7 @@ public Image upscaleImage(final OwnerId ownerId, final Image sourceImage, final
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedOutputImage, TYPE_PNG, outputStream);

final String filenamePng = Files.getNameWithoutExtension(filename) + SUFFIX_PNG;
final String filenamePng = getFilenameWithoutExtension(filename) + SUFFIX_PNG;

final byte[] targetData = outputStream.toByteArray();
logger.debug("Image: {}, size: {} KB, {}", filenamePng, targetData.length / KILOBYTE, ownerId);
Expand All @@ -90,4 +89,12 @@ public Image upscaleImage(final OwnerId ownerId, final Image sourceImage, final
throw new PresenceCheckException("Unable to read image", e);
}
}

private static String getFilenameWithoutExtension(final String filename) {
if (filename.contains(".")) {
return filename.substring(0, filename.lastIndexOf("."));
} else {
return filename;
}
}
}
Loading

0 comments on commit 8bb870a

Please sign in to comment.