Bug fox for Bug #6115 Register Users to VRE user cache problem and removed asl session

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/register-vre-users@135218 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2016-12-02 11:40:21 +00:00
parent 4dab4c016b
commit ec658e588c
5 changed files with 46 additions and 75 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/register-vre-users-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/register-vre-users-2.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/register-vre-users-2.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources"> <classpathentry excluding="**" kind="src" output="target/register-vre-users-2.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
@ -39,5 +39,5 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/register-vre-users-2.1.0-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/register-vre-users-2.2.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -1,4 +1,9 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.portlets-admin.register-vre-users.2-2-0"
date="2016-12-02">
<Change>Removed ASL Session</Change>
<Change>Bug fix for Bug #6115 Register Users to VRE user cache problem</Change>
</Changeset>
<Changeset component="org.gcube.portlets-admin.register-vre-users.2-1-0" <Changeset component="org.gcube.portlets-admin.register-vre-users.2-1-0"
date="2016-09-08"> date="2016-09-08">
<Change>Changed visbility of users depending on the gateway</Change> <Change>Changed visbility of users depending on the gateway</Change>

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.admin</groupId> <groupId>org.gcube.portlets.admin</groupId>
<artifactId>register-vre-users</artifactId> <artifactId>register-vre-users</artifactId>
<packaging>war</packaging> <packaging>war</packaging>
<version>2.1.0-SNAPSHOT</version> <version>2.2.0-SNAPSHOT</version>
<name>Register VRE Users</name> <name>Register VRE Users</name>
<description> <description>
Register VRE Users Portlet allow to select a user from the portal and add her to the VRE. Register VRE Users Portlet allow to select a user from the portal and add her to the VRE.
@ -63,11 +63,6 @@
<scope>provided</scope> <scope>provided</scope>
<version>${gwtVersion}</version> <version>${gwtVersion}</version>
</dependency> </dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId> <artifactId>gcube-widgets</artifactId>

View File

@ -5,8 +5,7 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager; import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager; import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite; import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
@ -33,44 +32,28 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.model.Group; import com.liferay.portal.model.Group;
import com.liferay.portal.model.User; import com.liferay.portal.model.User;
import com.liferay.portal.model.VirtualHost; import com.liferay.portal.model.VirtualHost;
import com.liferay.portal.security.permission.PermissionChecker; import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil; import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
import com.liferay.portal.security.permission.PermissionThreadLocal; import com.liferay.portal.security.permission.PermissionThreadLocal;
import com.liferay.portal.service.CompanyLocalServiceUtil;
import com.liferay.portal.service.LayoutSetLocalServiceUtil; import com.liferay.portal.service.LayoutSetLocalServiceUtil;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.service.VirtualHostLocalServiceUtil; import com.liferay.portal.service.VirtualHostLocalServiceUtil;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ManageUsersServiceImpl extends RemoteServiceServlet implements ManageUsersService { public class ManageUsersServiceImpl extends RemoteServiceServlet implements ManageUsersService {
private static final Logger _log = LoggerFactory.getLogger(ManageUsersServiceImpl.class); private static final Logger _log = LoggerFactory.getLogger(ManageUsersServiceImpl.class);
public static final String DEFAULT_COMPANY_WEB_ID = "liferay.com";
private GroupManager groupM = new LiferayGroupManager();
private UserManager userM = new LiferayUserManager();
private final static String POSITION = "POSITION"; private final static String POSITION = "POSITION";
private final static String LABS = "LABS"; private final static String LABS = "LABS";
/**
* the current ASLSession
* @return the session
*/
private ASLSession getASLSession() {
String sessionID = this.getThreadLocalRequest().getSession().getId();
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
if (user == null) {
_log.warn("USER IS NULL setting test.user");
user = "test.user";
}
else {
_log.info("LIFERAY PORTAL DETECTED user=" + user);
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
/** /**
* *
* @return true if you're running into the portal, false if in development * @return true if you're running into the portal, false if in development
@ -87,7 +70,7 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
} }
@Override @Override
public ArrayList<PortalUserDTO> getAvailableUsers() { public ArrayList<PortalUserDTO> getAvailableUsers() {
getASLSession();
ArrayList<PortalUserDTO> toReturn = new ArrayList<PortalUserDTO>(); ArrayList<PortalUserDTO> toReturn = new ArrayList<PortalUserDTO>();
if (isWithinPortal()) { if (isWithinPortal()) {
return getNonBelongingUsersForVRE(); return getNonBelongingUsersForVRE();
@ -144,9 +127,12 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
* @return A list with the username of the unregistered users * @return A list with the username of the unregistered users
*/ */
public ArrayList<PortalUserDTO> getNonBelongingUsersForVRE() { public ArrayList<PortalUserDTO> getNonBelongingUsersForVRE() {
CacheRegistryUtil.clear();
PortalContext pContext = PortalContext.getConfiguration();
String scope = pContext.getCurrentScope(getThreadLocalRequest());
GCubeUser currentUser = pContext.getCurrentUser(getThreadLocalRequest());
try { try {
long companyId = SiteManagerUtil.getCompany().getCompanyId(); long companyId = CompanyLocalServiceUtil.getCompanyByWebId(getDefaultCompanyWebId()).getCompanyId();
_log.trace("Setting Thread Permission"); _log.trace("Setting Thread Permission");
User userAdmin = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername()); User userAdmin = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername());
_log.trace("Setting Thread Permission for admin="+userAdmin.getScreenName()); _log.trace("Setting Thread Permission for admin="+userAdmin.getScreenName());
@ -158,8 +144,9 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
//List<GCubeUser> notBelongingUsers = userM.listUnregisteredUsersByGroup(getCurrentGroupID()); //List<GCubeUser> notBelongingUsers = userM.listUnregisteredUsersByGroup(getCurrentGroupID());
long currSiteGroupId = getSiteFromServletRequest(getThreadLocalRequest()).getGroupId(); long currSiteGroupId = getSiteFromServletRequest(getThreadLocalRequest()).getGroupId();
UserManager userM = new LiferayUserManager();
List<GCubeUser> nonBelongingUsers = userM.listUsersByGroup(currSiteGroupId); //the users of i-marine or services etc List<GCubeUser> nonBelongingUsers = userM.listUsersByGroup(currSiteGroupId); //the users of i-marine or services etc
nonBelongingUsers.removeAll(userM.listUsersByGroup(getCurrentGroupID())); nonBelongingUsers.removeAll(userM.listUsersByGroup(pContext.getCurrentGroupId(getThreadLocalRequest())));
for (GCubeUser u : nonBelongingUsers) { for (GCubeUser u : nonBelongingUsers) {
String id = u.getUsername(); String id = u.getUsername();
@ -172,7 +159,7 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
} }
if ((u.getLastName() != null && u.getLastName().compareTo("") != 0)) { if ((u.getLastName() != null && u.getLastName().compareTo("") != 0)) {
String firstLetter = u.getLastName().substring(0,1); String firstLetter = u.getLastName().substring(0,1);
String scope = getASLSession().getScope();
ScopeBean validator = new ScopeBean(scope); ScopeBean validator = new ScopeBean(scope);
String email = u.getEmail(); String email = u.getEmail();
String username = id; String username = id;
@ -184,7 +171,7 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
} }
} }
_log.trace("Setting Thread Permission back to regular"); _log.trace("Setting Thread Permission back to regular");
User user = UserLocalServiceUtil.getUserByScreenName(companyId, getASLSession().getUsername()); User user = UserLocalServiceUtil.getUserByScreenName(companyId, currentUser.getUsername());
permissionChecker = PermissionCheckerFactoryUtil.create(user); permissionChecker = PermissionCheckerFactoryUtil.create(user);
PermissionThreadLocal.setPermissionChecker(permissionChecker); PermissionThreadLocal.setPermissionChecker(permissionChecker);
@ -202,9 +189,10 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
*/ */
@Override @Override
public boolean registerUsers(List<PortalUserDTO> users2Register) { public boolean registerUsers(List<PortalUserDTO> users2Register) {
long vreGroupId = PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest());
UserManager userM = new LiferayUserManager();
for (PortalUserDTO user : users2Register) { for (PortalUserDTO user : users2Register) {
try { try {
long vreGroupId = getCurrentGroupID();
//add the user to the VRE //add the user to the VRE
userM.assignUserToGroup(vreGroupId, userM.getUserId(user.getId())); userM.assignUserToGroup(vreGroupId, userM.getUserId(user.getId()));
//send notification //send notification
@ -224,9 +212,12 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
* @throws Exception * @throws Exception
*/ */
private boolean sendNotificationToUser(long groupId, PortalUserDTO addressee) throws Exception { private boolean sendNotificationToUser(long groupId, PortalUserDTO addressee) throws Exception {
ASLSession session = getASLSession(); PortalContext pContext = PortalContext.getConfiguration();
Workspace workspace = HomeLibrary.getUserWorkspace(session.getUsername()); String scope = pContext.getCurrentScope(getThreadLocalRequest());
GCubeUser currentUser = pContext.getCurrentUser(getThreadLocalRequest());
Workspace workspace = HomeLibrary.getUserWorkspace(currentUser.getUsername());
List<String> recipientIds = new ArrayList<String>(); List<String> recipientIds = new ArrayList<String>();
recipientIds.add(addressee.getId()); recipientIds.add(addressee.getId());
@ -238,35 +229,33 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man
String vreURL = gatewayURL + "/group" + new LiferayGroupManager().getGroup(groupId).getFriendlyURL(); String vreURL = gatewayURL + "/group" + new LiferayGroupManager().getGroup(groupId).getFriendlyURL();
String subject = "Registration to VRE notification"; String subject = "Registration to VRE notification";
String body = "Dear "+addressee.getName()+", \n\n I just registered you to the VRE " + session.getGroupName()+" on the " + gatewayName + ". \n\n"; String body = "Dear "+addressee.getName()+", \n\n I just registered you to the VRE " + pContext.getCurrentGroupName(getThreadLocalRequest())+" on the " + gatewayName + ". \n\n";
body += "Please, click here to access the VRE: " + vreURL; body += "Please, click here to access the VRE: " + vreURL;
String messageId = workspace.getWorkspaceMessageManager().sendMessageToPortalLogins(subject, body, new ArrayList<String>(), recipientIds); String messageId = workspace.getWorkspaceMessageManager().sendMessageToPortalLogins(subject, body, new ArrayList<String>(), recipientIds);
_log.debug("Sending message notification to: " + recipientIds.toString()); _log.debug("Sending message notification to: " + recipientIds.toString());
NotificationsManager nm = new ApplicationNotificationsManager(new SocialNetworkingSite(getThreadLocalRequest()), session.getScope(), new SocialNetworkingUser( NotificationsManager nm = new ApplicationNotificationsManager(new SocialNetworkingSite(getThreadLocalRequest()), scope, new SocialNetworkingUser(
session.getUsername(), session.getUserEmailAddress(), session.getUserFullName(), session.getUserAvatarId())); currentUser.getUsername(), currentUser.getEmail(), currentUser.getFullname(), currentUser.getUserAvatarURL()));
Thread thread = new Thread(new MessageNotificationsThread(recipients, messageId, subject, body, nm)); Thread thread = new Thread(new MessageNotificationsThread(recipients, messageId, subject, body, nm));
thread.start(); thread.start();
return (messageId != null); return (messageId != null);
} }
/** /**
* Get the current group ID
* *
* @return the current group ID or null if an exception is thrown * @return the default company web-id (e.g. iMarine.eu)
* @throws Exception
*/ */
private long getCurrentGroupID() { public static String getDefaultCompanyWebId() {
ASLSession session = getASLSession(); String defaultWebId = "";
_log.debug("The current group NAME is --> " + session.getGroupName());
long toReturn = -1;
try { try {
toReturn = groupM.getGroupId(session.getGroupName()); defaultWebId = GetterUtil.getString(PropsUtil.get("company.default.web.id"));
} catch (UserManagementSystemException | GroupRetrievalFault e) {
e.printStackTrace();
} }
return toReturn; catch (NullPointerException e) {
_log.info("Cound not find property company.default.web.id in portal.ext file returning default web id: " + DEFAULT_COMPANY_WEB_ID);
return DEFAULT_COMPANY_WEB_ID;
}
return defaultWebId;
} }
} }

View File

@ -10,36 +10,18 @@ import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet; import javax.portlet.GenericPortlet;
import javax.portlet.PortletException; import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher; import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletSession;
import javax.portlet.RenderRequest; import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse; import javax.portlet.RenderResponse;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import com.liferay.portal.theme.ThemeDisplay;
/** /**
* ManageVREUsersPortlet Portlet Class * ManageVREUsersPortlet Portlet Class
* @author Massimiliano Assante - ISTI CNR * @author Massimiliano Assante - ISTI CNR
* @version 1.0 Feb 2014
*/ */
public class ManageVREUsersPortlet extends GenericPortlet { public class ManageVREUsersPortlet extends GenericPortlet {
private static Log _log = LogFactoryUtil.getLog(ManageVREUsersPortlet.class);
public void doView(RenderRequest request, RenderResponse response) public void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException { throws PortletException, IOException {
ScopeHelper.setContext(request);
PortletRequestDispatcher dispatcher = PortletRequestDispatcher dispatcher =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/manageusers_view.jsp"); getPortletContext().getRequestDispatcher("/WEB-INF/jsp/manageusers_view.jsp");
dispatcher.include(request, response); dispatcher.include(request, response);