This commit is contained in:
Lucio Lelii 2016-10-03 13:58:14 +00:00
parent fb3f20124f
commit a8d2daf9f1
2 changed files with 34 additions and 7 deletions

View File

@ -193,11 +193,10 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
StringBuilder callUrl;
callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath);
if (context!=null) callUrl.append("?context=").append(context);
callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath).append("?context=").append(context);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "PUT", true);
HttpURLConnection connection = makeRequest(url, "PUT", false);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "application/xml");
@ -224,7 +223,36 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
@Override
public String requestActivation(ContainerInfo container) throws Exception {
return requestActivation(container, null);
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);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "application/xml");
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
Binder.getContext().createMarshaller().marshal(container, os);
}
log.debug("response code is "+connection.getResponseCode());
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
String token= "";
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){
StringBuilder result = new StringBuilder();
String line;
while((line = reader.readLine()) != null)
result.append(line);
token = result.toString();
}
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
}
@Override

View File

@ -80,8 +80,7 @@ public class CallTest {
}
public String _requestNodeToken() throws Exception {
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devNext/NextNext"));
String token = authorizationService().requestActivation(new ContainerInfo("mynode",8080));
String token = authorizationService().requestActivation(new ContainerInfo("mynode",8080), "/gcube/devSec");
return token;
}