From 0c2ba66188cc33f6926b92896a357d3fe0366637 Mon Sep 17 00:00:00 2001 From: "massimiliano.assante" Date: Wed, 23 Mar 2016 11:44:50 +0000 Subject: [PATCH] ported to Liferay 6.2 git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/gcube-loggedin@126093 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 10 -- .../server/LoggedinServiceImpl.java | 131 ++---------------- 2 files changed, 12 insertions(+), 129 deletions(-) diff --git a/pom.xml b/pom.xml index 88c2790..7a589ed 100644 --- a/pom.xml +++ b/pom.xml @@ -104,16 +104,6 @@ aslcore provided - - org.gcube.common - home-library-jcr - provided - - - org.gcube.common - home-library - provided - org.gcube.dvos usermanagement-core diff --git a/src/main/java/org/gcube/portlets/user/gcubeloggedin/server/LoggedinServiceImpl.java b/src/main/java/org/gcube/portlets/user/gcubeloggedin/server/LoggedinServiceImpl.java index b0a2eda..4e950da 100644 --- a/src/main/java/org/gcube/portlets/user/gcubeloggedin/server/LoggedinServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/gcubeloggedin/server/LoggedinServiceImpl.java @@ -9,11 +9,8 @@ import javax.servlet.http.HttpServletRequest; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.SessionManager; -import org.gcube.common.homelibrary.home.HomeLibrary; -import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; -import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException; +import org.gcube.common.portal.CustomAttributeKeys; import org.gcube.common.portal.PortalContext; -import org.gcube.portal.custom.communitymanager.SiteManagerUtil; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portlets.user.gcubeloggedin.client.LoggedinService; import org.gcube.portlets.user.gcubeloggedin.shared.VObject; @@ -32,15 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; -import com.liferay.portal.kernel.bean.BeanLocatorException; -import com.liferay.portal.kernel.exception.PortalException; -import com.liferay.portal.kernel.exception.SystemException; -import com.liferay.portal.model.Group; -import com.liferay.portal.model.User; -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.GroupLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil; /** @@ -50,8 +38,6 @@ import com.liferay.portal.service.UserLocalServiceUtil; public class LoggedinServiceImpl extends RemoteServiceServlet implements LoggedinService { private static final Logger _log = LoggerFactory.getLogger(LoggedinServiceImpl.class); - private static final String MANDATORY_GROUP = "Mandatory"; - private static final String REQUEST_BASED_GROUP = "Requestbasedgroup"; /** * the current ASLSession @@ -90,7 +76,6 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi public VObject getSelectedRE(String portalURL) { ASLSession aslSession = getASLSession(); - String username = aslSession.getUsername(); String friendlyURL = ScopeServiceImpl.extractOrgFriendlyURL(portalURL); if (friendlyURL == null) {//the URL is not a portal URL, we are in devmode. @@ -132,102 +117,20 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi //set the description for the vre if (currSite.getDescription() != null) desc = currSite.getDescription(); - Group currGroup = null; + + Boolean isMandatory = false; try { - currGroup = GroupLocalServiceUtil.getGroup(currSite.getGroupId()); - } catch (PortalException e) { - e.printStackTrace(); - } catch (SystemException e) { - e.printStackTrace(); - } - VREClient vre = new VREClient(name, "", desc, logoURL, "", UserBelongingClient.BELONGING, isEnabled(username, currGroup, MANDATORY_GROUP), isEnabled(username, currGroup, REQUEST_BASED_GROUP)); - return vre; - } - - - private Boolean isEnabled(String username, Group currOrg, String attrToCheck) { - Boolean isEnabled = false; - if (username.compareTo("test.user") == 0) { - _log.warn("Found test.user maybe you are in dev mode, returning ... "); - return true; - } - try { - - long companyId = SiteManagerUtil.getCompany().getCompanyId(); - _log.trace("Setting Thread Permission"); - User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername()); - PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user); - PermissionThreadLocal.setPermissionChecker(permissionChecker); - _log.trace("Setting Permission ok!"); - - User currentUser = SiteManagerUtil.validateUser(username); - if (currOrg.getExpandoBridge().getAttribute(attrToCheck) == null || currOrg.getExpandoBridge().getAttribute(attrToCheck).equals("")) { - _log.trace("Attribute " + attrToCheck + " must be initialized"); - setOrgCustomAttribute(username, currOrg, attrToCheck); - isEnabled = true; - } - else { - String currVal = (String) currOrg.getExpandoBridge().getAttribute(attrToCheck); - isEnabled = (currVal.compareTo("true") == 0); - } - - _log.trace("Setting Thread Permission back to regular"); - permissionChecker = PermissionCheckerFactoryUtil.create(currentUser); - PermissionThreadLocal.setPermissionChecker(permissionChecker); - _log.trace("Setting Permission ok! returning ..."); - _log.debug(" returning *********** isEnabled=" + isEnabled); - return isEnabled; - } catch (BeanLocatorException ex) { - ex.printStackTrace(); - _log.warn("Could not read the property " + attrToCheck + " from LR DB, maybe you are in dev mode, returning true"); - return true; - } - catch (Exception e) { - e.printStackTrace(); - return false; - } - } - /** - * - * @param username - * @param attribute2Set - */ - private void setOrgCustomAttribute(String username, Group currGroup, String attribute2Set) { - User currUser = null; - if (username.compareTo("test.user") == 0) { - _log.warn("Found Test User, returning ... "); - return; - } - try { - long companyId = SiteManagerUtil.getCompany().getCompanyId(); - _log.trace("Setting Thread Permission"); - User user = UserLocalServiceUtil.getUserByScreenName(companyId, ScopeHelper.getAdministratorUsername()); - PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user); - PermissionThreadLocal.setPermissionChecker(permissionChecker); - _log.trace("Setting Permission ok!"); - - _log.debug("Creating and Setting custom attribute for colName " + attribute2Set + " to " +true); - //add the custom attrs - currUser = UserLocalServiceUtil.getUserByScreenName(companyId, username); - - if (! currGroup.getExpandoBridge().hasAttribute(attribute2Set)) - currGroup.getExpandoBridge().addAttribute(attribute2Set); - - currGroup.getExpandoBridge().setAttribute(attribute2Set, "true"); - _log.trace("setAttribute true"); - - - _log.trace("Setting Thread Permission back to regular"); - permissionChecker = PermissionCheckerFactoryUtil.create(currUser); - PermissionThreadLocal.setPermissionChecker(permissionChecker); - } - catch (Exception e) { + isMandatory = (Boolean) gm.readCustomAttr(currSite.getGroupId(), CustomAttributeKeys.MANDATORY.getKeyName()); + } catch (Exception e) { e.printStackTrace(); } + + VREClient vre = new VREClient( + name, "", desc, logoURL, "", UserBelongingClient.BELONGING, + isMandatory, + currSite.isRequestBasedGroup()); + return vre; } - - - /** * * @return the portal basic url, e.g. http://www.foo.com @@ -261,7 +164,6 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi UserManager userM = new LiferayUserManager(); try { userM.dismissUserFromGroup(getCurrentGroupID(), userM.getUserId(username)); - removeUserFromHLGroup(username, getASLSession().getScope()); sendUserUnregisteredNotification(username, getASLSession().getScope(), getPortalBasicUrl(), PortalContext.getConfiguration().getGatewayName()); return "/"; } catch (Exception e) { @@ -292,16 +194,7 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi return -1; } - private void removeUserFromHLGroup(String username, String group) { - try { - org.gcube.common.homelibrary.home.workspace.usermanager.UserManager um = HomeLibrary.getHomeManagerFactory().getUserManager(); - um.removeUserFromGroup(group, username, getASLSession().getUsername()); - } catch (InternalErrorException e) { - _log.error("Failed to get the usermanager from HL. Could not add remove user from the HL group"); - } catch (ItemNotFoundException e1) { - - } - } + protected static ArrayList getAdministratorsEmails(String scope) { LiferayUserManager userManager = new LiferayUserManager();