git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/common-encryption@130698 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b501a005a8
commit
4880954689
38
.classpath
38
.classpath
|
@ -1,10 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
#Tue Mar 06 09:17:02 EST 2012
|
||||
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.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
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.source=1.6
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
|
|
26
pom.xml
26
pom.xml
|
@ -16,21 +16,37 @@
|
|||
<developerConnection>scm:svn:https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/common-utils-encryption</developerConnection>
|
||||
<url>http://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/common-utils-encryption</url>
|
||||
</scm>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-bom</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<properties>
|
||||
<distroDirectory>distro</distroDirectory>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-authorization</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -8,9 +8,14 @@ import java.security.Key;
|
|||
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
import org.gcube.common.scope.impl.ScopeBean.Type;
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.impl.ContextBean;
|
||||
import org.gcube.common.scope.impl.ContextBean.Type;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
//import org.apache.xml.security.utils.JavaUtils;
|
||||
|
||||
|
||||
|
@ -50,7 +55,15 @@ final class SymmetricKey {
|
|||
* @throws InvalidKeyException if the key is not available or is invalid
|
||||
*/
|
||||
private static void load() throws InvalidKeyException {
|
||||
load(getKeyFileName(ScopeProvider.instance.get()));
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
AuthorizationEntry entry;
|
||||
try {
|
||||
entry = authorizationService().get(token);
|
||||
load(getKeyFileName(entry.getContext()));
|
||||
} catch (Exception e) {
|
||||
throw new InvalidKeyException("Unable to load the Key, token not valid",e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,7 +102,7 @@ final class SymmetricKey {
|
|||
protected static String getKeyFileName(String context) throws InvalidKeyException{
|
||||
String keyFile=null;
|
||||
if(context!=null){
|
||||
ScopeBean bean = new ScopeBean(context);
|
||||
ContextBean bean = new ContextBean(context);
|
||||
if(bean.is(Type.VRE))
|
||||
bean = bean.enclosingScope();
|
||||
String name = bean.name();
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package org.gcube.common.encryption;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.security.InvalidKeyException;
|
||||
|
||||
import org.gcube.common.encryption.SymmetricKey;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LocalKeyTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
ScopeProvider.instance.set("/gcube/devsec");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws InvalidKeyException {
|
||||
String key=SymmetricKey.getKeyFileName(ScopeProvider.instance.get());
|
||||
System.out.println("file key founded: "+key);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,9 @@
|
|||
package org.gcube.common.encryption;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.gcube.common.encryption.StringEncrypter;
|
||||
import org.gcube.common.encryption.SymmetricKey;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StringEncrypterTest {
|
||||
|
||||
|
@ -18,7 +14,6 @@ public class StringEncrypterTest {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
ScopeProvider.instance.set("/gcube/devsec");
|
||||
key = SymmetricKey.getKey();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
package org.gcube.common.encryption;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.Key;
|
||||
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
//import org.apache.xml.security.utils.JavaUtils;
|
||||
import org.gcube.common.encryption.SymmetricKey;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
//import org.apache.xml.security.utils.JavaUtils;
|
||||
|
||||
public class SymmetricKeyTest {
|
||||
|
||||
|
@ -22,7 +17,7 @@ public class SymmetricKeyTest {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
ScopeProvider.instance.set("/gcube/devsec");
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -42,33 +37,33 @@ public class SymmetricKeyTest {
|
|||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public final void testGetKeyOld() throws InvalidKeyException{
|
||||
// String keyAlgorithm = "AES";
|
||||
// String localKey = "/symm.key";
|
||||
// byte[] rawKey;
|
||||
// try {
|
||||
// rawKey = JavaUtils.getBytesFromStream(SymmetricKey.class.getResourceAsStream(localKey));
|
||||
// } catch (Exception e) {
|
||||
// System.out.println("Unable to load the Key from the classpath");
|
||||
// e.printStackTrace();
|
||||
// throw new InvalidKeyException();
|
||||
// }
|
||||
// try {
|
||||
// key2 = new SecretKeySpec(rawKey, 0, rawKey.length, keyAlgorithm);
|
||||
// }catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// throw new InvalidKeyException();
|
||||
// }
|
||||
// System.out.println("key successfully loaded");
|
||||
// System.out.println("key " + key2.getEncoded());
|
||||
// System.out.println("key algorithm " + key2.getAlgorithm());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public final void compare(){
|
||||
// assertEquals(key1, key2);
|
||||
// }
|
||||
// @Test
|
||||
// public final void testGetKeyOld() throws InvalidKeyException{
|
||||
// String keyAlgorithm = "AES";
|
||||
// String localKey = "/symm.key";
|
||||
// byte[] rawKey;
|
||||
// try {
|
||||
// rawKey = JavaUtils.getBytesFromStream(SymmetricKey.class.getResourceAsStream(localKey));
|
||||
// } catch (Exception e) {
|
||||
// System.out.println("Unable to load the Key from the classpath");
|
||||
// e.printStackTrace();
|
||||
// throw new InvalidKeyException();
|
||||
// }
|
||||
// try {
|
||||
// key2 = new SecretKeySpec(rawKey, 0, rawKey.length, keyAlgorithm);
|
||||
// }catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// throw new InvalidKeyException();
|
||||
// }
|
||||
// System.out.println("key successfully loaded");
|
||||
// System.out.println("key " + key2.getEncoded());
|
||||
// System.out.println("key algorithm " + key2.getAlgorithm());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public final void compare(){
|
||||
// assertEquals(key1, key2);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue