Added client calls for user and group managing
This commit is contained in:
parent
66417126c0
commit
eb8aa51a00
|
@ -1,11 +1,14 @@
|
|||
package org.gcube.common.storagehub.client.plugins;
|
||||
|
||||
import org.gcube.common.authorization.library.policies.Users;
|
||||
import org.gcube.common.clients.Plugin;
|
||||
import org.gcube.common.clients.ProxyBuilder;
|
||||
import org.gcube.common.clients.ProxyBuilderImpl;
|
||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||
import org.gcube.common.storagehub.client.Constants;
|
||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
|
||||
|
||||
|
@ -16,12 +19,22 @@ public abstract class AbstractPlugin<S,P> implements Plugin<S,P> {
|
|||
|
||||
private static final ItemManagerPlugin item_plugin = new ItemManagerPlugin();
|
||||
private static final WorkspaceManagerPlugin workspace_plugin = new WorkspaceManagerPlugin();
|
||||
private static final UserManagerPlugin user_plugin = new UserManagerPlugin();
|
||||
private static final GroupManagerPlugin group_plugin = new GroupManagerPlugin();
|
||||
|
||||
|
||||
public static ProxyBuilder<ItemManagerClient> item() {
|
||||
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,ItemManagerClient>(item_plugin);
|
||||
}
|
||||
|
||||
public static ProxyBuilder<GroupManagerClient> groups() {
|
||||
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,GroupManagerClient>(group_plugin);
|
||||
}
|
||||
|
||||
public static ProxyBuilder<UserManagerClient> users() {
|
||||
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,UserManagerClient>(user_plugin);
|
||||
}
|
||||
|
||||
public static ProxyBuilder<WorkspaceManagerClient> workspace() {
|
||||
return new ProxyBuilderImpl<GXWebTargetAdapterRequest,WorkspaceManagerClient>(workspace_plugin);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package org.gcube.common.storagehub.client.plugins;
|
||||
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.ws.EndpointReference;
|
||||
|
||||
import org.gcube.common.calls.jaxrs.GcubeService;
|
||||
import org.gcube.common.calls.jaxrs.TargetFactory;
|
||||
import org.gcube.common.clients.config.ProxyConfig;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||
import org.gcube.common.gxrest.response.entity.SerializableErrorEntityTextReader;
|
||||
import org.gcube.common.storagehub.client.Constants;
|
||||
import org.gcube.common.storagehub.client.MyInputStreamProvider;
|
||||
import org.gcube.common.storagehub.client.proxies.DefaultGroupManager;
|
||||
import org.gcube.common.storagehub.client.proxies.DefaultUserManager;
|
||||
import org.gcube.common.storagehub.client.proxies.GroupManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class GroupManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest, GroupManagerClient> {
|
||||
|
||||
public GroupManagerPlugin() {
|
||||
super("storagehub/workspace");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Exception convert(Exception e, ProxyConfig<?, ?> arg1) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupManagerClient newProxy(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||
return new DefaultGroupManager(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GXWebTargetAdapterRequest resolve(EndpointReference epr, ProxyConfig<?, ?> config)
|
||||
throws Exception {
|
||||
DOMResult result = new DOMResult();
|
||||
epr.writeTo(result);
|
||||
Node node =result.getNode();
|
||||
Node child=node.getFirstChild();
|
||||
String address = child.getTextContent();
|
||||
//GXWebTargetAdapterRequest request = GXWebTargetAdapterRequest.newRequest(address).path(this.name).path("items");
|
||||
GcubeService service = GcubeService.service().withName(Constants.MANAGER_QNAME).andPath("groups");
|
||||
GXWebTargetAdapterRequest requestAdapter = TargetFactory.stubFor(service).getAsGxRest(address);
|
||||
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
||||
requestAdapter.register(MyInputStreamProvider.class);
|
||||
requestAdapter.register(MultiPartFeature.class);
|
||||
return requestAdapter;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package org.gcube.common.storagehub.client.plugins;
|
||||
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.ws.EndpointReference;
|
||||
|
||||
import org.gcube.common.calls.jaxrs.GcubeService;
|
||||
import org.gcube.common.calls.jaxrs.TargetFactory;
|
||||
import org.gcube.common.clients.config.ProxyConfig;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||
import org.gcube.common.gxrest.response.entity.SerializableErrorEntityTextReader;
|
||||
import org.gcube.common.storagehub.client.Constants;
|
||||
import org.gcube.common.storagehub.client.MyInputStreamProvider;
|
||||
import org.gcube.common.storagehub.client.proxies.DefaultUserManager;
|
||||
import org.gcube.common.storagehub.client.proxies.UserManagerClient;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class UserManagerPlugin extends AbstractPlugin<GXWebTargetAdapterRequest, UserManagerClient> {
|
||||
|
||||
public UserManagerPlugin() {
|
||||
super("storagehub/workspace");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Exception convert(Exception e, ProxyConfig<?, ?> arg1) {
|
||||
return e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserManagerClient newProxy(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||
return new DefaultUserManager(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GXWebTargetAdapterRequest resolve(EndpointReference epr, ProxyConfig<?, ?> config)
|
||||
throws Exception {
|
||||
DOMResult result = new DOMResult();
|
||||
epr.writeTo(result);
|
||||
Node node =result.getNode();
|
||||
Node child=node.getFirstChild();
|
||||
String address = child.getTextContent();
|
||||
//GXWebTargetAdapterRequest request = GXWebTargetAdapterRequest.newRequest(address).path(this.name).path("items");
|
||||
GcubeService service = GcubeService.service().withName(Constants.MANAGER_QNAME).andPath("users");
|
||||
GXWebTargetAdapterRequest requestAdapter = TargetFactory.stubFor(service).getAsGxRest(address);
|
||||
requestAdapter.register(SerializableErrorEntityTextReader.class);
|
||||
requestAdapter.register(MyInputStreamProvider.class);
|
||||
requestAdapter.register(MultiPartFeature.class);
|
||||
return requestAdapter;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,199 @@
|
|||
package org.gcube.common.storagehub.client.proxies;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.MultivaluedHashMap;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
|
||||
import org.gcube.common.clients.Call;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
import org.gcube.common.gxrest.request.GXWebTargetAdapterRequest;
|
||||
import org.gcube.common.gxrest.response.inbound.GXInboundResponse;
|
||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
|
||||
public class DefaultGroupManager implements GroupManagerClient {
|
||||
|
||||
private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
|
||||
|
||||
public DefaultGroupManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUserToGroup(String userId, String groupId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
MultivaluedMap<String, String> formData = new MultivaluedHashMap<String, String>();
|
||||
formData.add("userId", userId);
|
||||
|
||||
GXInboundResponse response = myManager.path(groupId).put(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUserFromGroup(String userId, String groupId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
GXInboundResponse response = myManager.path(groupId).path("users").path(userId).delete();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getGroups() throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, List<String>> call = new Call<GXWebTargetAdapterRequest, List<String>>() {
|
||||
@Override
|
||||
public List<String> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
GXInboundResponse response = myManager.get();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
return response.getSource().readEntity(List.class);
|
||||
}
|
||||
};
|
||||
try {
|
||||
List<String> users = delegate.make(call);
|
||||
return users;
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeGroup(String groupId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
GXInboundResponse response = myManager.path(groupId).delete();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createGroup(String groupId, AccessType accessType) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
MultivaluedMap<String, Object> formData = new MultivaluedHashMap<String, Object>();
|
||||
formData.add("group", groupId);
|
||||
formData.add("accessType", accessType);
|
||||
|
||||
GXInboundResponse response = myManager.post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED));
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsersOfGroup(String groupId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, List<String>> call = new Call<GXWebTargetAdapterRequest, List<String>>() {
|
||||
@Override
|
||||
public List<String> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
GXInboundResponse response = myManager.path(groupId).path("users").get();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
return response.getSource().readEntity(List.class);
|
||||
}
|
||||
};
|
||||
try {
|
||||
List<String> users = delegate.make(call);
|
||||
return users;
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package org.gcube.common.storagehub.client.proxies;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.MultivaluedHashMap;
|
||||
import javax.ws.rs.core.MultivaluedMap;
|
||||
|
||||
import org.gcube.common.clients.Call;
|
||||
import org.gcube.common.clients.delegates.ProxyDelegate;
|
||||
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;
|
||||
|
||||
public class DefaultUserManager implements UserManagerClient {
|
||||
|
||||
private final ProxyDelegate<GXWebTargetAdapterRequest> delegate;
|
||||
|
||||
public DefaultUserManager(ProxyDelegate<GXWebTargetAdapterRequest> delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUser(String userId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
public Void call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
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
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUser(String userId) throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, Void> call = new Call<GXWebTargetAdapterRequest, Void>() {
|
||||
@Override
|
||||
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();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
delegate.make(call);
|
||||
return;
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUsers() throws StorageHubException {
|
||||
Call<GXWebTargetAdapterRequest, List<String>> call = new Call<GXWebTargetAdapterRequest, List<String>>() {
|
||||
@Override
|
||||
public List<String> call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
GXWebTargetAdapterRequest myManager = manager;
|
||||
|
||||
GXInboundResponse response = myManager.get();
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException())
|
||||
throw response.getException();
|
||||
else
|
||||
throw new BackendGenericError();
|
||||
}
|
||||
|
||||
return response.getSource().readEntity(List.class);
|
||||
}
|
||||
};
|
||||
try {
|
||||
List<String> users = delegate.make(call);
|
||||
return users;
|
||||
}catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package org.gcube.common.storagehub.client.proxies;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.storagehub.model.acls.AccessType;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
|
||||
public interface GroupManagerClient {
|
||||
|
||||
void addUserToGroup(String userId, String groupId) throws StorageHubException;
|
||||
|
||||
void removeUserFromGroup(String userId, String groupId) throws StorageHubException;
|
||||
|
||||
void removeGroup(String groupId) throws StorageHubException;
|
||||
|
||||
void createGroup(String groupId, AccessType accessType) throws StorageHubException;
|
||||
|
||||
List<String> getUsersOfGroup(String groupId) throws StorageHubException;
|
||||
|
||||
List<String> getGroups() throws StorageHubException;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.gcube.common.storagehub.client.proxies;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
|
||||
public interface UserManagerClient {
|
||||
|
||||
void addUser(String userId) throws StorageHubException;
|
||||
|
||||
void removeUser(String userId) throws StorageHubException;
|
||||
|
||||
List<String> getUsers() throws StorageHubException;
|
||||
|
||||
}
|
Loading…
Reference in New Issue