From 464ea56f278d59e1a97f10a800ac5ccfa22ef510 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 12 Dec 2019 16:18:05 +0100 Subject: [PATCH] added the part to reserve the screenname (username) when account removed --- pom.xml | 6 +++++ .../gcube/portal/removeaccount/Constants.java | 1 + .../thread/RemovedUserAccountThread.java | 27 ++++++++++++------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 6aa9f86..ed80066 100644 --- a/pom.xml +++ b/pom.xml @@ -89,6 +89,12 @@ portal-service provided + + javax.portlet + portlet-api + 2.0 + provided + junit junit diff --git a/src/main/java/org/gcube/portal/removeaccount/Constants.java b/src/main/java/org/gcube/portal/removeaccount/Constants.java index 0ec6d92..01a24f9 100644 --- a/src/main/java/org/gcube/portal/removeaccount/Constants.java +++ b/src/main/java/org/gcube/portal/removeaccount/Constants.java @@ -2,5 +2,6 @@ package org.gcube.portal.removeaccount; public class Constants { public static final String AUTORISED_INFRA_ROLE = "Infrastructure-Manager"; + public static final String USERNAME_PREFERENCE_KEY = "admin.reserved.screen.names"; } diff --git a/src/main/java/org/gcube/portal/removeaccount/thread/RemovedUserAccountThread.java b/src/main/java/org/gcube/portal/removeaccount/thread/RemovedUserAccountThread.java index 929be7e..98a6640 100644 --- a/src/main/java/org/gcube/portal/removeaccount/thread/RemovedUserAccountThread.java +++ b/src/main/java/org/gcube/portal/removeaccount/thread/RemovedUserAccountThread.java @@ -2,6 +2,9 @@ package org.gcube.portal.removeaccount.thread; import java.util.List; +import javax.portlet.PortletPreferences; +import com.liferay.portal.service.PortalPreferencesLocalServiceUtil; + import org.gcube.common.portal.PortalContext; import org.gcube.common.portal.mailing.EmailNotification; import org.gcube.portal.removeaccount.Constants; @@ -16,9 +19,8 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GatewayRolesNames; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - - import com.liferay.portal.service.UserLocalServiceUtil; +import com.liferay.portal.util.PortalUtil; /** @@ -52,10 +54,10 @@ public class RemovedUserAccountThread implements Runnable { @Override public void run() { try { - _log.info("Trying to remove user " + userName + " from JCR first, using storageHub with role: "+Constants.AUTORISED_INFRA_ROLE); - RemoveUserFromJCR rmJCR = new RemoveUserFromJCR(userName, gm, uMan); - boolean result = rmJCR.remove(); - _log.info("The user " + userName + " has been removed from JCR with success? " + result); +// _log.info("Trying to remove user " + userName + " from JCR first, using storageHub with role: "+Constants.AUTORISED_INFRA_ROLE); +// RemoveUserFromJCR rmJCR = new RemoveUserFromJCR(userName, gm, uMan); +// boolean result = rmJCR.remove(); +// _log.info("The user " + userName + " has been removed from JCR with success? " + result); } catch (Exception e) { _log.error("An error occurred during user workspace removal: ", e); @@ -68,12 +70,17 @@ public class RemovedUserAccountThread implements Runnable { //first remove the account try { UserLocalServiceUtil.deleteUser(userId); + _log.info("removeUser account for " + userName + " done with success, now notify the managers ... "); + //set the username as reserved + long defaultCompanyId = PortalUtil.getDefaultCompanyId(); + PortletPreferences prefs = PortalPreferencesLocalServiceUtil.getPreferences(defaultCompanyId, 1); + String value = prefs.getValue(Constants.USERNAME_PREFERENCE_KEY, null); + prefs.setValue(Constants.USERNAME_PREFERENCE_KEY, value+"\n"+userName); + prefs.store(); } catch (Exception e) { e.printStackTrace(); - } - _log.info("removeUser account for " + userName + " done with success, now notify the managers ... "); - //the notify the managers - + } + //then notify the managers RoleManager rm = new LiferayRoleManager(); try { String rootVoName = PortalContext.getConfiguration().getInfrastructureName();