Create Workspase is still performed via HomeLibrary
This commit is contained in:
parent
780ad7c473
commit
d8edcb1b7b
15
pom.xml
15
pom.xml
|
@ -41,6 +41,21 @@
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>home-library</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>home-library-jcr</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.common</groupId>
|
||||||
|
<artifactId>home-library-model</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-encryption</artifactId>
|
<artifactId>common-encryption</artifactId>
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
package org.gcube.portal.usersaccount;
|
package org.gcube.portal.usersaccount;
|
||||||
|
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
|
||||||
import org.gcube.portal.notifications.thread.NewUserAccountNotificationThread;
|
import org.gcube.portal.notifications.thread.NewUserAccountNotificationThread;
|
||||||
import org.gcube.portal.removeaccount.thread.RemoveUserTokenFromInfraThread;
|
import org.gcube.portal.removeaccount.thread.RemoveUserTokenFromInfraThread;
|
||||||
import org.gcube.portal.removeaccount.thread.RemovedUserAccountThread;
|
import org.gcube.portal.removeaccount.thread.RemovedUserAccountThread;
|
||||||
|
@ -18,8 +14,6 @@ import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
||||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -46,11 +40,11 @@ public class MyCreateUserAccountListener extends BaseModelListener<User> {
|
||||||
@Override
|
@Override
|
||||||
public void onAfterCreate(User user) throws ModelListenerException {
|
public void onAfterCreate(User user) throws ModelListenerException {
|
||||||
_log.info("onAfterCreate NewUserAccount listener for: " + user.getScreenName() + " / " + user.getFullName());
|
_log.info("onAfterCreate NewUserAccount listener for: " + user.getScreenName() + " / " + user.getFullName());
|
||||||
Thread emailManagersThread = new Thread(new NewUserAccountNotificationThread(user.getScreenName(), user.getFullName(), user.getEmailAddress()));
|
|
||||||
emailManagersThread.start();
|
|
||||||
|
|
||||||
Thread WorkspaceAccountCreationThread = new Thread(new WorkspaceCreateAccountThread(user.getScreenName(), user.getFullName(), user.getEmailAddress()));
|
Thread WorkspaceAccountCreationThread = new Thread(new WorkspaceCreateAccountThread(user.getScreenName(), user.getFullName(), user.getEmailAddress()));
|
||||||
WorkspaceAccountCreationThread.start();
|
WorkspaceAccountCreationThread.start();
|
||||||
|
|
||||||
|
Thread emailManagersThread = new Thread(new NewUserAccountNotificationThread(user.getScreenName(), user.getFullName(), user.getEmailAddress()));
|
||||||
|
emailManagersThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,29 +60,15 @@ public class MyCreateUserAccountListener extends BaseModelListener<User> {
|
||||||
_log.debug("Getting super user with role {}", Constants.AUTORISED_INFRA_ROLE);
|
_log.debug("Getting super user with role {}", Constants.AUTORISED_INFRA_ROLE);
|
||||||
//get the super user
|
//get the super user
|
||||||
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
||||||
// long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext);
|
|
||||||
// RoleManager rm = new LiferayRoleManager();
|
String adminUsername = "lucio.lelii";
|
||||||
// long roleId = rm.getRoleId(HookConstants.AUTORISED_INFRA_ROLE, rootgroupId);
|
_log.info("Got the super user: {}",adminUsername);
|
||||||
// List<GCubeUser> users = uMan.listUsersByGroupAndRole(rootgroupId, roleId);
|
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, adminUsername);
|
||||||
// if (users.isEmpty()) {
|
List<String> rolesString = new ArrayList<String>();
|
||||||
// _log.error("Cannot add the user as VRE Folder admin: there is no user having role {} on context: {}", HookConstants.AUTORISED_INFRA_ROLE, infraContext);
|
rolesString.add("Infrastructure-Manager");
|
||||||
// return false;
|
_log.info("authorizationService().setTokenRoles done");
|
||||||
// }
|
Thread dropUserWorkspaceThread = new Thread(new RemovedUserAccountThread(username2Delete, theAdminToken, rolesString));
|
||||||
// else {
|
dropUserWorkspaceThread.start();
|
||||||
//GCubeUser theAdmin = users.get(0);
|
|
||||||
String adminUsername = "lucio.lelii";
|
|
||||||
_log.info("Got the super user: {}",adminUsername);
|
|
||||||
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, adminUsername);
|
|
||||||
List<String> rolesString = new ArrayList<String>();
|
|
||||||
// List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
|
|
||||||
// for (GCubeRole gCubeRole : theAdminRoles) {
|
|
||||||
// rolesString.add(gCubeRole.getRoleName());
|
|
||||||
// }
|
|
||||||
rolesString.add("Infrastructure-Manager");
|
|
||||||
_log.info("authorizationService().setTokenRoles(theAdminToken, rolesString);",theAdminToken);
|
|
||||||
Thread dropUserWorkspaceThread = new Thread(new RemovedUserAccountThread(username2Delete, theAdminToken, rolesString));
|
|
||||||
dropUserWorkspaceThread.start();
|
|
||||||
// }
|
|
||||||
|
|
||||||
_log.info("Trying to remove user from LDAP ...");
|
_log.info("Trying to remove user from LDAP ...");
|
||||||
Thread removeFromLDAPThread = new Thread(new RemovedUserFromLDAPThread(username2Delete));
|
Thread removeFromLDAPThread = new Thread(new RemovedUserFromLDAPThread(username2Delete));
|
||||||
|
|
|
@ -1,77 +1,40 @@
|
||||||
package org.gcube.portal.usersaccount;
|
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.authorization.library.provider.SecurityTokenProvider;
|
||||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||||
|
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||||
import org.gcube.common.portal.PortalContext;
|
import org.gcube.common.portal.PortalContext;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class WorkspaceCreateAccountThread implements Runnable {
|
public class WorkspaceCreateAccountThread implements Runnable {
|
||||||
private static Logger _log = LoggerFactory.getLogger(WorkspaceCreateAccountThread.class);
|
private static Logger _log = LoggerFactory.getLogger(WorkspaceCreateAccountThread.class);
|
||||||
public static final String AUTORISED_INFRA_ROLE = "Infrastructure-Manager";
|
|
||||||
private String newUserUserName;
|
private String newUserUserName;
|
||||||
|
|
||||||
public WorkspaceCreateAccountThread(String newUserUserName, String newUserFullName, String newUserEmailAddress) {
|
public WorkspaceCreateAccountThread(String newUserUserName, String newUserFullName, String newUserEmailAddress) {
|
||||||
super();
|
super();
|
||||||
this.newUserUserName = newUserUserName;
|
this.newUserUserName = newUserUserName;
|
||||||
_log.info("Calling StorageHub for Workspace creation to new user: " + newUserUserName + " ("+newUserFullName+")");
|
_log.info("Calling HomeLibrary for Workspace creation to new user: " + newUserUserName + " ("+newUserFullName+")");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
getWS(newUserUserName, "/"+PortalContext.getConfiguration().getInfrastructureName());
|
getWS(newUserUserName, "/"+PortalContext.getConfiguration().getInfrastructureName());
|
||||||
}
|
}
|
||||||
public static void getWS(String currentUsername, String context) {
|
public static Workspace getWS(String currentUsername, String context) {
|
||||||
String username = currentUsername;
|
String username = currentUsername;
|
||||||
String authorizationToken = PortalContext.getConfiguration().getCurrentUserToken(context, username);
|
String authorizationToken = PortalContext.getConfiguration().getCurrentUserToken(context, username);
|
||||||
SecurityTokenProvider.instance.set(authorizationToken);
|
SecurityTokenProvider.instance.set(authorizationToken);
|
||||||
ScopeProvider.instance.set(context);
|
ScopeProvider.instance.set(context);
|
||||||
String previousToken = authorizationToken;
|
|
||||||
try {
|
try {
|
||||||
//get the super user
|
Workspace toReturn = HomeLibrary.getUserWorkspace(username);
|
||||||
String infraContext = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
_log.info("Done Workspace creation for user: " + currentUsername);
|
||||||
// long rootgroupId = gm.getGroupIdFromInfrastructureScope(infraContext);
|
return toReturn;
|
||||||
// RoleManager rm = new LiferayRoleManager();
|
|
||||||
// long roleId = rm.getRoleId(HookConstants.AUTORISED_INFRA_ROLE, rootgroupId);
|
|
||||||
// List<GCubeUser> users = uMan.listUsersByGroupAndRole(rootgroupId, roleId);
|
|
||||||
// if (users.isEmpty()) {
|
|
||||||
// _log.error("Cannot add the user as VRE Folder admin: there is no user having role {} on context: {}", HookConstants.AUTORISED_INFRA_ROLE, infraContext);
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
//GCubeUser theAdmin = users.get(0);
|
|
||||||
String adminUsername = "lucio.lelii";
|
|
||||||
_log.info("Got the super user: {}",adminUsername);
|
|
||||||
String theAdminToken = PortalContext.getConfiguration().getCurrentUserToken(infraContext, adminUsername);
|
|
||||||
List<String> rolesString = new ArrayList<String>();
|
|
||||||
// List<GCubeRole> theAdminRoles = rm.listRolesByUserAndGroup(theAdmin.getUserId(), rootgroupId);
|
|
||||||
// for (GCubeRole gCubeRole : theAdminRoles) {
|
|
||||||
// rolesString.add(gCubeRole.getRoleName());
|
|
||||||
// }
|
|
||||||
rolesString.add("Infrastructure-Manager");
|
|
||||||
_log.info("authorizationService().setTokenRoles(theAdminToken, rolesString);",theAdminToken);
|
|
||||||
authorizationService().setTokenRoles(theAdminToken, rolesString);
|
|
||||||
SecurityTokenProvider.instance.set(theAdminToken);
|
|
||||||
StorageHubClient shc = new StorageHubClient();
|
|
||||||
shc.createUserAccount(currentUsername);
|
|
||||||
SecurityTokenProvider.instance.set(previousToken);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
SecurityTokenProvider.instance.set(previousToken);
|
return null;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue