git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@131990 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c3e5848be2
commit
44968e867a
|
@ -15,6 +15,8 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
|
||||||
import org.gcube.common.authorization.client.Binder;
|
import org.gcube.common.authorization.client.Binder;
|
||||||
import org.gcube.common.authorization.client.Constants;
|
import org.gcube.common.authorization.client.Constants;
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
|
@ -46,8 +48,9 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getInternalEnpoint(int infrastructureHash){
|
private String getInternalEnpoint(int infrastructureHash){
|
||||||
StringBuilder endpoint = new StringBuilder("http://").append(getEndpoint(infrastructureHash).getHost()).append(":")
|
AuthorizationEndpoint ae = getEndpoint(infrastructureHash);
|
||||||
.append(getEndpoint(infrastructureHash).getPort()).append("/authorization-service/gcube/service");
|
StringBuilder endpoint = new StringBuilder(ae.isSecureConnection()?"https://":"http://").append(ae.getHost()).append(":")
|
||||||
|
.append(ae.getPort()).append("/authorization-service/gcube/service");
|
||||||
return endpoint.toString();
|
return endpoint.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +137,8 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
URL url = new URL(callUrl.toString());
|
URL url = new URL(callUrl.toString());
|
||||||
HttpURLConnection connection = makeRequest(url, "PUT", true);
|
HttpURLConnection connection = makeRequest(url, "PUT", true);
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setFixedLengthStreamingMode(0);
|
||||||
connection.setRequestProperty("Content-type", "application/xml");
|
connection.setRequestProperty("Content-type", "application/xml");
|
||||||
|
|
||||||
|
|
||||||
|
@ -235,6 +240,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
URL url = new URL(callUrl.toString());
|
URL url = new URL(callUrl.toString());
|
||||||
HttpURLConnection connection = makeRequest(url, "GET", false);
|
HttpURLConnection connection = makeRequest(url, "GET", false);
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
|
|
||||||
if (connection.getResponseCode()==404) throw new ObjectNotFound("token "+maskedToken+" not found");
|
if (connection.getResponseCode()==404) throw new ObjectNotFound("token "+maskedToken+" not found");
|
||||||
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service (error code is "+connection.getResponseCode()+")");
|
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service (error code is "+connection.getResponseCode()+")");
|
||||||
if (connection.getContentLengthLong()<=0) return null;
|
if (connection.getContentLengthLong()<=0) return null;
|
||||||
|
@ -299,7 +305,11 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
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)url.openConnection();
|
HttpURLConnection connection;
|
||||||
|
if (url.toString().startsWith("https://"))
|
||||||
|
connection = (HttpsURLConnection)url.openConnection();
|
||||||
|
else connection = (HttpURLConnection)url.openConnection();
|
||||||
|
|
||||||
if (includeTokenInHeader){
|
if (includeTokenInHeader){
|
||||||
if (SecurityTokenProvider.instance.get()==null) throw new RuntimeException("null token passed");
|
if (SecurityTokenProvider.instance.get()==null) throw new RuntimeException("null token passed");
|
||||||
connection.setRequestProperty(Constants.TOKEN_HEADER_ENTRY,Utils.getRealToken(SecurityTokenProvider.instance.get()));
|
connection.setRequestProperty(Constants.TOKEN_HEADER_ENTRY,Utils.getRealToken(SecurityTokenProvider.instance.get()));
|
||||||
|
|
Loading…
Reference in New Issue