User and Group management method upgrade

This commit is contained in:
lucio 2020-01-22 16:59:54 +01:00
parent 9de1e4ad59
commit b56206b1e4
3 changed files with 41 additions and 18 deletions

View File

@ -41,7 +41,7 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else if (response.getHTTPCode()==403) 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 else
throw new BackendGenericError(); throw new BackendGenericError();
} }
@ -73,7 +73,7 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else if (response.getHTTPCode()==403) 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 else
throw new BackendGenericError(); throw new BackendGenericError();
} }
@ -105,7 +105,7 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else if (response.getHTTPCode()==403) 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 else
throw new BackendGenericError(); throw new BackendGenericError();
} }
@ -137,7 +137,7 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else if (response.getHTTPCode()==403) 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 else
throw new BackendGenericError(); throw new BackendGenericError();
} }
@ -177,7 +177,7 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else if (response.getHTTPCode()==403) 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 else
throw new BackendGenericError(); throw new BackendGenericError();
} }

View File

@ -13,6 +13,7 @@ import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
import org.gcube.common.gxrest.response.inbound.GXInboundResponse; import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
import org.gcube.common.storagehub.model.exceptions.BackendGenericError; import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
import org.gcube.common.storagehub.model.exceptions.StorageHubException; import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
public class DefaultUserManager implements UserManagerClient { public class DefaultUserManager implements UserManagerClient {
@ -38,10 +39,13 @@ public class DefaultUserManager implements UserManagerClient {
if (response.isErrorResponse()) { if (response.isErrorResponse()) {
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else if (response.getHTTPCode()==403)
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
else else
throw new BackendGenericError(); throw new BackendGenericError();
} }
return null; return null;
} }
}; };
@ -62,13 +66,21 @@ public class DefaultUserManager implements UserManagerClient {
public Void call(GXWebTargetAdapterRequest manager) throws Exception { public Void call(GXWebTargetAdapterRequest manager) throws Exception {
GXWebTargetAdapterRequest myManager = manager; GXWebTargetAdapterRequest myManager = manager;
GXInboundResponse response = myManager.path(userId).delete(); try {
if (response.isErrorResponse()) { GXInboundResponse response = myManager.path(userId).delete();
if (response.hasException())
throw response.getException(); if (response.isErrorResponse()) {
else if (response.hasException())
throw new BackendGenericError(); 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; return null;
@ -96,10 +108,13 @@ public class DefaultUserManager implements UserManagerClient {
if (response.isErrorResponse()) { if (response.isErrorResponse()) {
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else if (response.getHTTPCode()==403)
throw new UserNotAuthorizedException("the call to this method is not allowed for the user");
else else
throw new BackendGenericError(); throw new BackendGenericError();
} }
return response.getSource().readEntity(List.class); return response.getSource().readEntity(List.class);
} }
}; };

View File

@ -52,6 +52,14 @@ public class Items {
} }
@Test
public void creteAndREmoveUser() throws StorageHubException {
StorageHubClient shc = new StorageHubClient();
shc.createUserAccount("giorgino");
shc.deleteUserAccount("giorgino");
}
@Test @Test
public void removeUserFromVRE() throws StorageHubException { public void removeUserFromVRE() throws StorageHubException {