added the part to reserve the screenname (username) when account removed
This commit is contained in:
parent
6a38f38842
commit
464ea56f27
6
pom.xml
6
pom.xml
|
@ -89,6 +89,12 @@
|
||||||
<artifactId>portal-service</artifactId>
|
<artifactId>portal-service</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.portlet</groupId>
|
||||||
|
<artifactId>portlet-api</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
|
|
@ -2,5 +2,6 @@ package org.gcube.portal.removeaccount;
|
||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
public static final String AUTORISED_INFRA_ROLE = "Infrastructure-Manager";
|
public static final String AUTORISED_INFRA_ROLE = "Infrastructure-Manager";
|
||||||
|
public static final String USERNAME_PREFERENCE_KEY = "admin.reserved.screen.names";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@ package org.gcube.portal.removeaccount.thread;
|
||||||
|
|
||||||
import java.util.List;
|
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.PortalContext;
|
||||||
import org.gcube.common.portal.mailing.EmailNotification;
|
import org.gcube.common.portal.mailing.EmailNotification;
|
||||||
import org.gcube.portal.removeaccount.Constants;
|
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.gcube.vomanagement.usermanagement.model.GatewayRolesNames;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
|
import com.liferay.portal.util.PortalUtil;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,10 +54,10 @@ public class RemovedUserAccountThread implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
_log.info("Trying to remove user " + userName + " from JCR first, using storageHub with role: "+Constants.AUTORISED_INFRA_ROLE);
|
// _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);
|
// RemoveUserFromJCR rmJCR = new RemoveUserFromJCR(userName, gm, uMan);
|
||||||
boolean result = rmJCR.remove();
|
// boolean result = rmJCR.remove();
|
||||||
_log.info("The user " + userName + " has been removed from JCR with success? " + result);
|
// _log.info("The user " + userName + " has been removed from JCR with success? " + result);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
_log.error("An error occurred during user workspace removal: ", e);
|
_log.error("An error occurred during user workspace removal: ", e);
|
||||||
|
@ -68,12 +70,17 @@ public class RemovedUserAccountThread implements Runnable {
|
||||||
//first remove the account
|
//first remove the account
|
||||||
try {
|
try {
|
||||||
UserLocalServiceUtil.deleteUser(userId);
|
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) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
_log.info("removeUser account for " + userName + " done with success, now notify the managers ... ");
|
//then notify the managers
|
||||||
//the notify the managers
|
|
||||||
|
|
||||||
RoleManager rm = new LiferayRoleManager();
|
RoleManager rm = new LiferayRoleManager();
|
||||||
try {
|
try {
|
||||||
String rootVoName = PortalContext.getConfiguration().getInfrastructureName();
|
String rootVoName = PortalContext.getConfiguration().getInfrastructureName();
|
||||||
|
|
Reference in New Issue