67 lines
2.3 KiB
Java
67 lines
2.3 KiB
Java
package org.gcube.portlets.admin.systemservicedefinition;
|
|
|
|
import javax.portlet.ActionRequest;
|
|
import javax.portlet.RenderRequest;
|
|
import javax.portlet.ResourceRequest;
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
import org.gcube.portlets.admin.systemservicedefinition.util.UserCredentials;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import com.liferay.portal.model.User;
|
|
import com.liferay.portal.util.PortalUtil;
|
|
|
|
/**
|
|
*
|
|
* @author Giancarlo Panichi
|
|
*
|
|
*/
|
|
public class SessionUtil {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(SessionUtil.class);
|
|
|
|
|
|
public static UserCredentials getUserCredentials(RenderRequest renderRequest) throws Exception {
|
|
User theUser = PortalUtil.getUser(renderRequest);
|
|
long userId=theUser.getUserId();
|
|
String username=theUser.getScreenName();
|
|
long groupId = PortalUtil.getScopeGroupId(renderRequest);
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
String currentScope=pContext.getCurrentScope(""+groupId);
|
|
|
|
UserCredentials serviceCredentials = new UserCredentials(userId, username, currentScope);
|
|
logger.info(serviceCredentials.toString());
|
|
return serviceCredentials;
|
|
}
|
|
|
|
public static UserCredentials getUserCredentials(ActionRequest actionRequest) throws Exception {
|
|
User theUser = PortalUtil.getUser(actionRequest);
|
|
long userId=theUser.getUserId();
|
|
String username=theUser.getScreenName();
|
|
long groupId = PortalUtil.getScopeGroupId(actionRequest);
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
String currentScope=pContext.getCurrentScope(""+groupId);
|
|
|
|
UserCredentials serviceCredentials = new UserCredentials(userId, username, currentScope);
|
|
logger.info(serviceCredentials.toString());
|
|
return serviceCredentials;
|
|
}
|
|
|
|
public static UserCredentials getUserCredentials(ResourceRequest resourceRequest) throws Exception{
|
|
|
|
User theUser= PortalUtil.getUser(resourceRequest);
|
|
long userId=theUser.getUserId();
|
|
String username=theUser.getScreenName();
|
|
long groupId = PortalUtil.getScopeGroupId(resourceRequest);
|
|
PortalContext pContext = PortalContext.getConfiguration();
|
|
String currentScope = pContext.getCurrentScope("" + groupId);
|
|
|
|
UserCredentials serviceCredentials = new UserCredentials(userId, username, currentScope);
|
|
logger.info(serviceCredentials.toString());
|
|
return serviceCredentials;
|
|
}
|
|
|
|
}
|