git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@117574 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ed1e6a29b2
commit
5a71b1d0ae
|
@ -0,0 +1,27 @@
|
||||||
|
package org.gcube.common.authorization.client.exceptions;
|
||||||
|
|
||||||
|
public class ObjectNotFound extends Exception {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public ObjectNotFound() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectNotFound(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectNotFound(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectNotFound(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package org.gcube.common.authorization.client.proxy;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||||
import org.gcube.common.authorization.library.BannedService;
|
import org.gcube.common.authorization.library.BannedService;
|
||||||
|
|
||||||
|
@ -9,7 +10,7 @@ public interface AuthorizationProxy {
|
||||||
|
|
||||||
String generate(String userName, List<String> roles);
|
String generate(String userName, List<String> roles);
|
||||||
|
|
||||||
AuthorizationEntry get(String token);
|
AuthorizationEntry get(String token) throws ObjectNotFound;
|
||||||
|
|
||||||
BannedService deny(String userName, String serviceClass, String serviceName);
|
BannedService deny(String userName, String serviceClass, String serviceName);
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.Map;
|
||||||
|
|
||||||
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.library.AuthorizationEntry;
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||||
import org.gcube.common.authorization.library.BannedService;
|
import org.gcube.common.authorization.library.BannedService;
|
||||||
import org.gcube.common.authorization.library.BannedServices;
|
import org.gcube.common.authorization.library.BannedServices;
|
||||||
|
@ -63,7 +64,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthorizationEntry get(final String token) {
|
public AuthorizationEntry get(final String token) throws ObjectNotFound{
|
||||||
Call<String, AuthorizationEntry> call = new Call<String, AuthorizationEntry>() {
|
Call<String, AuthorizationEntry> call = new Call<String, AuthorizationEntry>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,6 +72,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
|
|
||||||
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()==404) throw new ObjectNotFound("token "+token+" not found");
|
||||||
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||||
if (connection.getContentLengthLong()<=0) return null;
|
if (connection.getContentLengthLong()<=0) return null;
|
||||||
|
|
||||||
|
@ -86,6 +88,8 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
return cache.get(token).getEntry();
|
return cache.get(token).getEntry();
|
||||||
try {
|
try {
|
||||||
return delegate.make(call);
|
return delegate.make(call);
|
||||||
|
} catch (ObjectNotFound e) {
|
||||||
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw again(e).asServiceException();
|
throw again(e).asServiceException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import static org.gcube.common.authorization.client.Constants.authorizationServi
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
import org.gcube.common.authorization.library.BannedService;
|
import org.gcube.common.authorization.library.BannedService;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -14,7 +15,11 @@ 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("df75336d-0944-4324-b444-c711d21f705b"));
|
try{
|
||||||
|
System.out.println(authorizationService().build().get("fdsafsafsda"));
|
||||||
|
}catch(ObjectNotFound onf){
|
||||||
|
onf.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue