diff --git a/CHANGELOG.md b/CHANGELOG.md index a9e5ba4..5a4ca6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v1.2.2] - [2021-02-08] + +### Feature + +method for user existence check added + ## [v1.2.1] - [2020-07-17] diff --git a/pom.xml b/pom.xml index 15e16c1..8457d70 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ org.gcube.common storagehub-client-library - 1.2.1 + 1.2.2 storagehub-client-library diff --git a/src/main/java/org/gcube/common/storagehub/client/dsl/StorageHubClient.java b/src/main/java/org/gcube/common/storagehub/client/dsl/StorageHubClient.java index d24d2fe..0d623a9 100644 --- a/src/main/java/org/gcube/common/storagehub/client/dsl/StorageHubClient.java +++ b/src/main/java/org/gcube/common/storagehub/client/dsl/StorageHubClient.java @@ -76,4 +76,9 @@ public class StorageHubClient { public void deleteUserAccount(String userId) throws StorageHubException { userClient.removeUser(userId); } + + public boolean userExists(String user) throws StorageHubException { + return userClient.exists(user); + } + } diff --git a/src/main/java/org/gcube/common/storagehub/client/plugins/AbstractPlugin.java b/src/main/java/org/gcube/common/storagehub/client/plugins/AbstractPlugin.java index 0f11c5d..3235496 100644 --- a/src/main/java/org/gcube/common/storagehub/client/plugins/AbstractPlugin.java +++ b/src/main/java/org/gcube/common/storagehub/client/plugins/AbstractPlugin.java @@ -1,6 +1,5 @@ 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; diff --git a/src/main/java/org/gcube/common/storagehub/client/plugins/GroupManagerPlugin.java b/src/main/java/org/gcube/common/storagehub/client/plugins/GroupManagerPlugin.java index bfc8ae7..405a753 100644 --- a/src/main/java/org/gcube/common/storagehub/client/plugins/GroupManagerPlugin.java +++ b/src/main/java/org/gcube/common/storagehub/client/plugins/GroupManagerPlugin.java @@ -12,9 +12,7 @@ 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; 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 8441c12..f0ab384 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 @@ -12,6 +12,7 @@ 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.IdNotFoundException; import org.gcube.common.storagehub.model.exceptions.StorageHubException; import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException; @@ -127,5 +128,39 @@ public class DefaultUserManager implements UserManagerClient { throw new RuntimeException(e1); } } + + @Override + public boolean exists(String user) throws StorageHubException { + Call call = new Call() { + @Override + public Boolean call(GXWebTargetAdapterRequest manager) throws Exception { + GXWebTargetAdapterRequest myManager = manager.path(user); + + GXInboundResponse response = myManager.get(); + + if (response.isErrorResponse()) { + if (response.hasException()) + if (response.getException().getClass().equals(IdNotFoundException.class)) + return false; + else 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(); + } + + return true; + } + }; + try { + return delegate.make(call); + }catch(StorageHubException e) { + throw e; + }catch(Exception e1) { + throw new RuntimeException(e1); + } + } + } diff --git a/src/main/java/org/gcube/common/storagehub/client/proxies/UserManagerClient.java b/src/main/java/org/gcube/common/storagehub/client/proxies/UserManagerClient.java index a577eac..e7a797b 100644 --- a/src/main/java/org/gcube/common/storagehub/client/proxies/UserManagerClient.java +++ b/src/main/java/org/gcube/common/storagehub/client/proxies/UserManagerClient.java @@ -11,5 +11,7 @@ public interface UserManagerClient { void removeUser(String userId) throws StorageHubException; List getUsers() throws StorageHubException; + + boolean exists(String user) throws StorageHubException; }