Fixed code to generate DB Key
This commit is contained in:
parent
35e9883a38
commit
c93cd35172
|
@ -1,5 +1,14 @@
|
||||||
package org.gcube.informationsystem.resourceregistry.dbinitialization;
|
package org.gcube.informationsystem.resourceregistry.dbinitialization;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.security.Key;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.gcube.common.encryption.KeyFactory;
|
||||||
|
import org.gcube.common.encryption.KeySerialization;
|
||||||
|
import org.gcube.common.encryption.SymmetricKey;
|
||||||
import org.gcube.informationsystem.base.reference.Element;
|
import org.gcube.informationsystem.base.reference.Element;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||||
|
@ -35,7 +44,7 @@ public class DatabaseEnvironmentTest {
|
||||||
@Test
|
@Test
|
||||||
public void generateDBKey() throws Exception {
|
public void generateDBKey() throws Exception {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
InputStream input = DatabaseEnvironmentTest.class.getClassLoader().getResourceAsStream("config.properties");
|
InputStream input = DatabaseEnvironmentTest.class.getClassLoader().getResourceAsStream("config.properties.prod");
|
||||||
|
|
||||||
// load a properties file
|
// load a properties file
|
||||||
properties.load(input);
|
properties.load(input);
|
||||||
|
@ -44,10 +53,11 @@ public class DatabaseEnvironmentTest {
|
||||||
String keyAlgorithm = properties.getProperty("DB_KEY_ALGORITHM_VARNAME");
|
String keyAlgorithm = properties.getProperty("DB_KEY_ALGORITHM_VARNAME");
|
||||||
|
|
||||||
URL url = SymmetricKey.class.getResource(keyFileName);
|
URL url = SymmetricKey.class.getResource(keyFileName);
|
||||||
|
File keyFile = new File("src/test/resources", keyFileName);
|
||||||
Key key = null;
|
Key key = null;
|
||||||
if(url!=null) {
|
if(url!=null) {
|
||||||
try {
|
try {
|
||||||
key = SymmetricKey.loadKeyFromFile(keyFileName, keyAlgorithm);
|
key = SymmetricKey.loadKeyFromFile(keyFile, keyAlgorithm);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,8 +65,7 @@ public class DatabaseEnvironmentTest {
|
||||||
|
|
||||||
if(key==null){
|
if(key==null){
|
||||||
key = KeyFactory.newAESKey();
|
key = KeyFactory.newAESKey();
|
||||||
File file = new File("src/test/resources", keyFileName);
|
KeySerialization.store(key, keyFile);
|
||||||
KeySerialization.store(key, file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue