git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@132250 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e5c5e37594
commit
fb3f20124f
|
@ -35,6 +35,10 @@ public interface AuthorizationProxy {
|
||||||
|
|
||||||
String requestActivation(ContainerInfo container) throws Exception;
|
String requestActivation(ContainerInfo container) throws Exception;
|
||||||
|
|
||||||
public Map<String, String> retrieveApiKeys() throws Exception;
|
String requestActivation(ContainerInfo container, String context) throws Exception;
|
||||||
|
|
||||||
|
Map<String, String> retrieveApiKeys() throws Exception;
|
||||||
|
|
||||||
|
//File getSymmKey(String filePath) throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,18 +184,20 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String requestActivation(ContainerInfo container) throws Exception {
|
public String requestActivation(ContainerInfo container, String context) throws Exception {
|
||||||
|
|
||||||
String methodPath = "/token/node";
|
String methodPath = "/token/node";
|
||||||
|
|
||||||
int infrastructureHash = Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure());
|
int infrastructureHash = Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure());
|
||||||
StringBuilder callUrl =
|
|
||||||
new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath);
|
StringBuilder callUrl;
|
||||||
|
|
||||||
|
callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath);
|
||||||
|
if (context!=null) callUrl.append("?context=").append(context);
|
||||||
|
|
||||||
URL url = new URL(callUrl.toString());
|
URL url = new URL(callUrl.toString());
|
||||||
HttpURLConnection connection = makeRequest(url, "PUT", false);
|
HttpURLConnection connection = makeRequest(url, "PUT", true);
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
connection.setRequestProperty("Content-type", "application/xml");
|
connection.setRequestProperty("Content-type", "application/xml");
|
||||||
|
@ -218,6 +220,13 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
|
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String requestActivation(ContainerInfo container) throws Exception {
|
||||||
|
|
||||||
|
return requestActivation(container, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthorizationEntry get(String token) throws ObjectNotFound, Exception{
|
public AuthorizationEntry get(String token) throws ObjectNotFound, Exception{
|
||||||
String realToken = Utils.getRealToken(token);
|
String realToken = Utils.getRealToken(token);
|
||||||
|
@ -303,6 +312,38 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Override
|
||||||
|
public File getSymmKey(String filePath) throws Exception{
|
||||||
|
final String methodPath = "/symmKey/";
|
||||||
|
|
||||||
|
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure())))
|
||||||
|
.append(methodPath);
|
||||||
|
|
||||||
|
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.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)){
|
||||||
|
|
||||||
|
int read = 0;
|
||||||
|
byte[] bytes = new byte[1024];
|
||||||
|
|
||||||
|
while ((read = stream.read(bytes)) != -1) {
|
||||||
|
os.write(bytes, 0, read);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toReturnFile;
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
private HttpURLConnection makeRequest(URL url, String method, boolean includeTokenInHeader) throws Exception{
|
private HttpURLConnection makeRequest(URL url, String method, boolean includeTokenInHeader) throws Exception{
|
||||||
HttpURLConnection connection;
|
HttpURLConnection connection;
|
||||||
if (url.toString().startsWith("https://"))
|
if (url.toString().startsWith("https://"))
|
||||||
|
|
|
@ -25,9 +25,7 @@ public class CallTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestNodeToken() throws Exception {
|
public void requestNodeToken() throws Exception {
|
||||||
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devNext/NextNext"));
|
System.out.println(_requestNodeToken());
|
||||||
String token = authorizationService().requestActivation(new ContainerInfo("node11.d.d4science.research-infrastructures.eu",8080));
|
|
||||||
System.out.println(token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -55,12 +53,19 @@ public class CallTest {
|
||||||
public void createKeyWithError() throws Exception {
|
public void createKeyWithError() throws Exception {
|
||||||
authorizationService().generateApiKey("TEST");
|
authorizationService().generateApiKey("TEST");
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
@Test
|
||||||
|
public void getSymmKey() throws Exception{
|
||||||
|
SecurityTokenProvider.instance.set(_requestNodeToken());
|
||||||
|
authorizationService().getSymmKey("/tmp");
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createKey() throws Exception {
|
public void createKey() throws Exception {
|
||||||
String token = requestTestToken("/gcube/devNext/NextNext");
|
String token = requestTestToken("/gcube");
|
||||||
SecurityTokenProvider.instance.set(token);
|
SecurityTokenProvider.instance.set(token);
|
||||||
String key = authorizationService().generateApiKey("TEST");
|
String key = authorizationService().generateApiKey("PIPPO");
|
||||||
System.out.println("key : "+key);
|
System.out.println("key : "+key);
|
||||||
System.out.println(resolveToken(key));
|
System.out.println(resolveToken(key));
|
||||||
}
|
}
|
||||||
|
@ -74,6 +79,12 @@ public class CallTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String _requestNodeToken() throws Exception {
|
||||||
|
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devNext/NextNext"));
|
||||||
|
String token = authorizationService().requestActivation(new ContainerInfo("mynode",8080));
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createTestToken() throws Exception {
|
public void createTestToken() throws Exception {
|
||||||
System.out.println(requestTestToken("/gcube/devNext/NextNext"));
|
System.out.println(requestTestToken("/gcube/devNext/NextNext"));
|
||||||
|
|
Loading…
Reference in New Issue