First Commit - Source Code from Reply
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
@@ -0,0 +1,9 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="dbcm-core">
|
||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
||||
</wb-module>
|
||||
</project-modules>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<installed facet="java" version="1.6"/>
|
||||
<installed facet="jst.utility" version="1.0"/>
|
||||
</faceted-project>
|
||||
@@ -0,0 +1,2 @@
|
||||
disabled=06target
|
||||
eclipse.preferences.version=1
|
||||
@@ -0,0 +1,25 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>dbcm-core</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>dbcm</groupId>
|
||||
<artifactId>dbcm</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.6</maven.compiler.source>
|
||||
<maven.compiler.target>1.6</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,10 @@
|
||||
package dbcm.exception;
|
||||
|
||||
public class BadRequestException extends Exception{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public BadRequestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dbcm.exception;
|
||||
|
||||
public class NoResultException extends Exception{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public NoResultException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dbcm.exception;
|
||||
|
||||
public class TooManyResultException extends Exception{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public TooManyResultException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TooManyResultException(String pattern, int resultNum, int maxNum) {
|
||||
super("Per il pattern "+pattern +" sono stati restituiti "+ resultNum +" valori, ma"
|
||||
+ " ne sono consentiti al massimo "+maxNum);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
package dbcm.utilities;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.security.Key;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.SecretKeyFactory;
|
||||
import javax.crypto.spec.DESedeKeySpec;
|
||||
|
||||
import sun.misc.BASE64Decoder;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class CryptoUtility {
|
||||
public static final String TRIPLE_DES_CHIPER = "DESede/ECB/PKCS5Padding";
|
||||
public static final String TRIPLE_DES_PREFIX = "{3DES}";
|
||||
public static final String TRIPLE_DES_KEY = "DESede";
|
||||
public static final int TRIPLE_DES_KEY_SIZE = 168;
|
||||
public static final String KEY_MISSING = "Symmetric Key Missing";
|
||||
|
||||
public static final String MEMORY_ADDRESS = "INDIRIZZO_KEY";
|
||||
public static final String FLAG_SHARED_KEY = "USE_CRYPTO_SHARED";
|
||||
public static final String FILE_KEY = "PATH_KEY";
|
||||
public static final String INDIRIZZO_DINAMICO = "USE_DYNAMIC_ADDRESS";
|
||||
public static final int INDIRIZZO_STATICO = 5625;
|
||||
|
||||
private Key chiave3DES = null;
|
||||
private static CryptoUtility onlyInstance = null;
|
||||
|
||||
/**
|
||||
* Costruttore
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private CryptoUtility() throws Exception {
|
||||
String fileChiave = null;
|
||||
int indirizzo;
|
||||
|
||||
String confFile = System.getProperty("security_conf_file");
|
||||
IniFile iniFile = new IniFile(confFile);
|
||||
Properties p = iniFile.getSection("main.properties");
|
||||
|
||||
if ("true".equalsIgnoreCase(p.getProperty(FLAG_SHARED_KEY))) {
|
||||
indirizzo = "true".equalsIgnoreCase(p.getProperty(INDIRIZZO_DINAMICO)) ? Integer.parseInt(p.getProperty(MEMORY_ADDRESS)) : INDIRIZZO_STATICO;
|
||||
try {
|
||||
readKey(indirizzo);
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Impossibile caricare la chiave dalla ram: verificare che la chiave sia presente.");
|
||||
throw new Exception("Impossibile caricare la chiave dalla ram.");
|
||||
}
|
||||
} else {
|
||||
fileChiave = (String) p.get(FILE_KEY);
|
||||
loadKey(fileChiave);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utilizzato da applicazioni che inizializzano esplicitamente l'api di
|
||||
* cifratura con init(). Il Properties � letto autonomamente prima dell'init.
|
||||
*
|
||||
* @param config Le properties contenute nel file security.properties.
|
||||
* @throws Exception
|
||||
*/
|
||||
private CryptoUtility(Properties config) throws Exception {
|
||||
String fileChiave = null;
|
||||
int indirizzo;
|
||||
|
||||
if ("true".equalsIgnoreCase(config.getProperty(FLAG_SHARED_KEY))) {
|
||||
indirizzo = "true".equalsIgnoreCase(config.getProperty(INDIRIZZO_DINAMICO)) ? Integer.parseInt(config.getProperty(MEMORY_ADDRESS)) : INDIRIZZO_STATICO;
|
||||
try {
|
||||
readKey(indirizzo);
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Impossibile caricare la chiave dalla ram: verificare che la chiave sia presente.");
|
||||
throw new Exception("Impossibile caricare la chiave dalla ram.");
|
||||
}
|
||||
} else {
|
||||
fileChiave = (String) config.get(FILE_KEY);
|
||||
loadKey(fileChiave);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inizializzazione del framework di security
|
||||
*
|
||||
* @param fileChiave String
|
||||
* @throws Exception
|
||||
* @return CryptoUtility
|
||||
*/
|
||||
public static CryptoUtility getInstance() throws Exception {
|
||||
if (onlyInstance == null) {
|
||||
synchronized (CryptoUtility.class) {
|
||||
if (onlyInstance == null) {
|
||||
onlyInstance = new CryptoUtility();
|
||||
}
|
||||
}
|
||||
}
|
||||
return onlyInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utilizzato per inizializzare la classe prima delle operazioni di cifratura.
|
||||
*
|
||||
* @param secConfig Le properties del file security.properties
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void init(Properties secConfig) throws Exception {
|
||||
onlyInstance = new CryptoUtility(secConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* carica la chiave simmetrica di cifratura/decifratura
|
||||
*
|
||||
* @param fileChiave String
|
||||
* @throws Exception
|
||||
*/
|
||||
private void loadKey(String fileChiave) throws Exception {
|
||||
ObjectInputStream in = null;
|
||||
|
||||
try {
|
||||
in = new ObjectInputStream(new FileInputStream(fileChiave));
|
||||
chiave3DES = (Key) in.readObject();
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Legge la chiave (raw byte) dalla shared memory attraverso il bridge JNI
|
||||
*
|
||||
* @param indirizzo L'indirizzo della chiave nella memoria
|
||||
* @throws Exception
|
||||
*/
|
||||
private void readKey(int indirizzo) throws Exception {
|
||||
DESedeKeySpec spec = null;
|
||||
KeyJNIBridge bridge = new KeyJNIBridge();
|
||||
spec = new DESedeKeySpec(bridge.readKey(indirizzo));
|
||||
chiave3DES = SecretKeyFactory.getInstance(CryptoUtility.TRIPLE_DES_KEY).generateSecret(spec);
|
||||
}
|
||||
|
||||
/**
|
||||
* funzione di criptazione
|
||||
*
|
||||
* @param value String
|
||||
* @throws Exception
|
||||
* @return String
|
||||
*/
|
||||
public String cripta3DES(String value) throws Exception {
|
||||
byte[] res = null;
|
||||
Cipher cipher = Cipher.getInstance(TRIPLE_DES_CHIPER);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, chiave3DES);
|
||||
byte[] val = value.getBytes();
|
||||
res = new byte[cipher.getOutputSize(val.length)];
|
||||
int size = cipher.update(val, 0, val.length, res, 0);
|
||||
size += cipher.doFinal(res, size);
|
||||
return toString(res, res.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* funzione di decriptazione
|
||||
*
|
||||
* @param value String
|
||||
* @throws Exception
|
||||
* @return String
|
||||
*/
|
||||
public String decripta3DES(String value) throws Exception {
|
||||
Cipher cipher = Cipher.getInstance(TRIPLE_DES_CHIPER);
|
||||
cipher.init(Cipher.DECRYPT_MODE, chiave3DES);
|
||||
return new String(cipher.doFinal(toByteArray(value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* funzione di decriptazione che automaticamte elimina il prefisso 3DES
|
||||
*
|
||||
* @param value String
|
||||
* @throws Exception
|
||||
* @return String
|
||||
*/
|
||||
public String decripta3DESWithPrefix(String value) throws Exception {
|
||||
return decripta3DES(value.substring(TRIPLE_DES_PREFIX.length()));
|
||||
}
|
||||
|
||||
private static final String toString(byte[] bytes, int length) {
|
||||
BASE64Encoder encoder = new BASE64Encoder();
|
||||
String base64 = encoder.encode(bytes);
|
||||
return base64;
|
||||
}
|
||||
|
||||
private static final byte[] toByteArray(String string) throws Exception {
|
||||
BASE64Decoder decoder = new BASE64Decoder();
|
||||
byte[] raw = decoder.decodeBuffer(string);
|
||||
return raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* decripta un inputstream ritornandone un inputstream uno con tutte le key in
|
||||
* chiaro
|
||||
*
|
||||
* @param filename String
|
||||
* @throws Exception
|
||||
* @return InputStream
|
||||
*/
|
||||
public InputStream getCleanFile(InputStream in) throws Exception {
|
||||
ByteArrayInputStream bin = null;
|
||||
String read = null;
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(in));
|
||||
String key = null;
|
||||
String value = null;
|
||||
String cleanValue = null;
|
||||
StringBuffer stringOutput = new StringBuffer();
|
||||
byte[] b = null;
|
||||
int idx = -1;
|
||||
while ((read = input.readLine()) != null) {
|
||||
if ((read.startsWith(";") || read.startsWith("#")))
|
||||
stringOutput.append(read + "\n");
|
||||
else {
|
||||
idx = read.indexOf("=");
|
||||
if (idx == -1)
|
||||
stringOutput.append(read + "\n");
|
||||
else {
|
||||
cleanValue = "";
|
||||
key = read.substring(0, idx);
|
||||
if (idx < read.length())
|
||||
value = read.substring(idx + 1, read.length());
|
||||
else
|
||||
value = "";
|
||||
cleanValue = value;
|
||||
if ((key.startsWith(TRIPLE_DES_PREFIX)) && value != null && value.length() > 0) {
|
||||
try {
|
||||
if (value.startsWith(TRIPLE_DES_PREFIX)) {
|
||||
cleanValue = decripta3DES(value.substring(TRIPLE_DES_PREFIX.length()));
|
||||
// System.out.println("decripta3DES:" + key);
|
||||
}
|
||||
// else
|
||||
// System.out.println("NOT decripta3DES:" + key);
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Errore durante il decript della chiave:" + key);
|
||||
ex.printStackTrace();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
stringOutput.append(key + "=" + cleanValue + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
b = stringOutput.toString().getBytes();
|
||||
bin = new ByteArrayInputStream(b);
|
||||
return bin;
|
||||
}
|
||||
|
||||
/**
|
||||
* decripta un properties ritornandone uno con tutte le key in chiaro
|
||||
*
|
||||
* @param inProperties Properties
|
||||
* @throws Exception
|
||||
* @return Properties
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Properties getCleanProperties(Properties inProperties) throws Exception {
|
||||
String key = null;
|
||||
String value = null;
|
||||
String cleanValue = null;
|
||||
Properties outProperties = new Properties();
|
||||
|
||||
if ((inProperties != null) && (inProperties.size() != 0)) {
|
||||
Enumeration e = inProperties.keys();
|
||||
|
||||
while (e.hasMoreElements()) {
|
||||
key = (String) e.nextElement();
|
||||
value = (String) inProperties.get(key);
|
||||
cleanValue = value;
|
||||
if ((key.startsWith(TRIPLE_DES_PREFIX)) && value != null && value.length() > 0) {
|
||||
try {
|
||||
if (value.startsWith(TRIPLE_DES_PREFIX)) {
|
||||
cleanValue = decripta3DES(value.substring(TRIPLE_DES_PREFIX.length()));
|
||||
// System.out.println("decripta3DES:"+key);
|
||||
}
|
||||
// else
|
||||
// System.out.println("NOT decripta3DES:"+key);
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Errore durante il decript della chiave:" + key);
|
||||
ex.printStackTrace();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
outProperties.put(key, cleanValue);
|
||||
}
|
||||
}
|
||||
return outProperties;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package dbcm.utilities;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
public class DateUtils {
|
||||
public static final String FORMAT_YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
||||
public static final String FORMAT_YYYYMMDDHHMMSS000 = "yyyyMMddHHmmssSSS";
|
||||
public static final String FORMAT_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||
public static final String FORMAT_YYYY_MM_DD_SEP = "yyyy-MM-dd";
|
||||
public static final String FORMAT_YYYY_MM_DD = "yyyyMMdd";
|
||||
public static final String FORMAT_DD_MM_YYYY = "dd-MM-yyyy";
|
||||
|
||||
public static Date getToday() {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
public static Date getYesterday() {
|
||||
Calendar gc = new GregorianCalendar();
|
||||
gc.add(Calendar.DAY_OF_MONTH, -1);
|
||||
return gc.getTime();
|
||||
}
|
||||
|
||||
public static String toString(Date date, String format) {
|
||||
return new SimpleDateFormat(format).format(date);
|
||||
}
|
||||
|
||||
public static Date fromString(String dateString, String format) throws ParseException {
|
||||
return new SimpleDateFormat(format).parse(dateString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package dbcm.utilities;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
public class FileUitls {
|
||||
|
||||
public void copyFile(File in, File out) throws Exception {
|
||||
|
||||
FileInputStream fis = new FileInputStream(in);
|
||||
FileOutputStream fos = new FileOutputStream(out);
|
||||
byte[] buf = new byte[1024];
|
||||
int i = 0;
|
||||
while ((i = fis.read(buf)) != -1) {
|
||||
fos.write(buf, 0, i);
|
||||
}
|
||||
fis.close();
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
package dbcm.utilities;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
public class IniFile {
|
||||
private Properties sections;
|
||||
|
||||
/**
|
||||
* Constructor for the IniFile object
|
||||
*/
|
||||
public IniFile() {
|
||||
sections = new Properties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the IniFile object
|
||||
*
|
||||
* @param filename Description of Parameter
|
||||
* @exception FileNotFoundException Description of Exception
|
||||
*/
|
||||
public IniFile(String filename) throws FileNotFoundException {
|
||||
this();
|
||||
load(filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the IniFile object
|
||||
*
|
||||
* @param url Description of Parameter
|
||||
* @exception IOException Description of Exception
|
||||
*/
|
||||
public IniFile(URL url) throws IOException {
|
||||
this();
|
||||
load(url.openStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for the IniFile object
|
||||
*
|
||||
* @param input Description of Parameter
|
||||
* @exception IOException Description of Exception
|
||||
*/
|
||||
public IniFile(InputStream input) throws IOException {
|
||||
this();
|
||||
load(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the KeyValue attribute of the IniFile object
|
||||
*
|
||||
* @param section The new KeyValue value
|
||||
* @param key The new KeyValue value
|
||||
* @param value The new KeyValue value
|
||||
*/
|
||||
public void setKeyValue(String section, String key, String value) {
|
||||
try {
|
||||
getSection(section).put(key, value);
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Sections attribute of the IniFile object
|
||||
*
|
||||
* @return The Sections value
|
||||
*/
|
||||
public Properties getSections() {
|
||||
return sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Section attribute of the IniFile object
|
||||
*
|
||||
* @param section Description of Parameter
|
||||
* @return The Section value
|
||||
*/
|
||||
public Properties getSection(String section) {
|
||||
return (Properties) (sections.get(section));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the NullOrEmpty attribute of the IniFile object
|
||||
*
|
||||
* @param section Description of Parameter
|
||||
* @param key Description of Parameter
|
||||
* @return The NullOrEmpty value
|
||||
*/
|
||||
public boolean isNullOrEmpty(String section, String key) {
|
||||
String value = getKeyValue(section, key);
|
||||
return (value == null || value.length() == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the KeyValue attribute of the IniFile object
|
||||
*
|
||||
* @param section Description of Parameter
|
||||
* @param key Description of Parameter
|
||||
* @return The KeyValue value
|
||||
*/
|
||||
public String getKeyValue(String section, String key) {
|
||||
try {
|
||||
return (String) getSection(section).get(key);
|
||||
} catch (NullPointerException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the KeyIntValue attribute of the IniFile object
|
||||
*
|
||||
* @param section Description of Parameter
|
||||
* @param key Description of Parameter
|
||||
* @return The KeyIntValue value
|
||||
*/
|
||||
public int getKeyIntValue(String section, String key) {
|
||||
return getKeyIntValue(section, key, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the KeyIntValue attribute of the IniFile object
|
||||
*
|
||||
* @param section Description of Parameter
|
||||
* @param key Description of Parameter
|
||||
* @param defaultValue Description of Parameter
|
||||
* @return The KeyIntValue value
|
||||
*/
|
||||
public int getKeyIntValue(String section, String key, int defaultValue) {
|
||||
String value = getKeyValue(section, key);
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
try {
|
||||
return Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the KeysAndValues attribute of the IniFile object
|
||||
*
|
||||
* @param aSection Description of Parameter
|
||||
* @return The KeysAndValues value
|
||||
*/
|
||||
public String[][] getKeysAndValues(String aSection) {
|
||||
Properties section = getSection(aSection);
|
||||
if (section == null) {
|
||||
return null;
|
||||
}
|
||||
String[][] results = new String[section.size()][2];
|
||||
int i = 0;
|
||||
for (Enumeration<?> f = section.keys(), g = section.elements(); f.hasMoreElements(); i++) {
|
||||
results[i][0] = (String) f.nextElement();
|
||||
results[i][1] = (String) g.nextElement();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
* @param filename Description of Parameter
|
||||
* @exception FileNotFoundException Description of Exception
|
||||
*/
|
||||
public void load(String filename) throws FileNotFoundException {
|
||||
load(new FileInputStream(filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
* @param filename Description of Parameter
|
||||
* @exception IOException Description of Exception
|
||||
*/
|
||||
public void save(String filename) throws IOException {
|
||||
save(new FileOutputStream(filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
* @param in Description of Parameter
|
||||
*/
|
||||
public void load(InputStream in) {
|
||||
try {
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(in));
|
||||
String read;
|
||||
Properties section = null;
|
||||
String section_name;
|
||||
while ((read = input.readLine()) != null) {
|
||||
if (read.startsWith(";") || read.startsWith("#")) {
|
||||
continue;
|
||||
} else if (read.startsWith("[")) {
|
||||
// new section
|
||||
section_name = read.substring(1, read.indexOf("]"));
|
||||
section = (Properties) sections.get(section_name);
|
||||
if (section == null) {
|
||||
section = new Properties();
|
||||
sections.put(section_name, section);
|
||||
}
|
||||
} else if (read.indexOf("=") != -1 && section != null) {
|
||||
// new key
|
||||
String key = read.substring(0, read.indexOf("=")).trim();
|
||||
String value = read.substring(read.indexOf("=") + 1).trim();
|
||||
section.put(key, value);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
* @param out Description of Parameter
|
||||
*/
|
||||
public void save(OutputStream out) {
|
||||
try {
|
||||
PrintWriter output = new PrintWriter(out);
|
||||
String section;
|
||||
for (Enumeration<?> e = sections.keys(); e.hasMoreElements();) {
|
||||
section = (String) e.nextElement();
|
||||
output.println("[" + section + "]");
|
||||
for (Enumeration<?> f = getSection(section).keys(), g = getSection(section).elements(); f.hasMoreElements();) {
|
||||
output.println(f.nextElement() + "=" + g.nextElement());
|
||||
}
|
||||
}
|
||||
output.flush();
|
||||
output.close();
|
||||
out.flush();
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a feature to the Section attribute of the IniFile object
|
||||
*
|
||||
* @param section The feature to be added to the Section attribute
|
||||
*/
|
||||
public void addSection(String section) {
|
||||
sections.put(section, new Properties());
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*
|
||||
* @param section Description of Parameter
|
||||
*/
|
||||
public void removeSection(String section) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple test function
|
||||
*
|
||||
* @param args The command line arguments
|
||||
* @exception Exception Description of Exception
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
(new IniFile()).load(new FileInputStream(args[0]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dbcm.utilities;
|
||||
|
||||
public class KeyJNIBridge {
|
||||
static {
|
||||
System.loadLibrary("SecUtility");
|
||||
}
|
||||
|
||||
public KeyJNIBridge() {
|
||||
}
|
||||
|
||||
public native void writeKey(int indirizzo, byte[] chiaveInChiaro);
|
||||
|
||||
public native byte[] readKey(int indirizzo);
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
package dbcm.utilities;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class Resources {
|
||||
private static Logger logger = Logger.getLogger(Resources.class.getName());
|
||||
|
||||
private static Properties props = null;
|
||||
private static String propertiesPath = null;
|
||||
|
||||
static {
|
||||
init();
|
||||
}
|
||||
|
||||
private static void init() {
|
||||
if (props == null) {
|
||||
Properties appProps = new Properties();
|
||||
try {
|
||||
//propertiesPath = "C:\\dbcm\\properties\\resources.properties";
|
||||
propertiesPath = System.getProperty("mnp_path_properties", "");
|
||||
System.out.println("Path delle Properties ottenuto: " + propertiesPath);
|
||||
appProps.load(new FileInputStream(propertiesPath));
|
||||
// decifro gli eventuali valore cifrati
|
||||
try {
|
||||
props = CryptoUtility.getInstance().getCleanProperties(appProps);
|
||||
} catch (Exception ex1) {
|
||||
logger.error("init() - ERRORE nella creazione del properties crifrato: " + ex1.getMessage());
|
||||
props = new Properties();
|
||||
props.load(new FileInputStream(propertiesPath));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.error("init() - ERRORE nella creazione del properties crifrato: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Properties getLog4jProperties() {
|
||||
init();
|
||||
Properties p = new Properties();
|
||||
Enumeration<?> e = props.propertyNames();
|
||||
while (e.hasMoreElements()) {
|
||||
String s = (String) e.nextElement();
|
||||
if (s.startsWith("log4j")) {
|
||||
p.put(s, props.getProperty(s));
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public static String getDBCM_WS_ENABLED() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_WS_ENABLED"));
|
||||
}
|
||||
|
||||
public static String getDBCM_SCHEDULER_ENABLED() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_SCHEDULER_ENABLED"));
|
||||
}
|
||||
|
||||
public static String getDBCM_SCHEDULER_INTERVAL() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_SCHEDULER_INTERVAL"));
|
||||
}
|
||||
|
||||
public static String getDBCM_SCHEDULER_GFP_ENABLED() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_SCHEDULER_GFP_ENABLED"));
|
||||
}
|
||||
|
||||
public static String getDBCM_SCHEDULER_GFP_HH() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_SCHEDULER_GFP_HH"));
|
||||
}
|
||||
|
||||
public static String getDBCM_SCHEDULER_GFP_MM() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_SCHEDULER_GFP_MM"));
|
||||
}
|
||||
|
||||
public static String getDBCM_PATH_FILE_IN() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_PATH_FILE_IN"));
|
||||
}
|
||||
|
||||
public static String getDBCM_LOG4J_FILE() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_LOG4J_FILE"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_LOCAL_FILE_PATH() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_LOCAL_FILE_PATH"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_LOCAL_BACKUP_PATH() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_LOCAL_BACKUP_PATH"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_OCS_REMOTE_PATH() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_OCS_REMOTE_PATH"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_OPSC_REMOTE_PATH() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_OPSC_REMOTE_PATH"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_OCS1_FILE_NAME() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_OCS1_FILE_NAME"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_OCS2_FILE_NAME() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_OCS2_FILE_NAME"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_OCS3_FILE_NAME() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_OCS3_FILE_NAME"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_OCS4_FILE_NAME() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_OCS4_FILE_NAME"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_OPSC1_FILE_NAME() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_OPSC1_FILE_NAME"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_OPSC2_FILE_NAME() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_OPSC2_FILE_NAME"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_OPSC3_FILE_NAME() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_OPSC3_FILE_NAME"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_OPSC4_FILE_NAME() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_OPSC4_FILE_NAME"));
|
||||
}
|
||||
|
||||
public static String getDBCM_GFP_FILE_EXT() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_GFP_FILE_EXT"));
|
||||
}
|
||||
|
||||
public static Boolean getDBCM_STRICT_HOST_KEY_CHECKING_GFP() {
|
||||
init();
|
||||
String ret = StringUtils.trim(props.getProperty("DBCM_STRICT_HOST_KEY_CHECKING_GFP"));
|
||||
return "YES".equalsIgnoreCase(ret) ? true : false;
|
||||
}
|
||||
|
||||
public static String getDBCM_USER_GFP() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_USER_GFP"));
|
||||
}
|
||||
|
||||
public static String getDBCM_HOST_GFP() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("DBCM_HOST_GFP"));
|
||||
}
|
||||
|
||||
public static int getDBCM_TIMEOUT_GFP() {
|
||||
init();
|
||||
String ret = StringUtils.trim(props.getProperty("DBCM_TIMEOUT_GFP"));
|
||||
return Integer.parseInt(ret);
|
||||
}
|
||||
|
||||
public static String getSFTP_PRIVATEKEY_PATH() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("SFTP_PRIVATEKEY_PATH"));
|
||||
}
|
||||
|
||||
public static String getSFTP_PRIVATEKEY_PASSPHRASE() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("{3DES}SFTP_PRIVATEKEY_PASSPHRASE"));
|
||||
}
|
||||
|
||||
public static String getSFTP_KNOWNHOSTS() {
|
||||
init();
|
||||
return StringUtils.trim(props.getProperty("SFTP_KNOWN_HOSTS"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package dbcm.utilities;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
|
||||
public class StringUtils {
|
||||
public static boolean isEmpty(String string) {
|
||||
return string == null || "".equals(string);
|
||||
}
|
||||
|
||||
public static String fromObject(Class<?> clazz, Object obj) throws JAXBException {
|
||||
StringWriter sw = new StringWriter();
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(clazz);
|
||||
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
|
||||
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
|
||||
jaxbMarshaller.marshal(obj, sw);
|
||||
return sw.toString();
|
||||
}
|
||||
|
||||
public static String trim(String string) {
|
||||
return (string != null ? string.trim() : null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package dbcm.utilities;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class ZipUtils {
|
||||
public static boolean unzip(File gzipfile) {
|
||||
boolean result = true;
|
||||
try {
|
||||
byte[] buffer = new byte[1024];
|
||||
String zippedFileName = gzipfile.getAbsolutePath();
|
||||
String unzippedFileName = zippedFileName;
|
||||
if (zippedFileName.endsWith(".gzip")) {
|
||||
unzippedFileName = unzippedFileName.substring(0, unzippedFileName.length() - 5);
|
||||
} else if (zippedFileName.endsWith(".gz")) {
|
||||
unzippedFileName = unzippedFileName.substring(0, unzippedFileName.length() - 3);
|
||||
}
|
||||
GZIPInputStream gZIPInputStream = new GZIPInputStream(new FileInputStream(gzipfile));
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(unzippedFileName);
|
||||
int bytes_read;
|
||||
while ((bytes_read = gZIPInputStream.read(buffer)) > 0) {
|
||||
fileOutputStream.write(buffer, 0, bytes_read);
|
||||
}
|
||||
gZIPInputStream.close();
|
||||
fileOutputStream.close();
|
||||
} catch (Exception e) {
|
||||
System.out.println("Exception in unzip "+ e.getMessage());
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Fri Jun 10 14:06:50 CEST 2022
|
||||
version=1.0
|
||||
groupId=dbcm
|
||||
artifactId=dbcm-core
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
dbcm\utilities\StringUtils.class
|
||||
dbcm\utilities\DateUtils.class
|
||||
dbcm\exception\NoResultException.class
|
||||
dbcm\utilities\FileUitls.class
|
||||
dbcm\utilities\Resources.class
|
||||
dbcm\utilities\CryptoUtility.class
|
||||
dbcm\exception\BadRequestException.class
|
||||
dbcm\utilities\KeyJNIBridge.class
|
||||
dbcm\utilities\ZipUtils.class
|
||||
dbcm\exception\TooManyResultException.class
|
||||
dbcm\utilities\IniFile.class
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
C:\dev\TIM\DBCMNP\dbcmnp_workspace\dbcm\dbcm-core\src\main\java\dbcm\exception\BadRequestException.java
|
||||
C:\dev\TIM\DBCMNP\dbcmnp_workspace\dbcm\dbcm-core\src\main\java\dbcm\exception\NoResultException.java
|
||||
C:\dev\TIM\DBCMNP\dbcmnp_workspace\dbcm\dbcm-core\src\main\java\dbcm\utilities\DateUtils.java
|
||||
C:\dev\TIM\DBCMNP\dbcmnp_workspace\dbcm\dbcm-core\src\main\java\dbcm\utilities\CryptoUtility.java
|
||||
C:\dev\TIM\DBCMNP\dbcmnp_workspace\dbcm\dbcm-core\src\main\java\dbcm\utilities\KeyJNIBridge.java
|
||||
C:\dev\TIM\DBCMNP\dbcmnp_workspace\dbcm\dbcm-core\src\main\java\dbcm\utilities\Resources.java
|
||||
C:\dev\TIM\DBCMNP\dbcmnp_workspace\dbcm\dbcm-core\src\main\java\dbcm\utilities\StringUtils.java
|
||||
C:\dev\TIM\DBCMNP\dbcmnp_workspace\dbcm\dbcm-core\src\main\java\dbcm\utilities\FileUitls.java
|
||||
C:\dev\TIM\DBCMNP\dbcmnp_workspace\dbcm\dbcm-core\src\main\java\dbcm\utilities\ZipUtils.java
|
||||
C:\dev\TIM\DBCMNP\dbcmnp_workspace\dbcm\dbcm-core\src\main\java\dbcm\utilities\IniFile.java
|
||||
C:\dev\TIM\DBCMNP\dbcmnp_workspace\dbcm\dbcm-core\src\main\java\dbcm\exception\TooManyResultException.java
|
||||
Reference in New Issue
Block a user