user management method added

This commit is contained in:
lucio 2020-01-16 18:11:46 +01:00
parent 9732195398
commit 9de1e4ad59
7 changed files with 109 additions and 37 deletions

View File

@ -3,6 +3,7 @@ package org.gcube.common.storagehub.client.dsl;
import org.gcube.common.storagehub.client.plugins.AbstractPlugin; import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
import org.gcube.common.storagehub.client.proxies.GroupManagerClient; import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient; import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient; import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
import org.gcube.common.storagehub.model.exceptions.StorageHubException; import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.common.storagehub.model.items.Item; import org.gcube.common.storagehub.model.items.Item;
@ -12,6 +13,7 @@ public class StorageHubClient {
private WorkspaceManagerClient wsClient = AbstractPlugin.workspace().build(); private WorkspaceManagerClient wsClient = AbstractPlugin.workspace().build();
private ItemManagerClient itemclient = AbstractPlugin.item().build(); private ItemManagerClient itemclient = AbstractPlugin.item().build();
private GroupManagerClient groupClient = AbstractPlugin.groups().build(); private GroupManagerClient groupClient = AbstractPlugin.groups().build();
private UserManagerClient userClient = AbstractPlugin.users().build();
public FolderContainer getWSRoot(){ public FolderContainer getWSRoot(){
return new FolderContainer(itemclient, wsClient.getWorkspace()); return new FolderContainer(itemclient, wsClient.getWorkspace());
@ -63,4 +65,11 @@ public class StorageHubClient {
return new GenericItemContainer(itemclient, wsClient.restoreFromTrash(itemId)); return new GenericItemContainer(itemclient, wsClient.restoreFromTrash(itemId));
} }
public void createUserAccount(String userId) throws StorageHubException {
userClient.createUser(userId);
}
public void deleteUserAccount(String userId) throws StorageHubException {
userClient.removeUser(userId);
}
} }

View File

@ -4,9 +4,8 @@ import java.util.List;
import org.gcube.common.storagehub.client.proxies.GroupManagerClient; import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient; import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
import org.gcube.common.storagehub.model.Excludes; import org.gcube.common.storagehub.model.acls.AccessType;
import org.gcube.common.storagehub.model.exceptions.StorageHubException; import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.common.storagehub.model.items.Item;
public class VREFolderManager { public class VREFolderManager {
@ -34,9 +33,9 @@ public class VREFolderManager {
return groupClient.getUsersOfGroup(vreTitle); return groupClient.getUsersOfGroup(vreTitle);
} }
private Item getVreFolder() { /*private Item getVreFolder() {
return wsClient.getVreFolder(Excludes.ALL.toArray(new String[0])); return wsClient.getVreFolder(Excludes.ALL.toArray(new String[0]));
} }*/
public void setAdmin(String userId) throws StorageHubException{ public void setAdmin(String userId) throws StorageHubException{
groupClient.addAdmin(vreTitle, userId); groupClient.addAdmin(vreTitle, userId);
@ -49,5 +48,13 @@ public class VREFolderManager {
public List<String> getAdmins() throws StorageHubException{ public List<String> getAdmins() throws StorageHubException{
return groupClient.getAdmins(vreTitle); return groupClient.getAdmins(vreTitle);
} }
public void createVRE(AccessType accessType, String folderOwner) throws StorageHubException{
groupClient.createGroup(vreTitle, accessType, folderOwner);
}
public void removeVRE() throws StorageHubException{
groupClient.removeGroup(vreTitle);
}
} }

View File

@ -14,6 +14,8 @@ import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
import org.gcube.common.storagehub.model.acls.AccessType; import org.gcube.common.storagehub.model.acls.AccessType;
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;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
public class DefaultGroupManager implements GroupManagerClient { public class DefaultGroupManager implements GroupManagerClient {
@ -38,10 +40,13 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
if (response.isErrorResponse()) { if (response.isErrorResponse()) {
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else else if (response.getHTTPCode()==403)
throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
else
throw new BackendGenericError(); throw new BackendGenericError();
} }
return null; return null;
} }
}; };
@ -63,11 +68,13 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
GXWebTargetAdapterRequest myManager = manager; GXWebTargetAdapterRequest myManager = manager;
GXInboundResponse response = myManager.path(groupId).path("users").path(userId).delete(); GXInboundResponse response = myManager.path(groupId).path("users").path(userId).delete();
if (response.isErrorResponse()) { if (response.isErrorResponse()) {
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else else if (response.getHTTPCode()==403)
throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
else
throw new BackendGenericError(); throw new BackendGenericError();
} }
@ -97,10 +104,13 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
if (response.isErrorResponse()) { if (response.isErrorResponse()) {
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else else if (response.getHTTPCode()==403)
throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
else
throw new BackendGenericError(); throw new BackendGenericError();
} }
return response.getSource().readEntity(List.class); return response.getSource().readEntity(List.class);
} }
}; };
@ -126,10 +136,13 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
if (response.isErrorResponse()) { if (response.isErrorResponse()) {
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else else if (response.getHTTPCode()==403)
throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
else
throw new BackendGenericError(); throw new BackendGenericError();
} }
return null; return null;
} }
}; };
@ -146,33 +159,42 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
} }
@Override @Override
public void createGroup(String groupId, AccessType accessType) throws StorageHubException { public void createGroup(String groupId, AccessType accessType, String folderOwner) throws StorageHubException {
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() { Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
@Override @Override
public Void call(GXWebTargetAdapterRequest manager) throws Exception { public Void call(GXWebTargetAdapterRequest manager) throws Exception {
GXWebTargetAdapterRequest myManager = manager; GXWebTargetAdapterRequest myManager = manager;
MultivaluedMap<String, Object> formData = new MultivaluedHashMap<String, Object>(); try (FormDataMultiPart multipart = new FormDataMultiPart()){
formData.add("group", groupId); multipart.field("accessType", accessType, MediaType.APPLICATION_JSON_TYPE);
formData.add("accessType", accessType); multipart.field("group", groupId);
multipart.field("folderOwner", folderOwner);
GXInboundResponse response = myManager.post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
GXInboundResponse response = myManager.post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA_TYPE));
if (response.isErrorResponse()) { if (response.isErrorResponse()) {
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else else if (response.getHTTPCode()==403)
throw new BackendGenericError(); throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
else
throw new BackendGenericError();
}
} }
return null; return null;
} }
}; };
try { try {
delegate.make(call); delegate.make(call);
return; return;
}catch(Exception e) { }catch(StorageHubException e) {
throw new RuntimeException(e); throw e;
}catch(Exception e1) {
throw new RuntimeException(e1);
} }
} }
@ -189,18 +211,23 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
if (response.isErrorResponse()) { if (response.isErrorResponse()) {
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else else if (response.getHTTPCode()==403)
throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
else
throw new BackendGenericError(); throw new BackendGenericError();
} }
return response.getSource().readEntity(List.class); return response.getSource().readEntity(List.class);
} }
}; };
try { try {
List<String> users = delegate.make(call); List<String> users = delegate.make(call);
return users; return users;
}catch(Exception e) { }catch(StorageHubException e) {
throw new RuntimeException(e); throw e;
}catch(Exception e1) {
throw new RuntimeException(e1);
} }
} }
@ -221,18 +248,23 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
if (response.isErrorResponse()) { if (response.isErrorResponse()) {
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else else if (response.getHTTPCode()==403)
throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
else
throw new BackendGenericError(); throw new BackendGenericError();
} }
return null; return null;
} }
}; };
try { try {
delegate.make(call); delegate.make(call);
}catch(Exception e) { }catch(StorageHubException e) {
throw new RuntimeException(e); throw e;
} }catch(Exception e1) {
throw new RuntimeException(e1);
}
} }
@Override @Override
@ -247,10 +279,13 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
if (response.isErrorResponse()) { if (response.isErrorResponse()) {
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else else if (response.getHTTPCode()==403)
throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
else
throw new BackendGenericError(); throw new BackendGenericError();
} }
return null; return null;
} }
}; };
@ -277,10 +312,13 @@ private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
if (response.isErrorResponse()) { if (response.isErrorResponse()) {
if (response.hasException()) if (response.hasException())
throw response.getException(); throw response.getException();
else else if (response.getHTTPCode()==403)
throw new UserNotAuthorizedException("the call to this methdo is not allowed for the user");
else
throw new BackendGenericError(); throw new BackendGenericError();
} }
return response.getSource().readEntity(List.class); return response.getSource().readEntity(List.class);
} }
}; };

View File

@ -23,7 +23,7 @@ public class DefaultUserManager implements UserManagerClient {
} }
@Override @Override
public void addUser(String userId) throws StorageHubException { public void createUser(String userId) throws StorageHubException {
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() { Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
@Override @Override
public Void call(GXWebTargetAdapterRequest manager) throws Exception { public Void call(GXWebTargetAdapterRequest manager) throws Exception {

View File

@ -13,7 +13,7 @@ public interface GroupManagerClient {
void removeGroup(String groupId) throws StorageHubException; void removeGroup(String groupId) throws StorageHubException;
void createGroup(String groupId, AccessType accessType) throws StorageHubException; void createGroup(String groupId, AccessType accessType, String folderOwner) throws StorageHubException;
List<String> getUsersOfGroup(String groupId) throws StorageHubException; List<String> getUsersOfGroup(String groupId) throws StorageHubException;

View File

@ -6,7 +6,7 @@ import org.gcube.common.storagehub.model.exceptions.StorageHubException;
public interface UserManagerClient { public interface UserManagerClient {
void addUser(String userId) throws StorageHubException; void createUser(String userId) throws StorageHubException;
void removeUser(String userId) throws StorageHubException; void removeUser(String userId) throws StorageHubException;

View File

@ -19,6 +19,7 @@ import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.FolderContainer; import org.gcube.common.storagehub.client.dsl.FolderContainer;
import org.gcube.common.storagehub.client.dsl.ItemContainer; import org.gcube.common.storagehub.client.dsl.ItemContainer;
import org.gcube.common.storagehub.client.dsl.StorageHubClient; import org.gcube.common.storagehub.client.dsl.StorageHubClient;
import org.gcube.common.storagehub.client.dsl.VREFolderManager;
import org.gcube.common.storagehub.model.Metadata; import org.gcube.common.storagehub.model.Metadata;
import org.gcube.common.storagehub.model.acls.AccessType; import org.gcube.common.storagehub.model.acls.AccessType;
import org.gcube.common.storagehub.model.exceptions.StorageHubException; import org.gcube.common.storagehub.model.exceptions.StorageHubException;
@ -26,16 +27,32 @@ import org.gcube.common.storagehub.model.items.Item;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import ch.qos.logback.classic.pattern.Util;
public class Items { public class Items {
@BeforeClass @BeforeClass
public static void setUp(){ public static void setUp(){
SecurityTokenProvider.instance.set("d9431600-9fef-41a7-946d-a5b402de30d6-98187548"); SecurityTokenProvider.instance.set("b7c80297-e4ed-42ab-ab42-fdc0b8b0eabf-98187548");
ScopeProvider.instance.set("/gcube/devsec/devVRE"); ScopeProvider.instance.set("/gcube");
} }
@Test
public void allRound() throws StorageHubException {
StorageHubClient shc = new StorageHubClient();
VREFolderManager vreFolderMaanger = shc.getVreFolderManager(org.gcube.common.storagehub.client.dsl.Util.getVREGroupFromContext("/gcube/devsec/devVreLucio"));
vreFolderMaanger.createVRE(AccessType.READ_ONLY, "lucio.lelii");
/*vreFolderMaanger.addUser("lucio.lelii");
vreFolderMaanger.addUser("massimiliano.assante");
vreFolderMaanger.setAdmin("massimiliano.assante");*/
vreFolderMaanger.removeVRE();
}
@Test @Test
public void removeUserFromVRE() throws StorageHubException { public void removeUserFromVRE() throws StorageHubException {
StorageHubClient shc = new StorageHubClient(); StorageHubClient shc = new StorageHubClient();
@ -61,6 +78,7 @@ public class Items {
StorageHubClient shc = new StorageHubClient(); StorageHubClient shc = new StorageHubClient();
shc.getVreFolderManager().removeAdmin("vfloros"); shc.getVreFolderManager().removeAdmin("vfloros");
} }
@Test @Test