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())
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<GXWebTargetAdapterRequest> 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<GXWebTargetAdapterRequest> 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<GXWebTargetAdapterRequest> 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<GXWebTargetAdapterRequest> 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();
}

View File

@ -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<GXWebTargetAdapterRequest> delegate;
public DefaultUserManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
this.delegate = delegate;
}
@ -32,16 +33,19 @@ public class DefaultUserManager implements UserManagerClient {
MultivaluedMap<String, Object> formData = new MultivaluedHashMap<String, Object>();
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);
}
}
}

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
public void removeUserFromVRE() throws StorageHubException {