diff --git a/.classpath b/.classpath
index 26981b6..04023d0 100644
--- a/.classpath
+++ b/.classpath
@@ -15,6 +15,7 @@
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
index 6e80039..4e4a3ad 100644
--- a/.settings/org.eclipse.jdt.core.prefs
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -5,4 +5,5 @@ org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index a2d46af..eedc2aa 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -1,5 +1,5 @@
-
+
diff --git a/pom.xml b/pom.xml
index f5e988d..96ca0c8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,19 +1,20 @@
-
4.0.0
maven-parent
org.gcube.tools
- 1.0.0
+ 1.1.0
org.gcube.portal.liferay
user-registration-hook
war
user-registration-hook Hook
- 1.1.0-SNAPSHOT
+ 2.0.0-SNAPSHOT
@@ -32,7 +33,6 @@
maven-compiler-plugin
- 2.5
UTF-8
@@ -53,33 +53,22 @@
org.gcube.distribution
maven-portal-bom
- LATEST
+ 3.6.0
pom
import
+
+ org.gcube.common
+ storagehub-client-library
+
org.gcube.portal
notifications-common-library
provided
-
- org.gcube.common
- home-library
- provided
-
-
- org.gcube.common
- home-library-jcr
- provided
-
-
- org.gcube.common
- home-library-model
- provided
-
org.gcube.dvos
usermanagement-core
diff --git a/src/main/java/org/gcube/portal/usersaccount/WorkspaceCreateAccountThread.java b/src/main/java/org/gcube/portal/usersaccount/WorkspaceCreateAccountThread.java
index 296acfb..a3ae555 100644
--- a/src/main/java/org/gcube/portal/usersaccount/WorkspaceCreateAccountThread.java
+++ b/src/main/java/org/gcube/portal/usersaccount/WorkspaceCreateAccountThread.java
@@ -1,40 +1,74 @@
package org.gcube.portal.usersaccount;
+import java.util.ArrayList;
+import java.util.List;
+
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
-import org.gcube.common.homelibrary.home.HomeLibrary;
-import org.gcube.common.homelibrary.home.workspace.Workspace;
+import static org.gcube.common.authorization.client.Constants.authorizationService;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
+import org.gcube.common.storagehub.client.dsl.StorageHubClient;
+import org.gcube.vomanagement.usermanagement.RoleManager;
+import org.gcube.vomanagement.usermanagement.UserManager;
+import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
+import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
+import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
+import org.gcube.vomanagement.usermanagement.model.GCubeRole;
+import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WorkspaceCreateAccountThread implements Runnable {
private static Logger _log = LoggerFactory.getLogger(WorkspaceCreateAccountThread.class);
-
+ public static final String AUTORISED_INFRA_ROLE = "Infrastructure-Manager";
private String newUserUserName;
public WorkspaceCreateAccountThread(String newUserUserName, String newUserFullName, String newUserEmailAddress) {
super();
this.newUserUserName = newUserUserName;
- _log.info("Calling HomeLibrary for Workspace creation to new user: " + newUserUserName + " ("+newUserFullName+")");
+ _log.info("Calling StorageHub for Workspace creation to new user: " + newUserUserName + " ("+newUserFullName+")");
}
@Override
public void run() {
getWS(newUserUserName, "/"+PortalContext.getConfiguration().getInfrastructureName());
}
- public static Workspace getWS(String currentUsername, String context) {
+ public static void getWS(String currentUsername, String context) {
String username = currentUsername;
String authorizationToken = PortalContext.getConfiguration().getCurrentUserToken(context, username);
SecurityTokenProvider.instance.set(authorizationToken);
ScopeProvider.instance.set(context);
- try {
- Workspace toReturn = HomeLibrary.getUserWorkspace(username);
- _log.info("Done Workspace creation for user: " + currentUsername);
- return toReturn;
+ String previousToken = authorizationToken;
+ try {
+ //get the super user
+ String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
+ long groupId = new LiferayGroupManager().getGroupIdFromInfrastructureScope(infraContext);
+ RoleManager rm = new LiferayRoleManager();
+ UserManager uMan = new LiferayUserManager();
+ long roleId = rm.getRoleId(AUTORISED_INFRA_ROLE, groupId);
+ List users = uMan.listUsersByGroupAndRole(groupId, roleId);
+ if (users.isEmpty()) {
+ _log.error("Cannot create this user account on storageHub there is no user having role {} on context {}", AUTORISED_INFRA_ROLE , infraContext);
+ return;
+ }
+ else {
+ GCubeUser theAdmin = users.get(0);
+ String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, theAdmin.getUsername());
+ List theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), groupId);
+ List rolesString = new ArrayList();
+ for (GCubeRole gCubeRole : theAdminRoles) {
+ rolesString.add(gCubeRole.getRoleName());
+ }
+ authorizationService().setTokenRoles(theAdminToken, rolesString);
+ SecurityTokenProvider.instance.set(theAdminToken);
+ StorageHubClient shc = new StorageHubClient();
+ shc.createUserAccount(currentUsername);
+ SecurityTokenProvider.instance.set(previousToken);
+ }
}
catch (Exception e) {
e.printStackTrace();
- return null;
+ SecurityTokenProvider.instance.set(previousToken);
+ return;
}
}
}
diff --git a/src/main/webapp/WEB-INF/liferay-plugin-package.properties b/src/main/webapp/WEB-INF/liferay-plugin-package.properties
index 272a653..d42704a 100644
--- a/src/main/webapp/WEB-INF/liferay-plugin-package.properties
+++ b/src/main/webapp/WEB-INF/liferay-plugin-package.properties
@@ -1,6 +1,6 @@
name=user-registration-hook
module-group-id=liferay
-module-incremental-version=2
+module-incremental-version=3
tags=
short-description=
change-log=