From 11ed6e12904ae1b27de0b3bd0822ef7b5c96c4ee Mon Sep 17 00:00:00 2001 From: "lucio.lelii" Date: Wed, 24 Jun 2015 15:50:01 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@115516 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/proxy/DefaultAuthorizationProxy.java | 11 ++++++++--- .../common/authorizationservice/cl/CallTest.java | 6 +----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gcube/common/authorization/client/proxy/DefaultAuthorizationProxy.java b/src/main/java/org/gcube/common/authorization/client/proxy/DefaultAuthorizationProxy.java index a5d4ac2..32e8453 100644 --- a/src/main/java/org/gcube/common/authorization/client/proxy/DefaultAuthorizationProxy.java +++ b/src/main/java/org/gcube/common/authorization/client/proxy/DefaultAuthorizationProxy.java @@ -46,6 +46,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy { String callUrl = endpoint+"/generate/"+userName+"?roles="+rolesQueryString.toString(); URL url = new URL(callUrl); 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()));){ StringBuilder result = new StringBuilder(); String line; @@ -69,8 +70,10 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy { @Override public AuthorizationEntry call(String endpoint) throws Exception { + System.out.println("calling get to "+endpoint); URL url = new URL(endpoint+"/retrieve/"+token); HttpURLConnection connection = makeRequest(url, "GET"); + if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service"); if (connection.getContentLengthLong()<=0) return null; try(InputStream stream = (InputStream)connection.getContent();){ @@ -81,8 +84,8 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy { } }; - if (cache.containsKey(token) && cache.get(token).isValid()) - return cache.get(token).getEntry(); + /*if (cache.containsKey(token) && cache.get(token).isValid()) + return cache.get(token).getEntry();*/ try { return delegate.make(call); } catch (Exception e) { @@ -98,6 +101,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy { URL url = new URL(endpoint+"/deny/"+userName+"/"+service.getServiceClass()+"/"+service.getServiceName()); HttpURLConnection connection = makeRequest(url, "POST"); + if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service"); if (connection.getContentLengthLong()<=0) return null; try(InputStream stream = (InputStream)connection.getContent();){ @@ -122,7 +126,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy { public Empty call(String endpoint) throws Exception { URL url = new URL(endpoint+"/deny/"+userName+"/"+service.getServiceClass()+"/"+service.getServiceName()); 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(); } @@ -145,6 +149,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy { URL url = new URL(endpoint+"/deny/"+userName); HttpURLConnection connection = makeRequest(url, "GET"); + if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service"); if (connection.getContentLengthLong()<=0) return Collections.emptyList(); try(InputStream stream = (InputStream)connection.getContent();){ diff --git a/src/test/java/org/gcube/common/authorizationservice/cl/CallTest.java b/src/test/java/org/gcube/common/authorizationservice/cl/CallTest.java index 841875a..32332f6 100644 --- a/src/test/java/org/gcube/common/authorizationservice/cl/CallTest.java +++ b/src/test/java/org/gcube/common/authorizationservice/cl/CallTest.java @@ -2,24 +2,20 @@ package org.gcube.common.authorizationservice.cl; import static org.gcube.common.authorization.client.Constants.authorizationService; +import java.io.IOException; import java.util.Arrays; import java.util.List; import org.gcube.common.authorization.library.BannedService; 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.resources.discovery.client.api.DiscoveryClient; -import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.junit.Test; -import static org.gcube.resources.discovery.icclient.ICFactory.*; public class CallTest { @Test public void call(){ ScopeProvider.instance.set("/gcube/devsec"); - System.out.println(authorizationService().build().get("d7a4076c-e8c1-42fe-81e0-bdecb1e8074a")); }