Skip to content

Commit

Permalink
feat: Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzo-ingenito committed Jan 17, 2024
1 parent e29149f commit 7177758
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public class IniCFG {
private boolean enableLog;

@Value("${ini.client.auth-cert.path}")
private String trustStoreLocation;
private String authCertLocation;

@Value("${ini.client.auth-cert.password}")
private String trustStorePassword;
private String authCertPassword;

@Value("${ini.client.auth-cert.alias}")
private String trustStoreAlias;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import javax.xml.bind.JAXB;

import it.finanze.sanita.fse2.ms.iniclient.service.IConfigSRV;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -26,7 +25,16 @@

import it.finanze.sanita.fse2.ms.iniclient.client.IIniClient;
import it.finanze.sanita.fse2.ms.iniclient.config.Constants;
import it.finanze.sanita.fse2.ms.iniclient.dto.*;
import it.finanze.sanita.fse2.ms.iniclient.dto.DeleteRequestDTO;
import it.finanze.sanita.fse2.ms.iniclient.dto.DocumentEntryDTO;
import it.finanze.sanita.fse2.ms.iniclient.dto.DocumentTreeDTO;
import it.finanze.sanita.fse2.ms.iniclient.dto.GetMergedMetadatiDTO;
import it.finanze.sanita.fse2.ms.iniclient.dto.IniResponseDTO;
import it.finanze.sanita.fse2.ms.iniclient.dto.JWTPayloadDTO;
import it.finanze.sanita.fse2.ms.iniclient.dto.JWTTokenDTO;
import it.finanze.sanita.fse2.ms.iniclient.dto.MergedMetadatiRequestDTO;
import it.finanze.sanita.fse2.ms.iniclient.dto.SubmissionSetEntryDTO;
import it.finanze.sanita.fse2.ms.iniclient.dto.UpdateRequestDTO;
import it.finanze.sanita.fse2.ms.iniclient.dto.response.GetReferenceResponseDTO;
import it.finanze.sanita.fse2.ms.iniclient.enums.ActionEnumType;
import it.finanze.sanita.fse2.ms.iniclient.enums.ProcessorOperationEnum;
Expand All @@ -36,6 +44,7 @@
import it.finanze.sanita.fse2.ms.iniclient.logging.LoggerHelper;
import it.finanze.sanita.fse2.ms.iniclient.repository.entity.IniEdsInvocationETY;
import it.finanze.sanita.fse2.ms.iniclient.repository.mongo.impl.IniInvocationRepo;
import it.finanze.sanita.fse2.ms.iniclient.service.IConfigSRV;
import it.finanze.sanita.fse2.ms.iniclient.service.IIniInvocationSRV;
import it.finanze.sanita.fse2.ms.iniclient.utility.RequestUtility;
import it.finanze.sanita.fse2.ms.iniclient.utility.StringUtility;
Expand All @@ -47,16 +56,6 @@
import oasis.names.tc.ebxml_regrep.xsd.query._3.AdhocQueryResponse;
import oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryError;
import oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.webjars.NotFoundException;

import javax.xml.bind.JAXB;
import java.io.StringWriter;
import java.util.Date;

@Service
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public class SecuritySRV implements ISecuritySRV {
public SSLContext createSslCustomContext() throws NoSuchAlgorithmException, CertificateException, IOException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {

KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(new ByteArrayInputStream(FileUtility.getFileFromInternalResources(iniCFG.getTrustStoreLocation())), iniCFG.getTrustStorePassword().toCharArray());
keystore.load(new ByteArrayInputStream(FileUtility.getFileFromInternalResources(iniCFG.getAuthCertLocation())), iniCFG.getAuthCertPassword().toCharArray());

KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keystore, iniCFG.getTrustStorePassword().toCharArray());
keyManagerFactory.init(keystore, iniCFG.getAuthCertPassword().toCharArray());

SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustAllCerts, new java.security.SecureRandom());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@
*/
package it.finanze.sanita.fse2.ms.iniclient.utility;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

import it.finanze.sanita.fse2.ms.iniclient.exceptions.base.BusinessException;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
* The Class FileUtils.
Expand Down Expand Up @@ -56,30 +51,6 @@ public static byte[] getFileFromInternalResources(final String filename) {
return b;
}


// public static ByteArrayInputStream getFileFromGenericResource(final String path) {
// InputStream is = null;
// try {
// if (path.contains("classpath:")) {
// String sanitizedPath = path.replace("classpath:", "");
// is = Thread.currentThread().getContextClassLoader().getResourceAsStream(sanitizedPath);
// } else {
// is = Files.newInputStream(Paths.get(path));
// }
// return new ByteArrayInputStream(FileUtility.getByteFromInputStream(is));
// } catch (Exception e) {
// throw new BusinessException("Errore in fase di recupero contenuto del file:" + e.getMessage());
// } finally {
// if (is != null) {
// try {
// is.close();
// } catch (IOException e) {
// log.error("Error: {}", e.getMessage());
// }
// }
// }
// }

/**
* Recupero contenuto file da input stream.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import oasis.names.tc.ebxml_regrep.xsd.query._3.ResponseOptionType;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.AdhocQueryType;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.ObjectFactory;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotListType;
import oasis.names.tc.ebxml_regrep.xsd.rim._3.SlotType1;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ReadBodyBuilderUtility {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void sslContextSuccessTest() throws NoSuchAlgorithmException, UnrecoverableKeyEx
@Test
@DisplayName("SSLContext - failed to load trust store")
void sslContextTrustStoreFailureTest() {
when(iniCFG.getTrustStoreLocation()).thenReturn("nothing");
when(iniCFG.getAuthCertLocation()).thenReturn("nothing");
assertThrows(BusinessException.class, () -> securitySRV.createSslCustomContext());
}

Expand Down

0 comments on commit 7177758

Please sign in to comment.