/** * */ package org.gcube.portlets.widgets.ckancontentmoderator.server; import javax.servlet.http.HttpServletRequest; import org.gcube.common.portal.PortalContext; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.liferay.portal.service.UserLocalServiceUtil; // TODO: Auto-generated Javadoc /** * The Class WsUtil. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * * Jun 1, 2021 */ public class WsUtil { protected static Logger logger = LoggerFactory.getLogger(WsUtil.class); /** * Checks if is within portal. * * @return true if you're running into the portal, false if in development */ public static boolean isWithinPortal() { try { UserLocalServiceUtil.getService(); return true; } catch (Exception ex) { logger.trace("Development Mode ON"); return false; } } /** * Gets the current user. * * @param httpServletRequest the http servlet request * @return the current user */ public static GCubeUser getCurrentUser(HttpServletRequest httpServletRequest){ return PortalContext.getConfiguration().getCurrentUser(httpServletRequest); } /** * Gets the current scope. * * @param httpServletRequest the http servlet request * @return the current scope */ public static String getCurrentScope(HttpServletRequest httpServletRequest){ return PortalContext.getConfiguration().getCurrentScope(httpServletRequest); } /** * Gets the current token. * * @param scope the scope * @param username the username * @return the current token */ public static String getCurrentToken(String scope, String username){ return PortalContext.getConfiguration().getCurrentUserToken(scope,username); } }