First Commit - Source Code from Reply

This commit is contained in:
vincenzofariello
2024-05-13 12:54:14 +02:00
parent 73e32a5020
commit a15aee1f08
11184 changed files with 1065913 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
package mnp.utility;
public class ApplicationCostants {
private ApplicationCostants() {
}
//nome dei parametri della request sulla richiesta di upload
//che riceviamo dagli altri OLO
public static final String REQUEST_OLO_MITTENTE = "Operatore";
public static final String REQUEST_TIPO_FILE = "TipoFile";
public static final String REQUEST_FILE_NAME = "FileName";
}

View File

@@ -0,0 +1,74 @@
package mnp.utility;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.net.ssl.SSLSocketFactory;
public final class CustomSSLSocketFactory
extends SSLSocketFactory {
//The original socket factory without any timeouts set for the sockets.
private SSLSocketFactory originalFactory;
//the time in milliseconds after which, socket should timeout.
private int socketTimeout;
/**
* Constructor : set the socket factory and timeout
* period.
*/
public CustomSSLSocketFactory(SSLSocketFactory originalFactory, int timeout) {
super();
this.originalFactory = originalFactory;
socketTimeout = timeout;
}
/*****Override the original methods to include the timeouts for sockets*****/
public String[] getDefaultCipherSuites() {
return originalFactory.getDefaultCipherSuites();
}
public String[] getSupportedCipherSuites() {
return originalFactory.getSupportedCipherSuites();
}
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
Socket socket = originalFactory.createSocket(s, host, port, autoClose);
socket.setSoTimeout(socketTimeout);
return socket;
}
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
Socket socket = originalFactory.createSocket(host, port);
socket.setSoTimeout(socketTimeout);
return socket;
}
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
Socket socket = originalFactory.createSocket(host, port, localHost, localPort);
socket.setSoTimeout(socketTimeout);
return socket;
}
public Socket createSocket(InetAddress host, int port) throws IOException {
Socket socket = originalFactory.createSocket(host, port);
socket.setSoTimeout(socketTimeout);
return socket;
}
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
Socket socket = originalFactory.createSocket(address, port, localAddress, localPort);
socket.setSoTimeout(socketTimeout);
return socket;
}
}

View File

@@ -0,0 +1,186 @@
package mnp.utility;
import java.net.URL;
import javax.ejb.EJBHome;
import javax.ejb.EJBLocalHome;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.sql.DataSource;
import javax.mail.Session;
import java.util.Properties;
import javax.naming.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2007</p>
* <p>Company: </p>
* @author poccia carlo
* @version 1.0
* @version 2.0 C09_2017 RU_517 line 178 (Privacy Violation)
*/
public class FEServiceLocator {
private InitialContext ic;
public FEServiceLocator() throws Exception {
try {
ic = getInitialContext();
}
catch (NamingException ne) {
throw new RuntimeException(ne);
}
}
private Object lookup(String jndiName) throws NamingException {
return ic.lookup(jndiName);
}
/**
* will get the ejb Local home factory.
* clients need to cast to the type of EJBHome they desire
*
* @return the Local EJB Home corresponding to the homeName
*/
public EJBLocalHome getLocalHome(String jndiHomeName) throws NamingException {
return (EJBLocalHome) lookup(jndiHomeName);
}
/**
* will get the ejb Remote home factory.
* clients need to cast to the type of EJBHome they desire
*
* @return the EJB Home corresponding to the homeName
*/
public EJBHome getRemoteHome(String jndiHomeName, Class className) throws
NamingException {
Object objref = lookup(jndiHomeName);
return (EJBHome) PortableRemoteObject.narrow(objref, className);
}
/**
* This method helps in obtaining the jms connection factory
* @return the factory for obtaining jms connection
*/
public ConnectionFactory getConnectionFactory(String connFactoryName) throws
NamingException {
return (ConnectionFactory) lookup(connFactoryName);
}
/**
* This method obtains the topc itself for a caller
* @return the Topic Destination to send messages to
*/
public Destination getDestination(String destName) throws NamingException {
return (Destination) lookup(destName);
}
/**
* This method obtains the datasource itself for a caller
* @return the DataSource corresponding to the name parameter
*/
public DataSource getDataSource(String dataSourceName) throws NamingException {
return (DataSource) lookup(dataSourceName);
}
/**
* This method obtains the E-mail session itself for a caller
* @return the Session corresponding to the name parameter
*/
public Session getSession(String sessionName) throws NamingException {
return (Session) lookup(sessionName);
}
/**
* @return the URL value corresponding
* to the env entry name.
*/
public URL getUrl(String envName) throws NamingException {
return (URL) lookup(envName);
}
/**
* @return the boolean value corresponding
* to the env entry
*/
public boolean getBoolean(String envName) throws NamingException {
Boolean bool = (Boolean) lookup(envName);
return bool.booleanValue();
}
/**
* @return the String value corresponding
* to the env entry name.
*/
public String getString(String envName) throws NamingException {
return (String) lookup(envName);
}
/**
* finalize
*
* @throws Throwable
* @todo Implement this java.lang.Object method
*/
protected void finalize() throws Throwable {
super.finalize();
closeAll();
}
public void closeAll() {
if (ic != null) {
try {
ic.close();
}
catch (NamingException ex) {
ex.printStackTrace();
}
}
}
/**
* Ritorna il contesto
* @return
* @throws Exception
*/
private InitialContext getInitialContext() throws Exception {
String user = "";
String password = "";
try {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
Resources.getFEWLServerContextFactory());
System.out.println("Context.INITIAL_CONTEXT_FACTORY: "+Resources.getFEWLServerContextFactory());
properties.put(Context.PROVIDER_URL, Resources.getFEWLServerUrl());
System.out.println("Context.PROVIDER_URL: "+Resources.getFEWLServerUrl());
user = Resources.getFEWLServerUser();
password = Resources.getFEWLServerPwd();
if ( (user != null) && (!user.equals(""))) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS,
password == null ? "" : password);
}
return new InitialContext(properties);
}
catch (Exception e) {
System.out.println("I parametri di configurazione del Context sono : \n");
System.out.println("context.factory : [" +
Resources.getFEWLServerContextFactory() + "]");
System.out.println("url : [" + Resources.getFEWLServerUrl() + "]");
System.out.println("user [" + user + "]");
// C09_2017 RU_517 BEGIN
System.out.println("password [n/a] removed from logs as of C09_2017 RU_517 Fortify Privacy Violation ");
//System.out.println("password [" +password+"]");
// C09_2017 RU_517 END
throw e;
}
}
}

View File

@@ -0,0 +1,193 @@
package mnp.utility;
import it.valueteam.logging.Tracer;
import java.util.*;
import java.lang.*;
import java.io.*;
/**
* Classe con funzioni varie
* @version 2.0 C09_2017 RU_517 line 134 (Unreleased Resource: Streams)
*
*/
public class Functions
{
/**
* Elimino codici strani dall'XML
* */
public static String parseClear(String s) {
StringBuffer appo = new StringBuffer("");
for(int i=0; i<s.length(); i++) {
char c = s.charAt(i);
String str = String.valueOf(c);
if( !str.equals("\n") &&
!str.equals("\t") &&
!str.equals("\r")
) {
appo.append(str);
}
}
return appo.toString();
}
// ritorna la stringa corrispondente alla String s, secondo HTTP
public static String ParamString(String s)
{
Hashtable H=loadParamHT();
return sostituteChars(s,H);
}
// ritorna la stringa corrispondente alla String s, secondo HTML
public static String HtmlString(String s)
{
Hashtable H=loadHtmlHT();
return sostituteChars(s,H);
}
// ritorna la stringa corrispondente alla String s, secondo XML
public static String xmlString(String s)
{
Hashtable H=loadHtmlHT();
boolean inTag = false;
char openTag = '<';
char closeTag = '>';
StringBuffer sb=new StringBuffer (s);
for(int i=0;i<sb.length();i++)
{
char c = sb.charAt(i);
if( c==openTag )
inTag = true;
Character chara = new Character(c);
if(!inTag && H.containsKey(chara))
{
sb.deleteCharAt(i);
String sost=(String)H.get(chara);
sb.insert( i,sost );
i+=(sost.length()-1);
}
if( inTag && c==closeTag )
inTag = false;
}
return sb.toString();
}
// funzione standard di sostituzione caratteri a String s secondo l'Hashtable H
static String sostituteChars(String s,Hashtable H)
{
StringBuffer sb=new StringBuffer (s);
for(int i=0;i<sb.length();i++)
{
Character c=new Character(sb.charAt(i));
if(H.containsKey(c))
{
sb.deleteCharAt(i);
String sost=(String)H.get(c);
sb.insert( i,sost );
i+=(sost.length()-1);
}
}
return sb.toString();
}
// restituisce l' Hashtable cotenente i caratteri non ammessi come chiavi e la stringa equivalente in HTTP come elemento
private static Hashtable loadParamHT()
{
Hashtable h=new Hashtable();
//h.put(new Character(' '), "%20");h.put(new Character('\n'), "%0D");h.put(new Character('!'), "%21");h.put(new Character((char)34), "%22");// " doppio apiceh.put(new Character((char)92), "%5C");// \ backslashh.put(new Character('#'), "%23");h.put(new Character('&'), "%26");h.put(new Character('*'), "%2A");h.put(new Character((char)39), "%27");// ' apiceh.put(new Character('%'), "%25");h.put(new Character('`'), "%60");h.put(new Character('/'), "%2F");h.put(new Character('>'), "%3E");h.put(new Character('<'), "%3C");h.put(new Character('?'), "%3F");h.put(new Character('='), "%3D");h.put(new Character('-'), "%2D");h.put(new Character('@'), "%40");
for (int i=0;i<256;i++)
{
if(i==32) {
}
if(!(i>47&&i<58 || i>64&&i<91 || i>96 && i<123) && (i!=10)) h.put(new Character((char)i), "%"+Integer.toHexString(i) );
}
return h;
}
// restituisce l' Hashtable cotenente i caratteri non ammessi come chiavi e la stringa equivalente in HTML come elemento
private static Hashtable loadHtmlHT()
{
Hashtable h=new Hashtable();
h.put(new Character('&'),"&amp;" );
return h;
}
/**
* Copia un file in un altro
* */
public static void copyFile(File in, File out) throws Exception {
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(in);
fos = new FileOutputStream(out);
byte[] buf = new byte[1024];
int i = 0;
while ( (i = fis.read(buf)) != -1) {
fos.write(buf, 0, i);
}
}
catch (Exception ex) {
throw ex;
}
finally {
// C09_2017 RU_517 BEGIN
// Closing when previously closed will have no effect;
if(null != fis) {
try {
fis.close();
} catch (Exception e) {
fis = null;
System.out.println("FAIL release stream: ["+e.getClass().getName()+"] - " + e.getMessage());
}
}
if(null != fos) {
try {
fos.close();
} catch (Exception e) {
fos = null;
System.out.println("FAIL release stream: ["+e.getClass().getName()+"] - " + e.getMessage());
}
}
// C09_2017 RU_517 END
}
}
public static void initializeSecurityTracer() {
try {
System.out.println("configuring security log");
Properties pLog = new Properties();
Properties pLog1 = new Properties();
pLog.put("tracciamento.dir",Resources.getTRACCIAMENTO_DIR());
pLog.put("tracciamento.fileName",Resources.getTRACCIAMENTO_FILENAME());
pLog.put("tracciamento.pattern",Resources.getTRACCIAMENTO_PATTERN());
/** Begin Log4j base */
pLog1.put("log4j.logger.org.apache", Resources.getLOGGER_LEVEL_AND_APPENDER_NAME());
pLog1.put("log4j.appender.stdout", Resources.getAPPENDER());
pLog1.put("log4j.appender.stdout.layout", Resources.getLAYOUT());
pLog1.put("log4j.appender.stdout.layout.ConversionPattern", Resources.getCONVERSION_PATTERN());
/** End Log4j base*/
SecurityLogLoader actionLogMapping = new SecurityLogLoader();
Hashtable h = actionLogMapping.getActionMap();
Hashtable hh = actionLogMapping.getRetCodeMap();
Tracer.configure(pLog,pLog1,h,hh);
System.out.println(" security log configured");
} catch (Exception ex) {
System.err.println("Errore nell'inizializzazione del tracer");
ex.printStackTrace();
}
}
}

View File

@@ -0,0 +1,554 @@
package mnp.utility;
import java.io.*;
import java.net.*;
import java.security.*;
import javax.net.ssl.*;
import mnp.log.LoggableFE;
import mnp.log.ProcessLoggerFE;
import mnp.objects.LogInfoFE;
import mnp.objects.LogProcessFE;
public class OLOComunicationManager implements LoggableFE{
private static boolean httpsFlag;
private static boolean sslFlag;
private static final String BOUNDARY = "--MNP_BOUNDARY_FOR_MULTIPART";
private static int timeout = 0;
protected String versione = "1.4.0.1";
protected String codiceProcesso = "PC"; // codice processo?
private ProcessLoggerFE log = null;
static {
try {
//parametri per i test
httpsFlag = Resources.getExternalHttpsFlag();
sslFlag = Resources.getExternalSslFlag();
timeout = Resources.getHttpTimeOut();
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println(
"Impossibile inizializzare OLOComunicationManager.....Controllare proprietà!!!!!!!!!!!!!");
}
}
public OLOComunicationManager() throws Exception {
try {
LogProcessFE logProcessFE = new LogProcessFE();
logProcessFE.setCodice(codiceProcesso);
logProcessFE.setProcess(this);
log = new ProcessLoggerFE(logProcessFE);
}
catch (Exception ex) {
System.out.println("Errore nella creazione del LogProcessFE");
throw new Exception("Errore nella creazione del LogProcessFE");
}
}
/**
* Effettua l'invio del file verso un olo tramite form/multipart
* @param: content il contenuto del file dainviare
* @param: tipofile la tipologia di file da inviare (N,R)
* @param: filename nome del file da inviare
* @param: codOlo codice OLo donating destinatario del file
*/
public String sendFileMultipart(String filename,
String tipofile, String codOlo,
String content,String address) throws
Exception {
String response = null;
OutputStreamWriter wout = null;
java.net.HttpURLConnection connection = null;
String responseMSG = null;
InputStream win = null;
ByteArrayOutputStream requestStream = new ByteArrayOutputStream();
try {
//INIZIO TRATTAMENTO MESSAGGIO - VERSIONE
log.write("0001",versione);
System.out.println("Parametri con cui costruire la REQUEST:\n");
System.out.println(ApplicationCostants.REQUEST_TIPO_FILE + tipofile + ":\n");
System.out.println(ApplicationCostants.REQUEST_OLO_MITTENTE + codOlo +
":\n");
System.out.println(ApplicationCostants.REQUEST_FILE_NAME + filename +
":\n");
connection = getHttpConnection(createAddresWithParameter(address, codOlo, tipofile, filename));
connection.setRequestProperty("Content-type",
"multipart/form-data; boundary=" + BOUNDARY);
connection.setRequestProperty("Accept", "*/*");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Cache-Control", "no-cache");
requestStream.write(new String("--"+BOUNDARY+"\r\n").getBytes());
writeParamValue(requestStream,ApplicationCostants.REQUEST_TIPO_FILE , tipofile);
writeParamValue(requestStream, ApplicationCostants.REQUEST_OLO_MITTENTE, codOlo);
writeParamValue(requestStream, ApplicationCostants.REQUEST_FILE_NAME, filename);
writeFileValue(requestStream, filename, content);
System.out.println("La mia REQUEST multipart:\n"+ requestStream.toString());
wout = new OutputStreamWriter(connection.getOutputStream());
wout.write(requestStream.toString());
wout.write("\r\n");
wout.flush();
response = connection.getResponseMessage();
if (response == null || !response.equalsIgnoreCase("OK")) {
throw new IOException("Errore sulla risposta da OLO,response: "+response);
}
win = connection.getInputStream();
int b = 0;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((b=win.read())!=-1) {
baos.write(b);
}
responseMSG = new String(baos.toByteArray());
baos.close();
responseMSG = URLDecoder.decode(responseMSG,"UTF-8");
//FINE TRATTAMENTO MESSAGGIO
log.write("0002","");
System.out.println("responseMSG:"+responseMSG);
}
catch (java.io.InterruptedIOException tex) {
tex.printStackTrace();
log.write("9999", "Timeout nella connessione con:"+codOlo);
//FINE TRATTAMENTO MESSAGGIO CON ECCEZIONI
log.write("0003","");
// TimeOut nella connessione
throw new InterruptedIOException("Timeout nella connessione: " +
tex.getMessage());
}
catch (IOException ex) {
int responseCode = connection.getResponseCode();
log.write("9999", "responseCode:" + responseCode);
//FINE TRATTAMENTO MESSAGGIO CON ECCEZIONI
log.write("0003","");
if (responseCode == java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT) {
// TimeOut nella connessione FE - OLO
throw new InterruptedIOException(
"Timeout nella connessione con OLO:" + codOlo);
}
else {
throw ex;
}
}
catch (Exception ex) {
//FINE TRATTAMENTO MESSAGGIO CON ECCEZIONI
log.write("0003","");
ex.printStackTrace();
throw ex;
}
catch (Throwable t) {
log.write("9999", "Problemi nell'invio del file all'OLO: " + t.getMessage());
t.printStackTrace();
}
finally {
try {
requestStream.close();
} catch (Exception ex2) {
//nothing to do
}
try {
wout.close();
}
catch (Exception ex2) {
//nothing to do
}
try {
win.close();
}
catch (Exception ex2) {
//nothing to do
}
try {
connection.disconnect();
}
catch (Exception ex1) {
//nothing to do
}
}
return responseMSG;
}
/**
* Setta il valore di un aparametro all'interno di una form multipart
* @param: out: outputstream della connection
* @param: name: nome del parametro da settare nel form
* @param: value: valore del parametro da settare nel form
*/
private static void writeParamValue(ByteArrayOutputStream out, String name,
String value) throws
IOException {
//out.write(BOUNDARY);
out.write(new String("Content-Disposition: form-data; name=\"" + name + "\"\r\n\r\n").getBytes());
//out.write("Content-Type: text/plain;charset=utf-8");
out.write(value.getBytes());
out.write(new String("\r\n").getBytes());
out.write(new String("--"+BOUNDARY+"\r\n").getBytes());
}
/**
* Setta il nome e il contenuto del file all'interno di una form multipart
* @param: out: outputstream della connection
* @param: name: nome del file da inviare nel form
* @param: content: contenuto del file da invare nel form
*/
private static void writeFileValue(ByteArrayOutputStream out, String name,
String content) throws
IOException {
//out.write(new String("--"+BOUNDARY+"\r\n").getBytes());
out.write(new String("Content-Disposition: form-data; name=\"myprovafile\"; filename=\"" + name + "\"").
getBytes());
out.write("\r\nContent-Type: text/xml\r\n".getBytes());
out.write(new String("\r\n"+content).getBytes());
out.write(new String("\r\n--" + BOUNDARY + "--\r\n").getBytes());
}
private static String encode(String value) {
if (value == null || value.trim().length() == 0)return value;
StringBuffer newValue = new StringBuffer(value.length());
char[] chars = value.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (chars[i] == '\\') {
newValue.append("\\\\");
if (chars[i] == '\\') {
newValue.append("\\\\");
}
else {
newValue.append(chars[i]);
}
}
}
return newValue.toString();
}
/**
* Metodo aggiunto per nuovi log Governance
**/
public LogInfoFE getLogInfo() throws Exception{
LogInfoFE logInfoFE = new LogInfoFE();
logInfoFE.setLogPath(Resources.getLogPath());
logInfoFE.setProcess(getClass().getName());
return(logInfoFE);
}
/*invio i file o almeno ci provo da FE a BE, nel caso in cui non riesco a mandare i file
vado a salvarli su un file system ritornando con un exception*/
private final java.net.HttpURLConnection getHttpConnection(String
address) throws Exception {
log.write("9999", "INDIRIZZO DELL'OLO DA CHIAMARE : " + address);
System.out.println("URL dell'OLO da chiamare: "+address);
URL wlsUrl = null;
java.net.HttpURLConnection connection = null;
log.write("9999", "address:" + address);
try {
//HTTPS:
if (sslFlag) {
try {
wlsUrl = new URL(new URL(address), address,
new com.ibm.net.ssl.internal.www.protocol.https.
Handler());
}
catch (MalformedURLException ex) {
// C - ERRORE NELLA URL DELL'OLO
//todo
log.write("0081", " " + address);
throw ex;
}
// Caricamento Certificati
if (sslFlag) {
FileInputStream fis = null;
FileInputStream fist = null;
try {
log.write("9999", "Inizio caricamento certificati per SSL");
String keystore = Resources.getKeyStore();
String truststore = Resources.getTrustKeyStore();
String keypwd = Resources.getPrivateKeyAliasPwd();
String IBMJSSEProvider = "IBMJSSE2";
//manager del keystore della Private Key
String alg = KeyManagerFactory.getDefaultAlgorithm();
KeyManagerFactory kmFact = KeyManagerFactory.getInstance(alg,
IBMJSSEProvider); //<-- il provider!
fis = new FileInputStream(keystore);
KeyStore ks = KeyStore.getInstance("jks");
ks.load(fis, null);
fis.close();
kmFact.init(ks, keypwd.toCharArray());
KeyManager[] kms = kmFact.getKeyManagers();
//manager del keystore delle CA
String algt = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmFact = TrustManagerFactory.getInstance(algt,
IBMJSSEProvider); //<-- il provider!
fist = new FileInputStream(truststore);
KeyStore kst = KeyStore.getInstance("jks");
kst.load(fist, null);
fist.close();
tmFact.init(kst);
TrustManager[] tms = tmFact.getTrustManagers();
//creazione del context SSL
SSLContext sslContext;
sslContext = SSLContext.getInstance("SSL_TLS", IBMJSSEProvider);
sslContext.init(kms, tms, null);
//open connection
connection = (com.ibm.net.ssl.internal.www.protocol.https.
HttpsURLConnection) wlsUrl.openConnection();
//set del Socket Factory alla connessione https
SSLSocketFactory factory = sslContext.getSocketFactory();
com.ibm.net.ssl.internal.www.protocol.https.HttpsURLConnection
appoConnection =
(com.ibm.net.ssl.internal.www.protocol.https.HttpsURLConnection)
connection;
// Setto il timeout della connessione
CustomSSLSocketFactory csf = new CustomSSLSocketFactory(factory,
timeout);
appoConnection.setSSLSocketFactory(csf);
appoConnection.setDefaultSSLSocketFactory(csf);
log.write("9999", "Caricamento certificati per SSL completato");
}
catch (IOException ex) {
// C - ERRORE NEL CARICAMENTO DEI CERTIFICATI
//todo
log.write("0082", "");
throw ex;
}
finally {
// C09_2017 RU_517 BEGIN
// Closing when previously closed will have no effect;
if(null != fis) {
try {
fis.close();
} catch (Exception e) {
fis = null;
System.out.println("FAIL release stream: ["+e.getClass().getName()+"] - " + e.getMessage());
}
}
if(null != fist) {
try {
fist.close();
} catch (Exception e) {
fist = null;
System.out.println("FAIL release stream: ["+e.getClass().getName()+"] - " + e.getMessage());
}
}
// C09_2017 RU_517 END
}
}
}
//HTTP:
else {
try {
wlsUrl = new URL(address);
}
catch (MalformedURLException ex) {
// C - ERRORE NELLA URL DELL'OLO
log.write("0081", " " + address);
throw ex;
}
log.write("9999", "wlsUrl " + wlsUrl);
int timeout = Resources.getHttpTimeOut();
if (httpsFlag) {
System.setProperty("java.protocol.handler.pkgs", "weblogic.net");
connection = new weblogic.net.http.HttpsURLConnection(wlsUrl);
}
else {
connection = new weblogic.net.http.HttpURLConnection(wlsUrl);
}
( (weblogic.net.http.HttpURLConnection) connection).setTimeout(timeout);
connection.connect();
}
// Set request method
connection.setRequestMethod("POST");
// Apertura canali e scrittura file
connection.setDoOutput(true);
connection.setDoInput(true);
return connection;
}
catch (Exception ex) {
ex.printStackTrace();
throw ex;
}
}
private String createAddresWithParameter(String addr, String olo, String tipoFile, String fileName) {
StringBuffer buffer = new StringBuffer(addr + "?");
buffer.append(ApplicationCostants.REQUEST_OLO_MITTENTE).append("=").append(olo).append("&");
buffer.append(ApplicationCostants.REQUEST_TIPO_FILE).append("=").append(tipoFile).append("&");
buffer.append(ApplicationCostants.REQUEST_FILE_NAME).append("=").append(fileName);
return buffer.toString();
}
}
//
// /**
// * Effettua l'invio del file verso un olo utilizzando le stesse modalità di DBC
// * @param: filexml il contenuto del file dainviare
// * @param: tipofile la tipologia di file da inviare (N,R)
// * @param: filename nome del file da inviare
// * @param: codOlo codice OLo donating destinatario del file
// */
// public static final void sendFileAsParameter(String filexml,
// String tipofile,
// String filename,
// String codOlo) throws
// Exception {
// String response = null;
//
// System.out.println("Sending: " + filename + " to FE....");
//
// // CODIFICA: (1° step): Sostituzione caratteri non ammessi con XML
// filexml = XmlUtility.xmlString(filexml);
// String test = "\n******* CODIFICA: (1° step:XML)\nfilexml=" + filexml +
// "&filename=" + filename + "&tipofile=" + tipofile +
// "&codOlo=" + codOlo;
//
// // CODIFICA: (2° step): Codifica per HTML
// filexml = URLEncoder.encode(filexml, "UTF-8");
// test = "\n******* CODIFICA: (2° step:HTTP)\nfilexml=" + filexml +
// "&filename=" + filename + "&tipofile=" + tipofile + "&codOlo=" +
// codOlo;
//
// String query = "filexml=" + filexml + "&filename=" + filename +
// "&tipofile=" + tipofile + "&codOlo=" + codOlo;
//
// OutputStreamWriter wout = null;
//
// System.out.println("Sending: " + filename +
// " to FE... DONE, with response: " + response);
//
// weblogic.net.http.HttpURLConnection connection = null;
//
// try {
// connection = getHttpConnection();
// connection.connect();
// wout = new OutputStreamWriter(connection.getOutputStream());
// //wout.write(query);
// wout.flush();
// response = connection.getResponseMessage();
// }
// catch (java.io.InterruptedIOException tex) {
// // TimeOut nella connessione BE - FE
// throw new InterruptedIOException(
// "Timeout nella connessione con il Front-end");
// }
// catch (IOException ex) {
// int responseCode = connection.getResponseCode();
// if (responseCode == java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT) {
// // TimeOut nella connessione FE - AOM
// throw new InterruptedIOException(
// "Timeout nella connessione fra Front-End e AOM");
// }
// else {
// throw ex;
// }
// }
// finally {
// connection.disconnect();
// }
// if (response == null || !response.equalsIgnoreCase("OK")) {
// throw new Exception("Bad Response");
// }
// wout.close();
//
// }
//
//
// protected static final weblogic.net.http.HttpURLConnection
// getHttpConnection() throws Exception {
//
//
// weblogic.net.http.HttpURLConnection connection = null;
//
// if (httpsFlag) {
// System.setProperty("java.protocol.handler.pkgs", "weblogic.net");
// connection = new weblogic.net.http.HttpsURLConnection(sendServ);
// }
// else {
// connection = new weblogic.net.http.HttpURLConnection(sendServ);
// }
//
// // Caricamento Certificati
// if (httpsFlag && sslFlag) {
// try {
// KeyStore ks = KeyStore.getInstance("jks");
// ks.load(new FileInputStream(Resources.getKeyStore()), null);
// PrivateKey key = (PrivateKey) ks.getKey(Resources.
// getPrivateKeyAlias(),
// Resources.getPrivateKeyAliasPwd().
// toCharArray());
// Certificate[] certChain = ks.getCertificateChain(Resources.
// getPrivateKeyAlias());
// ( (weblogic.net.http.HttpsURLConnection) connection).
// loadLocalIdentity(certChain, key);
// System.out.println("Caricamento certificati per SSL completato");
// }
// catch (IOException ex) {
// System.out.println("ERRORE caricamento certificati per SSL");
// throw ex;
// }
// }
//
// //set timeout
// connection.setTimeout(timeout);
//
// // Set request method
// connection.setRequestMethod("POST");
// //connection.setRequestProperty("content", "xml");
//
// // Apertura canali e scrittura file
// connection.setDoOutput(true);
// connection.setDoInput(true);
// try {
//
// connection.connect();
// }
// catch (java.io.InterruptedIOException tex) {
// // TimeOut nella connessione BE - FE
// throw new InterruptedIOException(
// "Timeout nella connessione con il Front-end");
// }
// catch (IOException ex) {
// int responseCode = connection.getResponseCode();
// if (responseCode ==
// java.net.HttpURLConnection.HTTP_CLIENT_TIMEOUT) {
// // TimeOut nella connessione FE - AOM
// throw new InterruptedIOException(
// "Timeout nella connessione fra Front-End e AOM");
// }
// else {
// throw ex;
// }
// }

View File

@@ -0,0 +1,505 @@
package mnp.utility;
import java.io.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import it.valueteam.securityutility.*;
/**
* Title: MNP Project
* Des cription: Mobile Number Portability
* Copyright: Copyright (c) 2002
* Company: Siemens
* @author Gian Luca Paloni
* @version 1.0 (Modifica File di Properties 28/08/2002)
* @version 2.0 (11/11/2002): Aggiunte proprietà: CCRM_NOTIF_VALID_PREFIX_OUT, PATH_CCRM_OUT
*/
public class Resources {
private static Properties props = null;
private static String propertiesPath = null;
private static String hName=null;
private static String hIP=null;
static{
init();
}
private Resources() {
}
private static void init(){
Properties appProps = new Properties();
FileInputStream fInput = null;
try {
if (System.getProperty("mnpgw_path_properties") != null)
propertiesPath=System.getProperty("mnpgw_path_properties");
else
propertiesPath= System.getProperty("mnp_path_properties");
System.out.println("Path delle Properties ottenuto: "+propertiesPath);
fInput = new FileInputStream(propertiesPath);
appProps.load(fInput);
//decifro gli eventuali valore cifrati
try {
props = CryptoUtility.getInstance().getCleanProperties(appProps);
}
catch (Exception ex1) {
System.out.println("ERRORE nella creazione del properties crifrato");
ex1.printStackTrace();
fInput = new FileInputStream(propertiesPath);
props=new Properties();
props.load(fInput);
}
}
catch (Exception ex) {
System.out.println("ERRORE nella creazione del properties");
}
finally {
if (fInput!=null)
try {
fInput.close();
}
catch (IOException ex1) {
//niente da fare
}
}
}
/**
* Sezione certificati e SSL
* */
public static String getKeyFile()
{
if (props==null)
init();
String ret = Trim(props.getProperty("SSL_KEY_FILE"));
return ret;
}
public static String getCertFile()
{
if (props==null)
init();
String ret = Trim(props.getProperty("SSL_CERT_FILE"));
return ret;
}
public static String getCaCertFile()
{
if (props==null)
init();
String ret = Trim(props.getProperty("SSL_CACERT_FILE"));
return ret;
}
public static String getKeyStore()
{
if (props==null)
init();
String ret = Trim(props.getProperty("SSL_KEYSTORE"));
return ret;
}
public static String getTrustKeyStore()
{
if (props==null)
init();
String ret = Trim(props.getProperty("SSL_TRUSTKEYSTORE"));
return ret;
}
public static String getPrivateKeyAlias()
{
if (props==null)
init();
String ret = Trim(props.getProperty("SSL_PRIVATEKEY_ALIAS"));
return ret;
}
public static String getPrivateKeyAliasPwd()
{
if (props==null)
init();
String ret = Trim(props.getProperty("{3DES}SSL_PRIVATEKEY_ALIAS_PWD"));
return ret;
}
/*
* CARLO 03-02-2003
* aggiunto metodo Trim(String) richiemato da tutti i metodi
* Se null->null altrimenti trimmo
* */
private static final String Trim(String valore){
if (valore!=null)
return valore.trim();
else return null;
}
//
public static String getHOSTPROXY()
{
if (props==null)
init();
String ret = Trim(props.getProperty("HOSTPROXY"));
return ret;
}
public static String getPORTPROXY()
{
if (props==null)
init();
String ret = Trim(props.getProperty("PORTPROXY"));
return ret;
}
public static boolean withProxy()
{
if(props == null)
init();
String hasProxy = Trim(props.getProperty("EnableProxy"));
if ( hasProxy==null || hasProxy.equalsIgnoreCase("yes"))
return true;
else return false;
}
public static boolean withSSL()
{
if(props == null)
init();
String hasSSL = Trim(props.getProperty("EnableSSL"));
if ( hasSSL==null || hasSSL.equalsIgnoreCase("yes") )
return true;
else return false;
}
public static boolean getInternalHttpsFlag()
{
if(props == null)
init();
String s = Trim(props.getProperty("INTERNAL_HTTPS_FLAG"));
if (s!=null && s.equalsIgnoreCase("true"))
return true;
else
return false;
}
public static boolean getInternalSslFlag()
{
if(props == null)
init();
String s = Trim(props.getProperty("INTERNAL_SSL_FLAG"));
if (s!=null && s.equalsIgnoreCase("true"))
return true;
else
return false;
}
public static boolean getInternalProxyFlag()
{
if(props == null)
init();
String s = Trim(props.getProperty("INTERNAL_PROXY_FLAG"));
if (s!=null && s.equalsIgnoreCase("true"))
return true;
else
return false;
}
public static boolean getExternalHttpsFlag()
{
if(props == null)
init();
String s = Trim(props.getProperty("EXTERNAL_HTTPS_FLAG"));
if (s!=null && s.equalsIgnoreCase("true"))
return true;
else
return false;
}
public static boolean getExternalSslFlag()
{
if(props == null)
init();
String s = Trim(props.getProperty("EXTERNAL_SSL_FLAG"));
if (s!=null && s.equalsIgnoreCase("true"))
return true;
else
return false;
}
public static boolean getExternalProxyFlag()
{
if(props == null)
init();
String s = Trim(props.getProperty("EXTERNAL_PROXY_FLAG"));
if (s!=null && s.equalsIgnoreCase("true"))
return true;
else
return false;
}
/**
* Prende dal file di properties il path
* del server dove salvare i file perchè non riesce a inviare
* ossia il path assoluto.
* Francesca 11/03/2003
*/
public static String getPathFileRinvio(){
String sPathFileRinvio = null;
if(props == null)
init();
sPathFileRinvio = Trim(props.getProperty("path_file_rinvio"));
return sPathFileRinvio;
}
/**
* Prende dal file di properties il path
* del server dove salvare i file perchè non riesce a inviare
* ossia il path assoluto.
* Francesca 11/03/2003
*/
public static String getPathFileRinvioWarning(){
String sPathFileRinvioW = null;
if(props == null)
init();
sPathFileRinvioW = Trim(props.getProperty("path_file_rinvio_warning"));
return sPathFileRinvioW;
}
/**
* Prende dal file di properties il path
* del destinatario per inviare i file
* Francesca 14/03/2003
*/
public static String getInternalReceiverURL(){
String sPathDest = null;
if(props == null)
init();
sPathDest = Trim(props.getProperty("InternalReceiverURL"));
return sPathDest;
}
public static String getTestMode(){
String testMode = null;
if(props == null)
init();
testMode = Trim(props.getProperty("test"));
return testMode;
}
public static String getTestURL(){
String testURL = null;
if(props == null)
init();
testURL = Trim(props.getProperty("testURL"));
return testURL;
}
public static String getOloURL(String codOlo){
String sPathOlo = null;
if(props == null)
init();
sPathOlo = Trim(props.getProperty(codOlo.toLowerCase()));
return sPathOlo;
}
/**
* Prende dal file di properties il path
* del file XML che contiene i log
* Ambra 12/08/2003
*/
public static String getPathFileXMLLOG(){
String pathFileXMLLOG = null;
if(props == null)
init();
pathFileXMLLOG = Trim(props.getProperty("path_file_XMLLOG"));
return pathFileXMLLOG;
}
/**
* Restituisce la stringa di info sul file di log in base al tipo di processo
* @return Stringa path del log
* Stefano
*/
public static String getLogPath(){
String logPath = null;
if(props == null)
init();
logPath = Trim(props.getProperty("LOG_PATH"));
return logPath;
}
public static int getHttpTimeOut() throws Exception{
if( props == null )
init();
String app = Trim(props.getProperty("HTTP_TIMEOUT"));
int ret = 0;
try {
ret = Integer.parseInt(app);
//trasformo il dato in millesecondi
ret = ret * 60000;
}
catch(Exception ex) {
System.out.println("Proprieta' HTTP_TIMEOUT non presente");
throw ex;
}
return ret;
}
//log sicurezza
/**
*
* @return String : il percorso del file XML contenente le operazioni e gli esiti
*/
public static String getXMLSecurityLogPathFile() {
if (props == null)
init();
return Trim(props.getProperty("XML_SECURITY_LOG_PATH"));
}
/**
* @return la directory nella quale scrivere il log di sicurezza
*/
public static String getTRACCIAMENTO_DIR() {
if (props == null)
init();
return Trim(props.getProperty("tracciamento.dir"));
}
/**
* @return il nome del file di log sicurezza
*/
public static String getTRACCIAMENTO_FILENAME() {
if (props == null)
init();
return Trim(props.getProperty("tracciamento.filename"));
}
/**
* @return il pattern da utilizzare per il log di sicurezza
*/
public static String getTRACCIAMENTO_PATTERN() {
if (props == null)
init();
return Trim(props.getProperty("tracciamento.pattern"));
}
/**
* getLOGGER_LEVEL_AND_APPENDER_NAME
*/
public static String getLOGGER_LEVEL_AND_APPENDER_NAME() {
if (props == null)
init();
return Trim(props.getProperty("log4j.logger.org.apache"));
}
/**
* Log4j base properties
*/
public static String getAPPENDER() {
if (props == null)
init();
return Trim(props.getProperty("log4j.appender.stdout"));
}
public static String getLAYOUT() {
if (props == null)
init();
return Trim(props.getProperty("log4j.appender.stdout.layout"));
}
public static String getCONVERSION_PATTERN() {
if (props == null)
init();
return Trim(props.getProperty("log4j.appender.stdout.layout.ConversionPattern"));
}
/**
* context factory x wls
* @return String
*/
public static String getFEWLServerContextFactory() {
if (props == null)
init();
String ret = Trim(props.getProperty("FE.WLSERVER.CONTEXT.FACTORY"));
return ret;
}
/**
* url di connessione a dbc
* @return String
*/
public static String getFEWLServerUrl() {
if (props == null)
init();
String ret = Trim(props.getProperty("FE.WLSERVER.URL"));
return ret;
}
/**
* username x utente
* @return String
*/
public static String getFEWLServerUser() {
if (props == null)
init();
String ret = Trim(props.getProperty("FE.WLSERVER.USER"));
return ret;
}
/**
* Password dell'utente
* @return String
*/
public static String getFEWLServerPwd() {
if (props == null)
init();
String ret = Trim(props.getProperty("{3DES}FE.WLSERVER.USER.PWD"));
return ret;
}
/**
* JNDI NAME del servizio su FE
* @return String
*/
public static String getFEPROXYJndiName() {
if (props == null)
init();
String ret = Trim(props.getProperty("FE.FEPROXY.JNDI_NAME"));
return ret;
}
public static String getHostName() throws UnknownHostException{
if(hName == null)
hName=InetAddress.getLocalHost().getHostName();
return hName;
}
public static String getHostAddress() throws UnknownHostException{
if(hIP == null)
hIP=InetAddress.getLocalHost().getHostAddress();
return hIP;
}
}

View File

@@ -0,0 +1,74 @@
package mnp.utility;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Hashtable;
import mnp.xml.logsicurezza.*;
import org.exolab.castor.xml.*;
public class SecurityLogLoader {
private Hashtable mappaAzione,mappaRetCode;
public SecurityLogLoader() throws Exception {
// C09_2017 RU_517 line 21 (Unreleased Resource: Streams)
FileReader frd = null;
try {
mappaAzione= new Hashtable();
mappaRetCode=new Hashtable();
String nomeFile = Resources.getXMLSecurityLogPathFile();
frd = new FileReader(nomeFile);
LISTA_LOG_SICUREZZA logList = (LISTA_LOG_SICUREZZA) Unmarshaller.
unmarshal(LISTA_LOG_SICUREZZA.class, frd);
LOG_ACTIONItem[] actionItems = ((LOG_ACTION)logList.getLOG_ACTION()).getLOG_ACTIONItem();
LOG_RET_CODEItem[] retCodeItems = ((LOG_RET_CODE)logList.getLOG_RET_CODE()).getLOG_RET_CODEItem();
for (int i = 0; i < actionItems.length; i++) {
mappaAzione.put(new Integer( ((LOG_ACTION_ITEM)actionItems[i].getLOG_ACTION_ITEM()).getCODICE_LOG()),
((LOG_ACTION_ITEM)actionItems[i].getLOG_ACTION_ITEM()).getDESCRIZIONE_LOG()
);
}
for (int i = 0; i < retCodeItems.length; i++) {
mappaRetCode.put( new Integer( ((LOG_RET_CODE_ITEM)retCodeItems[i].getLOG_RET_CODE_ITEM()).getVALORE()),
((LOG_RET_CODE_ITEM)retCodeItems[i].getLOG_RET_CODE_ITEM()).getDESCRIZIONE()
);
}
}
catch (IOException ex) {
System.out.println(
"Errore in lettura del file XML relativo alle Azioni del log di sicurezza");
throw ex;
}
catch (ValidationException ex) {
System.out.println("Errore di validazione");
throw ex;
}
catch (MarshalException ex) {
System.out.println("Errore marshall");
throw ex;
}
// C09_2017 RU_517 BEGIN
// Closing when previously closed will have no effect;
finally {
if(null != frd) {
try {
frd.close();
} catch (Exception e) {
frd = null;
System.out.println("FAIL release stream: ["+e.getClass().getName()+"] - " + e.getMessage());
}
}
}
// C09_2017 RU_517 END
}
public Hashtable getActionMap() {
return mappaAzione;
}
public Hashtable getRetCodeMap() {
return mappaRetCode;
}
}