diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultGroupManager.java b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultGroupManager.java index 6adddba..55c3b5e 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultGroupManager.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultGroupManager.java @@ -41,7 +41,7 @@ private final ProxyDelegate delegate; if (response.hasException()) throw response.getException(); else if (response.getHTTPCode()==403) - throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user"); + throw new UserNotAuthorizedException("the call to this method is not allowed for the user"); else throw new BackendGenericError(); } @@ -73,7 +73,7 @@ private final ProxyDelegate delegate; if (response.hasException()) throw response.getException(); else if (response.getHTTPCode()==403) - throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user"); + throw new UserNotAuthorizedException("the call to this method is not allowed for the user"); else throw new BackendGenericError(); } @@ -105,7 +105,7 @@ private final ProxyDelegate delegate; if (response.hasException()) throw response.getException(); else if (response.getHTTPCode()==403) - throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user"); + throw new UserNotAuthorizedException("the call to this method is not allowed for the user"); else throw new BackendGenericError(); } @@ -137,7 +137,7 @@ private final ProxyDelegate delegate; if (response.hasException()) throw response.getException(); else if (response.getHTTPCode()==403) - throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user"); + throw new UserNotAuthorizedException("the call to this method is not allowed for the user"); else throw new BackendGenericError(); } @@ -177,7 +177,7 @@ private final ProxyDelegate delegate; if (response.hasException()) throw response.getException(); else if (response.getHTTPCode()==403) - throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user"); + throw new UserNotAuthorizedException("the call to this method is not allowed for the user"); else throw new BackendGenericError(); } diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultUserManager.java b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultUserManager.java index d98294e..8441c12 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultUserManager.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/DefaultUserManager.java @@ -13,11 +13,12 @@ import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest; import org.gcube.common.gxrest.response.inbound.GXInboundResponse; import org.gcube.common.storagehub.model.exceptions.BackendGenericError; import org.gcube.common.storagehub.model.exceptions.StorageHubException; +import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException; public class DefaultUserManager implements UserManagerClient { private final ProxyDelegate delegate; - + public DefaultUserManager(ProxyDelegate delegate) { this.delegate = delegate; } @@ -32,16 +33,19 @@ public class DefaultUserManager implements UserManagerClient { MultivaluedMap formData = new MultivaluedHashMap(); formData.add("user", userId); formData.add("password", userId+"pwd"); - + GXInboundResponse response = myManager.post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED)); if (response.isErrorResponse()) { if (response.hasException()) throw response.getException(); - else + else if (response.getHTTPCode()==403) + throw new UserNotAuthorizedException("the call to this method is not allowed for the user"); + else throw new BackendGenericError(); } + return null; } }; @@ -62,13 +66,21 @@ public class DefaultUserManager implements UserManagerClient { public Void call(GXWebTargetAdapterRequest manager) throws Exception { GXWebTargetAdapterRequest myManager = manager; - GXInboundResponse response = myManager.path(userId).delete(); - - if (response.isErrorResponse()) { - if (response.hasException()) - throw response.getException(); - else - throw new BackendGenericError(); + try { + + GXInboundResponse response = myManager.path(userId).delete(); + + if (response.isErrorResponse()) { + if (response.hasException()) + throw response.getException(); + else if (response.getHTTPCode()==403) + throw new UserNotAuthorizedException("the call to this method is not allowed for the user"); + else + throw new BackendGenericError(); + } + }catch (Exception e) { + e.printStackTrace(); + throw e; } return null; @@ -92,14 +104,17 @@ public class DefaultUserManager implements UserManagerClient { GXWebTargetAdapterRequest myManager = manager; GXInboundResponse response = myManager.get(); - + if (response.isErrorResponse()) { if (response.hasException()) throw response.getException(); - else + else if (response.getHTTPCode()==403) + throw new UserNotAuthorizedException("the call to this method is not allowed for the user"); + else throw new BackendGenericError(); } + return response.getSource().readEntity(List.class); } }; @@ -112,5 +127,5 @@ public class DefaultUserManager implements UserManagerClient { throw new RuntimeException(e1); } } - + } diff --git a/src/test/java/org/gcube/data/access/fs/Items.java b/src/test/java/org/gcube/data/access/fs/Items.java index 30fde10..116f10e 100644 --- a/src/test/java/org/gcube/data/access/fs/Items.java +++ b/src/test/java/org/gcube/data/access/fs/Items.java @@ -52,6 +52,14 @@ public class Items { } + @Test + public void creteAndREmoveUser() throws StorageHubException { + StorageHubClient shc = new StorageHubClient(); + shc.createUserAccount("giorgino"); + shc.deleteUserAccount("giorgino"); + + + } @Test public void removeUserFromVRE() throws StorageHubException {