This commit is contained in:
Lucio Lelii 2016-10-26 07:48:56 +00:00
parent 5ac0bf67d1
commit f4971155f5
4 changed files with 24 additions and 22 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.0.1-SNAPSHOT</version>
<name>authorization service client library</name>
<parent>

View File

@ -1,5 +1,6 @@
package org.gcube.common.authorization.client.proxy;
import java.io.File;
import java.util.List;
import java.util.Map;
@ -39,6 +40,6 @@ public interface AuthorizationProxy {
Map<String, String> retrieveApiKeys() throws Exception;
//File getSymmKey(String filePath) throws Exception;
File getSymmKey(String filePath) throws Exception;
}

View File

@ -4,6 +4,8 @@ import static org.gcube.common.authorization.client.Constants.CONTEXT_PARAM;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
@ -190,11 +192,11 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
String methodPath = "/token/node";
int infrastructureHash = Utils.getInfrastructureHashfromContext(context);
StringBuilder callUrl;
callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath).append("?context=").append(context);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "PUT", false);
connection.setDoOutput(true);
@ -218,7 +220,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
}
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
}
@Override
public String requestActivation(ContainerInfo container) throws Exception {
@ -226,11 +228,11 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
String methodPath = "/token/node";
int infrastructureHash = Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure());
StringBuilder callUrl;
callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "PUT", true);
connection.setDoOutput(true);
@ -340,7 +342,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
}
}
/*
@Override
public File getSymmKey(String filePath) throws Exception{
final String methodPath = "/symmKey/";
@ -351,15 +353,15 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "GET", true);
connection.setDoInput(true);
if (connection.getResponseCode()!=200) throw new Exception("error retrieving policies");
if (connection.getResponseCode()!=200) throw new Exception("error retrieving key");
if (connection.getContentLengthLong()<=0) return null;
String resourceName = (String)connection.getHeaderField("resource-name");
File toReturnFile = new File(filePath+"/"+resourceName);
toReturnFile.createNewFile();
try(InputStream stream = (InputStream)connection.getContent();
OutputStream os = new FileOutputStream(filePath)){
OutputStream os = new FileOutputStream(toReturnFile)){
int read = 0;
byte[] bytes = new byte[1024];
@ -369,8 +371,8 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
}
}
return toReturnFile;
}*/
}
private HttpURLConnection makeRequest(URL url, String method, boolean includeTokenInHeader) throws Exception{
HttpURLConnection connection;

View File

@ -20,7 +20,7 @@ public class CallTest {
@Test
public void resolveNodeToken() throws Exception{
System.out.println(resolveToken("d7a6b96b-97eb-40fd-96ff-c8e5f37a91c7-98187548")); //81caac0f-8a0d-4923-9312-7ff0eb3f2d5e|98187548"));
System.out.println(resolveToken("a7caa51b-6979-4b1d-abc6-449365b8350a-98187548")); //81caac0f-8a0d-4923-9312-7ff0eb3f2d5e|98187548"));
}
@Test
@ -36,7 +36,6 @@ public class CallTest {
authorizationService().addPolicies(policies);
}
@Test
public void getPolicies() throws Exception{
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devNext/NextNext"));
@ -57,12 +56,12 @@ public class CallTest {
public void createKeyWithError() throws Exception {
authorizationService().generateApiKey("TEST");
}
/*
@Test
public void getSymmKey() throws Exception{
SecurityTokenProvider.instance.set(_requestNodeToken());
authorizationService().getSymmKey("/tmp");
}*/
}
@Test
@ -85,13 +84,13 @@ public class CallTest {
public String _requestNodeToken() throws Exception {
SecurityTokenProvider.instance.set(requestTestToken("/gcube"));
String token = authorizationService().requestActivation(new ContainerInfo("mynode",8080), "/gcube/devSec");
String token = authorizationService().requestActivation(new ContainerInfo("dlib29.isti.cnr.it",8080), "/gcube/devsec");
return token;
}
@Test
public void createTestToken() throws Exception {
System.out.println(requestTestToken("/gcube/devNext/NextNext"));
System.out.println(requestTestToken("/gcube/devsec/devVRE"));
}
private String requestTestToken(String context) throws Exception{