git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@115516 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
dace2de108
commit
11ed6e1290
|
@ -46,6 +46,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
String callUrl = endpoint+"/generate/"+userName+"?roles="+rolesQueryString.toString();
|
String callUrl = endpoint+"/generate/"+userName+"?roles="+rolesQueryString.toString();
|
||||||
URL url = new URL(callUrl);
|
URL url = new URL(callUrl);
|
||||||
HttpURLConnection connection = makeRequest(url, "POST");
|
HttpURLConnection connection = makeRequest(url, "POST");
|
||||||
|
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()));){
|
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()));){
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
String line;
|
String line;
|
||||||
|
@ -69,8 +70,10 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
@Override
|
@Override
|
||||||
public AuthorizationEntry call(String endpoint) throws Exception {
|
public AuthorizationEntry call(String endpoint) throws Exception {
|
||||||
|
|
||||||
|
System.out.println("calling get to "+endpoint);
|
||||||
URL url = new URL(endpoint+"/retrieve/"+token);
|
URL url = new URL(endpoint+"/retrieve/"+token);
|
||||||
HttpURLConnection connection = makeRequest(url, "GET");
|
HttpURLConnection connection = makeRequest(url, "GET");
|
||||||
|
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||||
if (connection.getContentLengthLong()<=0) return null;
|
if (connection.getContentLengthLong()<=0) return null;
|
||||||
|
|
||||||
try(InputStream stream = (InputStream)connection.getContent();){
|
try(InputStream stream = (InputStream)connection.getContent();){
|
||||||
|
@ -81,8 +84,8 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (cache.containsKey(token) && cache.get(token).isValid())
|
/*if (cache.containsKey(token) && cache.get(token).isValid())
|
||||||
return cache.get(token).getEntry();
|
return cache.get(token).getEntry();*/
|
||||||
try {
|
try {
|
||||||
return delegate.make(call);
|
return delegate.make(call);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -98,6 +101,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
URL url = new URL(endpoint+"/deny/"+userName+"/"+service.getServiceClass()+"/"+service.getServiceName());
|
URL url = new URL(endpoint+"/deny/"+userName+"/"+service.getServiceClass()+"/"+service.getServiceName());
|
||||||
HttpURLConnection connection = makeRequest(url, "POST");
|
HttpURLConnection connection = makeRequest(url, "POST");
|
||||||
|
|
||||||
|
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||||
if (connection.getContentLengthLong()<=0) return null;
|
if (connection.getContentLengthLong()<=0) return null;
|
||||||
|
|
||||||
try(InputStream stream = (InputStream)connection.getContent();){
|
try(InputStream stream = (InputStream)connection.getContent();){
|
||||||
|
@ -122,7 +126,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
public Empty call(String endpoint) throws Exception {
|
public Empty call(String endpoint) throws Exception {
|
||||||
URL url = new URL(endpoint+"/deny/"+userName+"/"+service.getServiceClass()+"/"+service.getServiceName());
|
URL url = new URL(endpoint+"/deny/"+userName+"/"+service.getServiceClass()+"/"+service.getServiceName());
|
||||||
HttpURLConnection connection = makeRequest(url, "DELETE");
|
HttpURLConnection connection = makeRequest(url, "DELETE");
|
||||||
System.out.println("response status "+connection.getResponseCode());
|
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||||
return new Empty();
|
return new Empty();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -145,6 +149,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
URL url = new URL(endpoint+"/deny/"+userName);
|
URL url = new URL(endpoint+"/deny/"+userName);
|
||||||
|
|
||||||
HttpURLConnection connection = makeRequest(url, "GET");
|
HttpURLConnection connection = makeRequest(url, "GET");
|
||||||
|
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||||
if (connection.getContentLengthLong()<=0) return Collections.emptyList();
|
if (connection.getContentLengthLong()<=0) return Collections.emptyList();
|
||||||
|
|
||||||
try(InputStream stream = (InputStream)connection.getContent();){
|
try(InputStream stream = (InputStream)connection.getContent();){
|
||||||
|
|
|
@ -2,24 +2,20 @@ package org.gcube.common.authorizationservice.cl;
|
||||||
|
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.BannedService;
|
import org.gcube.common.authorization.library.BannedService;
|
||||||
import org.gcube.common.authorization.library.provider.Service;
|
import org.gcube.common.authorization.library.provider.Service;
|
||||||
import org.gcube.common.resources.gcore.GenericResource;
|
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
|
||||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.*;
|
|
||||||
public class CallTest {
|
public class CallTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void call(){
|
public void call(){
|
||||||
ScopeProvider.instance.set("/gcube/devsec");
|
ScopeProvider.instance.set("/gcube/devsec");
|
||||||
|
|
||||||
System.out.println(authorizationService().build().get("d7a4076c-e8c1-42fe-81e0-bdecb1e8074a"));
|
System.out.println(authorizationService().build().get("d7a4076c-e8c1-42fe-81e0-bdecb1e8074a"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue