From ec658e588ca64923bd52a741ea4ddd3ede7a5573 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 2 Dec 2016 11:40:21 +0000 Subject: [PATCH] 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 --- .classpath | 6 +- distro/changelog.xml | 5 ++ pom.xml | 7 +- .../server/ManageUsersServiceImpl.java | 85 ++++++++----------- .../server/portlet/ManageVREUsersPortlet.java | 18 ---- 5 files changed, 46 insertions(+), 75 deletions(-) diff --git a/.classpath b/.classpath index 8d525ba..5afb66a 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -39,5 +39,5 @@ - + diff --git a/distro/changelog.xml b/distro/changelog.xml index cfd03d3..aca7706 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,9 @@ + + Removed ASL Session + Bug fix for Bug #6115 Register Users to VRE user cache problem + Changed visbility of users depending on the gateway diff --git a/pom.xml b/pom.xml index aafbfc3..dc557b0 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portlets.admin register-vre-users war - 2.1.0-SNAPSHOT + 2.2.0-SNAPSHOT Register VRE Users Register VRE Users Portlet allow to select a user from the portal and add her to the VRE. @@ -63,11 +63,6 @@ provided ${gwtVersion} - - org.gcube.applicationsupportlayer - aslcore - provided - org.gcube.portlets.user gcube-widgets diff --git a/src/main/java/org/gcube/portlets/admin/manageusers/server/ManageUsersServiceImpl.java b/src/main/java/org/gcube/portlets/admin/manageusers/server/ManageUsersServiceImpl.java index 869bb12..0ec23f3 100644 --- a/src/main/java/org/gcube/portlets/admin/manageusers/server/ManageUsersServiceImpl.java +++ b/src/main/java/org/gcube/portlets/admin/manageusers/server/ManageUsersServiceImpl.java @@ -5,8 +5,7 @@ import java.util.List; 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.NotificationsManager; import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite; @@ -33,44 +32,28 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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.User; import com.liferay.portal.model.VirtualHost; import com.liferay.portal.security.permission.PermissionChecker; import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil; import com.liferay.portal.security.permission.PermissionThreadLocal; +import com.liferay.portal.service.CompanyLocalServiceUtil; import com.liferay.portal.service.LayoutSetLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.VirtualHostLocalServiceUtil; @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 GroupManager groupM = new LiferayGroupManager(); - private UserManager userM = new LiferayUserManager(); - + public static final String DEFAULT_COMPANY_WEB_ID = "liferay.com"; private final static String POSITION = "POSITION"; 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 @@ -87,7 +70,7 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man } @Override public ArrayList getAvailableUsers() { - getASLSession(); + ArrayList toReturn = new ArrayList(); if (isWithinPortal()) { return getNonBelongingUsersForVRE(); @@ -144,9 +127,12 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man * @return A list with the username of the unregistered users */ public ArrayList getNonBelongingUsersForVRE() { - + CacheRegistryUtil.clear(); + PortalContext pContext = PortalContext.getConfiguration(); + String scope = pContext.getCurrentScope(getThreadLocalRequest()); + GCubeUser currentUser = pContext.getCurrentUser(getThreadLocalRequest()); try { - long companyId = SiteManagerUtil.getCompany().getCompanyId(); + long companyId = CompanyLocalServiceUtil.getCompanyByWebId(getDefaultCompanyWebId()).getCompanyId(); _log.trace("Setting Thread Permission"); User userAdmin = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername()); _log.trace("Setting Thread Permission for admin="+userAdmin.getScreenName()); @@ -158,8 +144,9 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man //List notBelongingUsers = userM.listUnregisteredUsersByGroup(getCurrentGroupID()); long currSiteGroupId = getSiteFromServletRequest(getThreadLocalRequest()).getGroupId(); + UserManager userM = new LiferayUserManager(); List 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) { String id = u.getUsername(); @@ -172,7 +159,7 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man } if ((u.getLastName() != null && u.getLastName().compareTo("") != 0)) { String firstLetter = u.getLastName().substring(0,1); - String scope = getASLSession().getScope(); + ScopeBean validator = new ScopeBean(scope); String email = u.getEmail(); String username = id; @@ -184,7 +171,7 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man } } _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); PermissionThreadLocal.setPermissionChecker(permissionChecker); @@ -202,9 +189,10 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man */ @Override public boolean registerUsers(List users2Register) { + long vreGroupId = PortalContext.getConfiguration().getCurrentGroupId(getThreadLocalRequest()); + UserManager userM = new LiferayUserManager(); for (PortalUserDTO user : users2Register) { try { - long vreGroupId = getCurrentGroupID(); //add the user to the VRE userM.assignUserToGroup(vreGroupId, userM.getUserId(user.getId())); //send notification @@ -224,9 +212,12 @@ public class ManageUsersServiceImpl extends RemoteServiceServlet implements Man * @throws Exception */ private boolean sendNotificationToUser(long groupId, PortalUserDTO addressee) throws Exception { - ASLSession session = getASLSession(); - Workspace workspace = HomeLibrary.getUserWorkspace(session.getUsername()); + PortalContext pContext = PortalContext.getConfiguration(); + String scope = pContext.getCurrentScope(getThreadLocalRequest()); + GCubeUser currentUser = pContext.getCurrentUser(getThreadLocalRequest()); + Workspace workspace = HomeLibrary.getUserWorkspace(currentUser.getUsername()); + List recipientIds = new ArrayList(); 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 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; String messageId = workspace.getWorkspaceMessageManager().sendMessageToPortalLogins(subject, body, new ArrayList(), recipientIds); _log.debug("Sending message notification to: " + recipientIds.toString()); - NotificationsManager nm = new ApplicationNotificationsManager(new SocialNetworkingSite(getThreadLocalRequest()), session.getScope(), new SocialNetworkingUser( - session.getUsername(), session.getUserEmailAddress(), session.getUserFullName(), session.getUserAvatarId())); + NotificationsManager nm = new ApplicationNotificationsManager(new SocialNetworkingSite(getThreadLocalRequest()), scope, new SocialNetworkingUser( + currentUser.getUsername(), currentUser.getEmail(), currentUser.getFullname(), currentUser.getUserAvatarURL())); Thread thread = new Thread(new MessageNotificationsThread(recipients, messageId, subject, body, nm)); thread.start(); return (messageId != null); } + /** - * Get the current group ID * - * @return the current group ID or null if an exception is thrown - * @throws Exception + * @return the default company web-id (e.g. iMarine.eu) */ - private long getCurrentGroupID() { - ASLSession session = getASLSession(); - _log.debug("The current group NAME is --> " + session.getGroupName()); - long toReturn = -1; + public static String getDefaultCompanyWebId() { + String defaultWebId = ""; try { - toReturn = groupM.getGroupId(session.getGroupName()); - } catch (UserManagementSystemException | GroupRetrievalFault e) { - e.printStackTrace(); + defaultWebId = GetterUtil.getString(PropsUtil.get("company.default.web.id")); } - 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; } - } diff --git a/src/main/java/org/gcube/portlets/admin/manageusers/server/portlet/ManageVREUsersPortlet.java b/src/main/java/org/gcube/portlets/admin/manageusers/server/portlet/ManageVREUsersPortlet.java index 7576f8a..515f37c 100644 --- a/src/main/java/org/gcube/portlets/admin/manageusers/server/portlet/ManageVREUsersPortlet.java +++ b/src/main/java/org/gcube/portlets/admin/manageusers/server/portlet/ManageVREUsersPortlet.java @@ -10,36 +10,18 @@ import javax.portlet.ActionResponse; import javax.portlet.GenericPortlet; import javax.portlet.PortletException; import javax.portlet.PortletRequestDispatcher; -import javax.portlet.PortletSession; import javax.portlet.RenderRequest; 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 * @author Massimiliano Assante - ISTI CNR - * @version 1.0 Feb 2014 */ public class ManageVREUsersPortlet extends GenericPortlet { - private static Log _log = LogFactoryUtil.getLog(ManageVREUsersPortlet.class); - - public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { - ScopeHelper.setContext(request); - PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/manageusers_view.jsp"); dispatcher.include(request, response);