Removed ASL Session from this component

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-sharing-widget@134832 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-11-25 15:24:20 +00:00
parent 98588ef1be
commit 4e786c7011
7 changed files with 484 additions and 251 deletions

13
pom.xml
View File

@ -14,7 +14,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-sharing-widget</artifactId>
<packaging>jar</packaging>
<version>1.7.0-SNAPSHOT</version>
<version>1.8.0-SNAPSHOT</version>
<name>gCube Workspace Sharing Widget</name>
<description>
gCube Workspace Sharing Widget allows users to share gCube Workspace items
@ -105,23 +105,12 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>custom-portal-handler</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>gcube-widgets</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>accesslogger</artifactId>

View File

@ -6,7 +6,6 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
@ -26,6 +25,7 @@ import org.gcube.common.portal.PortalContext;
import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing;
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService;
import org.gcube.portlets.widgets.workspacesharingwidget.server.notifications.NotificationsProducer;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.PortalContextInfo;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.ScopeUtility;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.UserUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil;
@ -62,7 +62,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
*/
protected GWTWorkspaceSharingBuilder getGWTWorkspaceBuilder()
{
return WsUtil.getGWTWorkspaceSharingBuilder(this.getThreadLocalRequest().getSession());
return WsUtil.getGWTWorkspaceSharingBuilder(this.getThreadLocalRequest());
}
/**
@ -75,7 +75,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
*/
protected Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException
{
return WsUtil.getWorkspace(this.getThreadLocalRequest().getSession());
return WsUtil.getWorkspace(this.getThreadLocalRequest());
}
/**
@ -86,7 +86,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
*/
protected NotificationsProducer getNotificationProducer(HttpServletRequest request){
return WsUtil.getNotificationProducer(WsUtil.getAslSession(this.getThreadLocalRequest().getSession()), request);
return WsUtil.getNotificationProducer(request);
}
/**
@ -96,7 +96,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
*/
protected ScopeUtility getScopeUtilFilter(){
return WsUtil.getScopeUtilFilter(this.getThreadLocalRequest().getSession());
return WsUtil.getScopeUtilFilter(this.getThreadLocalRequest());
}
/**
@ -115,7 +115,8 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
public List<InfoContactModel> getAllContacts(boolean readGroupsFromHL, boolean readGroupsFromPortal) throws Exception {
try {
ASLSession aslSession = WsUtil.getAslSession(this.getThreadLocalRequest().getSession()); //THIS FORCE THE SESSION CREATION
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
logger.info("Get all contacts");
GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder();
@ -140,7 +141,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
logger.info("Liferay User Manager getting list users by group: "+groupId);
List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(userManag.listUsersByGroup(groupId));
*/
List<GCubeUser> users = UserUtil.getOrganizationUsers(aslSession.getScope());
List<GCubeUser> users = UserUtil.getOrganizationUsers(info.getCurrentScope());
if(users==null)
throw new Exception("An error occurred on recovering users from Portal, try again later");
@ -164,10 +165,11 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
PortalContext context = PortalContext.getConfiguration();
logger.info("context.getInfrastructureName(): "+context.getInfrastructureName());
logger.info("aslSession.getGroupName(): "+ aslSession.getGroupName());
logger.info("aslSession.getScope().toString(): "+ aslSession.getScope());
String groupName = context.getCurrentGroupName(this.getThreadLocalRequest());
logger.info("context.getGroupName(): "+ groupName);
logger.info("context.getScope(): "+ info.getCurrentScope());
try{
ScopeUtility scopeUtility = new ScopeUtility(aslSession.getScope());
ScopeUtility scopeUtility = new ScopeUtility(info.getCurrentScope());
if(scopeUtility.getVoName()!=null){
logger.info("VO name is not null, trying to calculate List VO");
@ -175,10 +177,10 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
// String voPath = ConstantsSharing.PATH_SEPARATOR+context.getInfrastructureName() + ConstantsSharing.PATH_SEPARATOR + aslSession.getGroupName() + ConstantsSharing.PATH_SEPARATOR;
listContactsModel.addAll(builder.buildGXTListContactsModelFromVOs(lsVOs, scopeUtility.getVo()));
}else
logger.warn("VO name is null, skipping list VO "+ aslSession.getGroupName());
logger.warn("VO name is null, skipping list VO "+ groupName);
}catch(Exception e){
logger.warn("An error occurred on recovering vo name, skipping list VO "+ aslSession.getGroupName());
logger.warn("An error occurred on recovering vo name, skipping list VO "+ groupName);
}
}
@ -285,8 +287,8 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
*/
@Override
public String getMyLogin(){
ASLSession asl = WsUtil.getAslSession(this.getThreadLocalRequest().getSession());
return asl.getUsername();
PortalContextInfo info = WsUtil.getPortalContext(this.getThreadLocalRequest());
return info.getUsername();
}
/* (non-Javadoc)
@ -350,7 +352,7 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
*/
@Override
public boolean isSessionExpired() throws Exception {
return WsUtil.isSessionExpired(this.getThreadLocalRequest().getSession());
return WsUtil.isSessionExpired(this.getThreadLocalRequest());
}
@ -403,14 +405,12 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
// printContacts(listContacts);
List<String> listLogin = UserUtil.getListLoginByInfoContactModel(listContacts);
WorkspaceSharedFolder sharedFolder = null;
List<InfoContactModel> listSharedContact = null;
boolean sourceFolderIsShared = folder.isShared();
if(sourceFolderIsShared){ //if source folder is already share... retrieve old list of sharing to notify
if(sourceFolderIsShared){ //if source folder is already shared... retrieve old list of sharing to notify
listSharedContact = getListUserSharedByFolderSharedId(folder.getIdentifier());
}

View File

@ -6,7 +6,6 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
@ -17,51 +16,54 @@ import org.gcube.portlets.widgets.workspacesharingwidget.server.util.UserUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
/**
* The Class NotificationsProducer.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
*
* Nov 25, 2016
*/
public class NotificationsProducer {
protected ScopeBean scope;
protected static Logger logger = Logger.getLogger(NotificationsProducer.class);
protected NotificationsManager notificationsMng;
protected ASLSession aslSession;
protected String userId;
/**
* Instantiates a new notifications producer.
*
* @param aslSession the asl session
* @param request the request
*/
public NotificationsProducer(ASLSession aslSession, HttpServletRequest request) {
this.notificationsMng = WsUtil.getNotificationManager(aslSession, request);
this.aslSession = aslSession;
this.userId = aslSession.getUsername();
public NotificationsProducer(HttpServletRequest request) {
this.notificationsMng = WsUtil.getNotificationManager(request);
this.userId = WsUtil.getPortalContext(request).getUsername();
}
/**
* Gets the notifications mng.
*
* @return the notifications mng
*/
public NotificationsManager getNotificationsMng() {
return notificationsMng;
}
/**
* Sets the notification mng.
*
* @param notificationMng the new notification mng
*/
public void setNotificationMng(NotificationsManager notificationMng) {
this.notificationsMng = notificationMng;
}
public ASLSession getAslSession() {
return aslSession;
}
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param sharedFolder
* Runs a new thread to notify the contacts passed in input.
*
* @param listContacts the list contacts
* @param sharedFolder the shared folder
*/
public void notifyFolderSharing(final List<InfoContactModel> listContacts, final WorkspaceSharedFolder sharedFolder) {
@ -103,10 +105,13 @@ public class NotificationsProducer {
/**
* Runs a new thread to notify the contacts passed in input
* @param folderItem
* @param listContacts
* @param sharedFolder
* Runs a new thread to notify the contacts passed in input.
*
* @param listSharedContact the list shared contact
* @param folderItem the folder item
* @param itemOldName the item old name
* @param itemNewName the item new name
* @param idsharedFolder the idshared folder
*/
public void notifyFolderRenamed(final List<InfoContactModel> listSharedContact, final WorkspaceItem folderItem, final String itemOldName, final String itemNewName, final String idsharedFolder) {
@ -159,9 +164,12 @@ public class NotificationsProducer {
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param sharedFolder
* Runs a new thread to notify the contacts passed in input.
*
* @param listSharedContact the list shared contact
* @param previousName the previous name
* @param item the item
* @param sharedFolder the shared folder
*/
public void notifyItemRenamed(final List<InfoContactModel> listSharedContact, final String previousName, final WorkspaceItem item, final WorkspaceSharedFolder sharedFolder) {
@ -203,7 +211,8 @@ public class NotificationsProducer {
/**
* Runs a new thread to notify the new contacts passed in input
* Runs a new thread to notify the new contacts passed in input.
*
* @param listSharedContact - list of contacts already shared
* @param listSharingContact - list of "new" contacts witch share
* @param sharedFolder - the shared folder
@ -295,9 +304,10 @@ public class NotificationsProducer {
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param unSharedFolder
* Runs a new thread to notify the contacts passed in input.
*
* @param listContacts the list contacts
* @param unSharedFolder the un shared folder
*/
public void notifyFolderUnSharing(final List<InfoContactModel> listContacts, final WorkspaceSharedFolder unSharedFolder) {
@ -340,9 +350,11 @@ public class NotificationsProducer {
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param workspaceItem
* Runs a new thread to notify the contacts passed in input.
*
* @param listContacts the list contacts
* @param workspaceItem the workspace item
* @param sharedFolder the shared folder
*/
public void notifyAddedItemToSharing(final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) {
@ -395,9 +407,11 @@ public class NotificationsProducer {
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param workspaceItem
* Runs a new thread to notify the contacts passed in input.
*
* @param listContacts the list contacts
* @param workspaceItem the workspace item
* @param sharedFolder the shared folder
*/
public void notifyUpdatedItemToSharing(final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) {
@ -453,9 +467,11 @@ public class NotificationsProducer {
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param sharedFolder
* Runs a new thread to notify the contacts passed in input.
*
* @param listContacts the list contacts
* @param workspaceItem the workspace item
* @param sharedFolder the shared folder
*/
public void notifyMovedItemToSharing(final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceSharedFolder sharedFolder) {
@ -523,9 +539,11 @@ public class NotificationsProducer {
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param sharedFolder
* Runs a new thread to notify the contacts passed in input.
*
* @param listContacts the list contacts
* @param itemName the item name
* @param sharedFolder the shared folder
*/
public void notifyRemovedItemToSharing(final List<InfoContactModel> listContacts, final String itemName, final WorkspaceSharedFolder sharedFolder) {
@ -586,9 +604,10 @@ public class NotificationsProducer {
}
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param unSharedFolder
* Runs a new thread to notify the contacts passed in input.
*
* @param listContacts the list contacts
* @param folderNameDeleted the folder name deleted
*/
public void notifySharedFolderDeleted(final List<InfoContactModel> listContacts, final String folderNameDeleted) {
@ -633,6 +652,11 @@ public class NotificationsProducer {
//DEBUG
/**
* Prints the contacts.
*
* @param listContacts the list contacts
*/
private void printContacts(List<InfoContactModel> listContacts){
System.out.println("Print contacts");

View File

@ -7,7 +7,6 @@ import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
import org.gcube.common.homelibrary.home.workspace.Workspace;
@ -20,9 +19,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class NotificationsUtil.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @May 27, 2013
*
*/
public class NotificationsUtil {
@ -33,13 +33,12 @@ public class NotificationsUtil {
* Send a notification if an item is added or updated to sharing folder.
*
* @param request the request
* @param httpSession the http session
* @param sourceItem the source item
* @param sourceSharedId the source shared id
* @param folderDestinationItem the folder destination item
* @param isOverwrite the is overwrite
*/
public static void checkSendNotifyChangedItemToShare(HttpServletRequest request, HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) {
public static void checkSendNotifyChangedItemToShare(HttpServletRequest request, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) {
logger.info("checkSendNotifyAddItemToShare");
@ -61,13 +60,13 @@ public class NotificationsUtil {
//if shareChangeCondition is true.. notifies added item to sharing
if(shareChangeCondition){
Workspace workspace = WsUtil.getWorkspace(httpSession);
Workspace workspace = WsUtil.getWorkspace(request);
List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder());
WorkspaceItem destinationSharedFolder = workspace.getItem(folderDestinationItem.getIdSharedFolder());
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession), request);
NotificationsProducer np = new NotificationsProducer(request);
//SWITCH BEETWEEN ADDED OR UPDATED
if(!isOverwrite)
@ -92,11 +91,12 @@ public class NotificationsUtil {
/**
* Gets the list user shared by folder shared id.
*
* @param workspace
* @param idSharedFolder
* @return
* @throws Exception
* @param workspace the workspace
* @param idSharedFolder the id shared folder
* @return the list user shared by folder shared id
* @throws Exception the exception
*/
public static List<InfoContactModel> getListUserSharedByFolderSharedId(Workspace workspace, String idSharedFolder) throws Exception {
@ -133,35 +133,27 @@ public class NotificationsUtil {
}
}
/**
* Check send notify remove item to share.
*
* @param httpSession
* @param sourceItemIsShared
* @param oldItemName
* @param oldItemId
* @param sourceFolderSharedId
* @param request the request
* @param sourceItemIsShared the source item is shared
* @param oldItemName the old item name
* @param oldItemId the old item id
* @param sourceFolderSharedId the source folder shared id
*/
public static void checkSendNotifyRemoveItemToShare(HttpServletRequest request, HttpSession httpSession, final boolean sourceItemIsShared, final String oldItemName, String oldItemId, final String sourceFolderSharedId) {
public static void checkSendNotifyRemoveItemToShare(HttpServletRequest request, final boolean sourceItemIsShared, final String oldItemName, String oldItemId, final String sourceFolderSharedId) {
logger.info("checkNotifyRemoveItemToShare:");
try{
if(!sourceItemIsShared){
logger.info("checkSendNotifyRemoveItemToShare returned, source item is not shared");
return;
}
String idSharedFolder = sourceFolderSharedId!=null?sourceFolderSharedId:"";
// System.out.println("shareChangeCondition remove item: "+ shareChangeCondition);
boolean isRootFolderShared = checkIsRootFolderShared(oldItemId, idSharedFolder);
logger.info("isRootFolderShared is: "+ isRootFolderShared);
@ -170,16 +162,13 @@ public class NotificationsUtil {
return;
}
boolean isSharedFolder = isASharedFolderForId(httpSession,idSharedFolder);
boolean isSharedFolder = isASharedFolderForId(request,idSharedFolder);
logger.info("idSharedFolder is: "+ idSharedFolder +" is shared folder: "+isSharedFolder);
//Notify Removed Item To Sharing?
if(isSharedFolder && !isRootFolderShared){
Workspace workspace = WsUtil.getWorkspace(httpSession);
Workspace workspace = WsUtil.getWorkspace(request);
//get contacts
List<InfoContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, idSharedFolder);
@ -188,7 +177,7 @@ public class NotificationsUtil {
//System.out.println(" name sourceSharedFolder: "+ sourceSharedFolder.getName());
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession), request);
NotificationsProducer np = new NotificationsProducer(request);
if(sourceSharedFolder instanceof WorkspaceSharedFolder)
np.notifyRemovedItemToSharing(listContacts, oldItemName, (WorkspaceSharedFolder) sourceSharedFolder);
@ -206,9 +195,10 @@ public class NotificationsUtil {
}
/**
* Checks if is a root shared folder.
*
* @param wsItem
* @return
* @param wsItem the ws item
* @return true, if is a root shared folder
*/
public static boolean isARootSharedFolder(WorkspaceItem wsItem){
if(wsItem!=null)
@ -216,22 +206,23 @@ public class NotificationsUtil {
return false;
}
/**
* Checks if is a shared folder for id.
*
* @param wsItem
* @return
* @param request the request
* @param itemId the item id
* @return true, if is a shared folder for id
*/
public static boolean isASharedFolderForId(HttpSession httpSession, String itemId){
public static boolean isASharedFolderForId(HttpServletRequest request, String itemId){
if(itemId==null || itemId.isEmpty())
return false;
try {
Workspace workspace = WsUtil.getWorkspace(httpSession);
Workspace workspace = WsUtil.getWorkspace(request);
WorkspaceItem wsItem = workspace.getItem(itemId);
if(wsItem!=null)
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
return false;
@ -244,10 +235,11 @@ public class NotificationsUtil {
/**
* Check is root folder shared.
*
* @param itemId
* @param rootFolderSharedId
* @return
* @param itemId the item id
* @param rootFolderSharedId the root folder shared id
* @return true, if successful
*/
public static boolean checkIsRootFolderShared(String itemId, String rootFolderSharedId) {

View File

@ -0,0 +1,251 @@
/**
*
*/
package org.gcube.portlets.widgets.workspacesharingwidget.server.util;
import java.io.Serializable;
/**
* The Class PortalContextInfo.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Nov 25, 2016
*/
public class PortalContextInfo implements Serializable{
/**
*
*/
private static final long serialVersionUID = -7960309866466555863L;
private String username;
private String userFullName;
private String userEmail;
private String userAvatarID;
private String userAvatarURL;
private String currentScope;
private String userToken;
private long currGroupId;
/**
*
*/
public PortalContextInfo() {
}
/**
* Instantiates a new portal context info.
*
* @param username the username
* @param userFullName the user full name
* @param userEmail the user email
* @param userAvatarID the user avatar id
* @param userAvatarURL the user avatar url
* @param currentScope the current scope
* @param userToken the user token
* @param currGroupId the curr group id
*/
public PortalContextInfo(String username, String userFullName, String userEmail, String userAvatarID, String userAvatarURL, String currentScope, String userToken, long currGroupId) {
this.username = username;
this.userFullName = userFullName;
this.userEmail = userEmail;
this.userAvatarID = userAvatarID;
this.userAvatarURL = userAvatarURL;
this.currentScope = currentScope;
this.userToken = userToken;
this.currGroupId = currGroupId;
}
/**
* @return the username
*/
public String getUsername() {
return username;
}
/**
* @return the userFullName
*/
public String getUserFullName() {
return userFullName;
}
/**
* @return the userEmail
*/
public String getUserEmail() {
return userEmail;
}
/**
* @return the userAvatarID
*/
public String getUserAvatarID() {
return userAvatarID;
}
/**
* @return the userAvatarURL
*/
public String getUserAvatarURL() {
return userAvatarURL;
}
/**
* @return the currentScope
*/
public String getCurrentScope() {
return currentScope;
}
/**
* @return the userToken
*/
public String getUserToken() {
return userToken;
}
/**
* @return the currGroupId
*/
public long getCurrGroupId() {
return currGroupId;
}
/**
* @param username the username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* @param userFullName the userFullName to set
*/
public void setUserFullName(String userFullName) {
this.userFullName = userFullName;
}
/**
* @param userEmail the userEmail to set
*/
public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}
/**
* @param userAvatarID the userAvatarID to set
*/
public void setUserAvatarID(String userAvatarID) {
this.userAvatarID = userAvatarID;
}
/**
* @param userAvatarURL the userAvatarURL to set
*/
public void setUserAvatarURL(String userAvatarURL) {
this.userAvatarURL = userAvatarURL;
}
/**
* @param currentScope the currentScope to set
*/
public void setCurrentScope(String currentScope) {
this.currentScope = currentScope;
}
/**
* @param userToken the userToken to set
*/
public void setUserToken(String userToken) {
this.userToken = userToken;
}
/**
* @param currGroupId the currGroupId to set
*/
public void setCurrGroupId(long currGroupId) {
this.currGroupId = currGroupId;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("PortalContextInfo [username=");
builder.append(username);
builder.append(", userFullName=");
builder.append(userFullName);
builder.append(", userEmail=");
builder.append(userEmail);
builder.append(", userAvatarID=");
builder.append(userAvatarID);
builder.append(", userAvatarURL=");
builder.append(userAvatarURL);
builder.append(", currentScope=");
builder.append(currentScope);
builder.append(", userToken=");
builder.append(userToken);
builder.append(", currGroupId=");
builder.append(currGroupId);
builder.append("]");
return builder.toString();
}
}

View File

@ -19,11 +19,12 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class UserUtil.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Aug 3, 2015
* Nov 25, 2016
*/
public class UserUtil {
@ -38,16 +39,13 @@ public class UserUtil {
* @return the user full name
*/
public static String getUserFullName(String portalLogin){
// return user.getPortalLogin(); //for testing in eclipse
// logger.trace("Finding full name for: "+portalLogin);
if(portalLogin==null)
return "";
logger.info("Get user full name for: "+portalLogin);
logger.info("Into portal: "+WsUtil.isWithinPortal());
if (portalLogin.compareTo(WsUtil.TEST_USER) != 0 && WsUtil.isWithinPortal()) { //skip test.user
if (portalLogin != null && WsUtil.isWithinPortal()) { //skip test.user
GCubeUser curr = null;
@ -56,9 +54,9 @@ public class UserUtil {
curr = um.getUserByUsername(portalLogin);
} catch (UserManagementSystemException e) {
logger.error("An error occurred in getUserFullName "+e,e);
logger.warn("An error occurred in getUserFullName "+e);
} catch (UserRetrievalFault e) {
logger.error("An error occurred in getUserFullName "+e,e);
logger.warn("An error occurred in getUserFullName "+e);
}
}catch (Exception e) {
logger.error("An error occurred in getUserFullName "+e,e);
@ -67,7 +65,6 @@ public class UserUtil {
}
if (curr != null){
// logger.trace("Return "+curr.getFullname() +" full name for: "+portalLogin);
return curr.getFullname();
}
}else{

View File

@ -10,8 +10,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang.StringUtils;
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;
@ -21,13 +19,14 @@ import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
import org.gcube.portlets.widgets.workspacesharingwidget.server.GWTWorkspaceSharingBuilder;
import org.gcube.portlets.widgets.workspacesharingwidget.server.notifications.NotificationsProducer;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VO;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.system.VRE;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -35,35 +34,22 @@ import com.liferay.portal.service.UserLocalServiceUtil;
/**
* The Class WsUtil.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Feb 18, 2014
*
* Nov 25, 2016
*/
public class WsUtil {
public static final String USERNAME_ATTRIBUTE = ScopeHelper.USERNAME_ATTRIBUTE;
public static final String WORKSPACEBUILDER_ATTRIBUTE = "WORKSPACE_SHARING_BUILDER_ATTRIBUTE";
public static final String NOTIFICATION_MANAGER = "NOTIFICATION_SHARING_MANAGER";
public static final String NOTIFICATION_PRODUCER = "NOTIFICATION_SHARING_PRODUCER";
public static final String WORKSPACE_SCOPE_UTIL = "WORKSPACE_SHARING_SCOPE_UTIL";
public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl"; //USE THE SAME OF WORKSPACE
// public static final String TEST_SCOPE = "/gcube/devsec";
// public static final String TEST_USER = "pasquale.pagano";
public static final String TEST_SCOPE = "/gcube/devsec";
// public static final String TEST_USER = "federico.defaveri";
// public static final String TEST_USER = "massimiliano.assante";
// public static final String TEST_USER = "pasquale.pagano";
// public static final String TEST_USER = "francesco.mangiacrapa";
// public static final String TEST_USER_FULL_NAME = "Francesco Mangiacrapa";
// public static final String TEST_USER = "aureliano.gentile";
public static final String TEST_USER = "test.user";
// public static final String TEST_USER = "antonio.gioia";
public static final String TEST_USER_FULL_NAME = "Test User";
protected static Logger logger = LoggerFactory.getLogger(WsUtil.class);
// public static boolean withoutPortal = false;
/**
* Checks if is within portal.
*
* @return true if you're running into the portal, false if in development
*/
@ -78,76 +64,46 @@ public class WsUtil {
}
}
public static ASLSession getAslSession(HttpSession httpSession)
{
String sessionID = httpSession.getId();
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
ASLSession session;
if (user == null) {
/*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
* COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
user=TEST_USER;
//UNCOMMENT THIS IN DEVELOP ENVIROMENT
// user = "francesco.mangiacrapa";
logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
logger.warn("session id: "+sessionID);
logger.warn("TEST_USER: "+user);
logger.warn("TEST_SCOPE: "+TEST_SCOPE);
logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE);
session = SessionManager.getInstance().getASLSession(sessionID, user);
session.setScope(TEST_SCOPE);
//MANDATORY FOR SOCIAL LIBRARY
session.setUserAvatarId(user + "Avatar");
session.setUserFullName(TEST_USER_FULL_NAME);
session.setUserEmailAddress(user + "@mail.test");
//SET HTTP SESSION ATTRIBUTE
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
// withoutPortal = true;
return session;
}else if(user.compareToIgnoreCase(TEST_USER)==0){
// withoutPortal = true;
//COMMENT THIS IN PRODUCTION ENVIROMENT
// }else if(user.compareToIgnoreCase("francesco.mangiacrapa")==0){
// withoutPortal = false;
// END UNCOMMENT
}else{
// withoutPortal = false;
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
/**
* Gets the portal context.
*
* @param httpSession
* @return true if current username into ASL session is WsUtil.TEST_USER, false otherwise
* @throws Exception
* @param httpServletRequest the http servlet request
* @return the portal context
*/
public static boolean isSessionExpired(HttpSession httpSession) throws Exception {
logger.info("workspace session validating...");
//READING USERNAME FROM ASL SESSION
String userUsername = getAslSession(httpSession).getUsername();
boolean isTestUser = userUsername.compareTo(WsUtil.TEST_USER)==0;
//TODO UNCOMMENT THIS FOR RELEASE
logger.info("Is "+WsUtil.TEST_USER+" test user? "+isTestUser);
if(isTestUser){
logger.error("workspace session is expired! username is: "+WsUtil.TEST_USER);
return true; //is TEST_USER, session is expired
}
logger.info("workspace session is valid! current username is: "+userUsername);
return false;
public static PortalContextInfo getPortalContext(HttpServletRequest httpServletRequest){
PortalContext pContext = PortalContext.getConfiguration();
//USER
GCubeUser user = pContext.getCurrentUser(httpServletRequest);
String username = user.getUsername();
String fullName = user.getFullname();
String email = user.getEmail();
String avatarID = user.getUserAvatarId();
String avatarURL = user.getUserAvatarURL();
//SESSION
String currentScope = pContext.getCurrentScope(httpServletRequest);
String userToken = pContext.getCurrentUserToken(httpServletRequest);
long currGroupId = pContext.getCurrentGroupId(httpServletRequest);
return new PortalContextInfo(username, fullName, email, avatarID, avatarURL, currentScope, userToken, currGroupId);
}
/**
* Checks if is session expired.
*
* @param httpServletRequest the http servlet request
* @return true, if is session expired
* @throws Exception the exception
*/
public static boolean isSessionExpired(HttpServletRequest httpServletRequest) throws Exception {
logger.trace("workspace session validating...");
PortalContextInfo info = getPortalContext(httpServletRequest);
return info.getUsername()==null;
}
/**
* Gets the vres from infrastructure.
*
* @param infrastructure the infrastructure name
* @param startScopes the starting scopes
@ -177,18 +133,26 @@ public class WsUtil {
return toReturn;
}
public static Workspace getWorkspace(final HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException
/**
* Gets the workspace.
*
* @param httpServletRequest the http servlet request
* @return the workspace
* @throws InternalErrorException the internal error exception
* @throws HomeNotFoundException the home not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
public static Workspace getWorkspace(HttpServletRequest httpServletRequest) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException
{
logger.trace("Get Workspace");
PortalContextInfo info = getPortalContext(httpServletRequest);
logger.trace("PortalContextInfo: "+info);
logger.info("Get Workspace");
final ASLSession session = getAslSession(httpSession);
logger.info("ASLSession scope: "+session.getScope() + " username: "+session.getUsername());
ScopeProvider.instance.set(info.getCurrentScope());
logger.trace("Scope provider instancied");
ScopeProvider.instance.set(session.getScope());
logger.info("Scope provider instancied");
Workspace workspace = HomeLibrary.getUserWorkspace(session.getUsername());
Workspace workspace = HomeLibrary.getUserWorkspace(info.getUsername());
HttpSession session = httpServletRequest.getSession();
if (session.getAttribute(WORKSPACEBUILDER_ATTRIBUTE) == null)
{
@ -198,38 +162,37 @@ public class WsUtil {
//ADDED 03/09/2013
//TODO IS GROUP?
builder.setUserLogged(new InfoContactModel(session.getUsername(), session.getUsername(), session.getUserFullName(), false));
builder.setUserLogged(new InfoContactModel(info.getUsername(), info.getUsername(), info.getUserFullName(), false));
session.setAttribute(WORKSPACEBUILDER_ATTRIBUTE, builder);
}
return workspace;
}
/**
* Gets the notification manager.
*
* @param session the session
* @param request the request
* @param httpServletRequest the http servlet request
* @return the notification manager
*/
public static NotificationsManager getNotificationManager(ASLSession session, HttpServletRequest request)
public static NotificationsManager getNotificationManager(HttpServletRequest httpServletRequest)
{
PortalContextInfo info = getPortalContext(httpServletRequest);
HttpSession session = httpServletRequest.getSession();
NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER);
if (notifMng == null) {
try{
logger.info("Create new NotificationsManager for user: "+session.getUsername());
logger.info("Create new NotificationsManager for user: "+info.getUsername());
logger.info("New ApplicationNotificationsManager with portlet class name: "+NOTIFICATION_PORTLET_CLASS_ID);
SocialNetworkingSite site = new SocialNetworkingSite(request);
SocialNetworkingUser curser = new SocialNetworkingUser(session.getUsername(), session.getUserEmailAddress(), session.getUserFullName(), session.getUserAvatarId());
notifMng = new ApplicationNotificationsManager(site, session.getScope(), curser, NOTIFICATION_PORTLET_CLASS_ID);
SocialNetworkingSite site = new SocialNetworkingSite(httpServletRequest);
SocialNetworkingUser curser = new SocialNetworkingUser(info.getUsername(), info.getUserEmail(), info.getUserFullName(), info.getUserAvatarID());
notifMng = new ApplicationNotificationsManager(site, info.getCurrentScope(), curser, NOTIFICATION_PORTLET_CLASS_ID);
session.setAttribute(NOTIFICATION_MANAGER, notifMng);
}catch (Exception e) {
logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e);
logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+info.getUsername(),e);
}
}
@ -240,56 +203,71 @@ public class WsUtil {
/**
* Gets the notification producer.
*
* @param session the session
* @param request the request
* @param httpServletRequest the http servlet request
* @return the notification producer
*/
public static NotificationsProducer getNotificationProducer(ASLSession session, HttpServletRequest request)
public static NotificationsProducer getNotificationProducer(HttpServletRequest httpServletRequest)
{
PortalContextInfo info = getPortalContext(httpServletRequest);
HttpSession session = httpServletRequest.getSession();
NotificationsProducer notifProducer = (NotificationsProducer) session.getAttribute(NOTIFICATION_PRODUCER);
if (notifProducer == null) {
logger.info("Create new Notification Producer for user: "+session.getUsername());
notifProducer = new NotificationsProducer(session, request);
logger.info("Create new Notification Producer for user: "+info.getUsername());
notifProducer = new NotificationsProducer(httpServletRequest);
session.setAttribute(NOTIFICATION_PRODUCER, notifProducer);
}
return notifProducer;
}
public static String getUserId(HttpSession httpSession) {
/**
* Gets the user id.
*
* @param httpServletRequest the http servlet request
* @return the user id
*/
public static String getUserId(HttpServletRequest httpServletRequest) {
ASLSession session = getAslSession(httpSession);
return session.getUsername();
PortalContextInfo info = getPortalContext(httpServletRequest);
return info.getUsername();
}
public static boolean isVRE(ASLSession session){
/**
* Checks if is vre.
*
* @param scope the scope
* @return true, if is vre
*/
public static boolean isVRE(String scope){
String currentScope = session.getScopeName();
int slashCount = StringUtils.countMatches(currentScope, "/");
int slashCount = StringUtils.countMatches(scope, "/");
if(slashCount < 3){
logger.info("currentScope is not VRE");
logger.trace("currentScope is not VRE");
return false;
}
logger.info("currentScope is VRE");
logger.trace("currentScope is VRE");
return true;
}
public static ScopeUtility getScopeUtilFilter(HttpSession httpSession){
ASLSession session = getAslSession(httpSession);
/**
* Gets the scope util filter.
*
* @param httpServletRequest the http servlet request
* @return the scope util filter
*/
public static ScopeUtility getScopeUtilFilter(HttpServletRequest httpServletRequest){
PortalContextInfo info = getPortalContext(httpServletRequest);
ScopeUtility scopeUtil = null;
try{
scopeUtil = (ScopeUtility) session.getAttribute(WsUtil.WORKSPACE_SCOPE_UTIL);
scopeUtil = (ScopeUtility) httpServletRequest.getSession().getAttribute(WsUtil.WORKSPACE_SCOPE_UTIL);
if(scopeUtil==null){
scopeUtil = new ScopeUtility(session.getScopeName());
scopeUtil = new ScopeUtility(info.getCurrentScope());
}
}catch (Exception e) {
@ -300,15 +278,17 @@ public class WsUtil {
}
/**
* @param session
* @return
* Gets the GWT workspace sharing builder.
*
* @param httpServletRequest the http servlet request
* @return the GWT workspace sharing builder
*/
public static GWTWorkspaceSharingBuilder getGWTWorkspaceSharingBuilder(HttpSession httpSession) {
ASLSession session = getAslSession(httpSession);
public static GWTWorkspaceSharingBuilder getGWTWorkspaceSharingBuilder(HttpServletRequest httpServletRequest) {
PortalContextInfo info = getPortalContext(httpServletRequest);
GWTWorkspaceSharingBuilder builder = null;
try{
builder = (GWTWorkspaceSharingBuilder) session.getAttribute(WsUtil.WORKSPACEBUILDER_ATTRIBUTE);
builder = (GWTWorkspaceSharingBuilder) httpServletRequest.getSession().getAttribute(WsUtil.WORKSPACEBUILDER_ATTRIBUTE);
if(builder==null)
return new GWTWorkspaceSharingBuilder();