ref 6278:DataMiner - getUserId doesn't work when session expires and Reload is performed

https://support.d4science.org/issues/6278

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/data-miner-manager@142350 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-02-07 17:19:38 +00:00
parent 70e94abbff
commit 4e5f62d95a
9 changed files with 145 additions and 105 deletions

View File

@ -1,4 +1,8 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.portlets-user.data-miner-manager.1-3-0"
date="2016-02-15">
<Change>Updated PortalContext [ticket #6278]</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.data-miner-manager.1-2-0" <Changeset component="org.gcube.portlets-user.data-miner-manager.1-2-0"
date="2016-12-01"> date="2016-12-01">
<Change>Updated Output support</Change> <Change>Updated Output support</Change>

View File

@ -502,9 +502,7 @@ public class ComputationsExecutedPanel extends FramedPanel {
+ Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER + Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER
+ "=" + selectedItem.getName() + "&" + "=" + selectedItem.getName() + "&"
+ Constants.CURR_GROUP_ID + "=" + Constants.CURR_GROUP_ID + "="
+ GCubeClientContext.getCurrentContextId() + GCubeClientContext.getCurrentContextId());
+ "&" + Constants.CURR_USER_ID + "="
+ GCubeClientContext.getCurrentUserId());
Log.debug("Retrieved link: " + actionUrl); Log.debug("Retrieved link: " + actionUrl);
Window.open(actionUrl.toString(), selectedItem.getName(), ""); Window.open(actionUrl.toString(), selectedItem.getName(), "");

View File

@ -425,9 +425,7 @@ public class InputDataSetsPanel extends FramedPanel {
+ Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER + Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER
+ "=" + selectedItem.getName() + "&" + "=" + selectedItem.getName() + "&"
+ Constants.CURR_GROUP_ID + "=" + Constants.CURR_GROUP_ID + "="
+ GCubeClientContext.getCurrentContextId() + GCubeClientContext.getCurrentContextId());
+ "&" + Constants.CURR_USER_ID + "="
+ GCubeClientContext.getCurrentUserId());
Log.debug("Retrieved link: " + actionUrl); Log.debug("Retrieved link: " + actionUrl);
Window.open(actionUrl.toString(), selectedItem.getName(), ""); Window.open(actionUrl.toString(), selectedItem.getName(), "");

View File

@ -424,9 +424,7 @@ public class OutputDataSetsPanel extends FramedPanel {
+ Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER + Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER
+ "=" + selectedItem.getName() + "&" + "=" + selectedItem.getName() + "&"
+ Constants.CURR_GROUP_ID + "=" + Constants.CURR_GROUP_ID + "="
+ GCubeClientContext.getCurrentContextId() + GCubeClientContext.getCurrentContextId());
+ "&" + Constants.CURR_USER_ID + "="
+ GCubeClientContext.getCurrentUserId());
Log.debug("Retrieved link: " + actionUrl); Log.debug("Retrieved link: " + actionUrl);
Window.open(actionUrl.toString(), selectedItem.getName(), ""); Window.open(actionUrl.toString(), selectedItem.getName(), "");

View File

@ -11,6 +11,7 @@ import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest; import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse; import javax.portlet.RenderResponse;
import org.gcube.common.portal.PortalContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -44,8 +45,8 @@ public class DataMinerManager extends GenericPortlet {
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
logger.trace("DataMinerManager loading from JSP: "+VIEW_JSP); logger.trace("DataMinerManager loading from JSP: "+VIEW_JSP);
//logger.trace("setting context using ScopeHelper"); logger.trace("Setting user in session using PortalContext");
//ScopeHelper.setContext(request); PortalContext.setUserInSession(request);
logger.trace("passing to the render"); logger.trace("passing to the render");
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP); PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(VIEW_JSP);

View File

@ -4,7 +4,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletRequest;
import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletService; import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletService;
import org.gcube.portlets.user.dataminermanager.server.dmservice.SClient; import org.gcube.portlets.user.dataminermanager.server.dmservice.SClient;
@ -24,8 +24,6 @@ import org.gcube.portlets.user.dataminermanager.shared.process.OperatorsClassifi
import org.gcube.portlets.user.dataminermanager.shared.session.UserInfo; import org.gcube.portlets.user.dataminermanager.shared.session.UserInfo;
import org.gcube.portlets.user.dataminermanager.shared.workspace.DataMinerWorkArea; import org.gcube.portlets.user.dataminermanager.shared.workspace.DataMinerWorkArea;
import org.gcube.portlets.user.dataminermanager.shared.workspace.ItemDescription; import org.gcube.portlets.user.dataminermanager.shared.workspace.ItemDescription;
//import org.gcube.portlets.user.tdw.server.datasource.DataSourceFactoryRegistry; //import org.gcube.portlets.user.tdw.server.datasource.DataSourceFactoryRegistry;
//import org.gcube.portlets.widgets.file_dw_import_wizard.server.file.TargetRegistry; //import org.gcube.portlets.widgets.file_dw_import_wizard.server.file.TargetRegistry;
import org.gcube.portlets.widgets.wsexplorer.shared.Item; import org.gcube.portlets.widgets.wsexplorer.shared.Item;
@ -93,9 +91,11 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
throws ServiceException { throws ServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); ServiceCredentials serviceCredentials = SessionUtil
SClient smClient = SessionUtil.getSClient(serviceCredentials, session); .getServiceCredentials(httpRequest);
SClient smClient = SessionUtil.getSClient(httpRequest,
serviceCredentials);
List<OperatorsClassification> list = smClient List<OperatorsClassification> list = smClient
.getOperatorsClassifications(); .getOperatorsClassifications();
return list; return list;
@ -115,10 +115,13 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
public List<Parameter> getParameters(Operator operator) public List<Parameter> getParameters(Operator operator)
throws ServiceException { throws ServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
SClient smClient = SessionUtil.getSClient(serviceCredentials, session);
SClient smClient = SessionUtil.getSClient(httpRequest,
serviceCredentials);
List<Parameter> list = smClient.getInputParameters(operator); List<Parameter> list = smClient.getInputParameters(operator);
return list; return list;
} catch (ServiceException e) { } catch (ServiceException e) {
@ -136,10 +139,14 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
public ComputationId startComputation(Operator operator) public ComputationId startComputation(Operator operator)
throws ServiceException { throws ServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
SClient smClient = SessionUtil.getSClient(httpRequest,
serviceCredentials);
logger.debug("StartComputation(): [ operator=" + operator + "]"); logger.debug("StartComputation(): [ operator=" + operator + "]");
SClient smClient = SessionUtil.getSClient(serviceCredentials, session);
ComputationId computationId = smClient.startComputation(operator); ComputationId computationId = smClient.startComputation(operator);
return computationId; return computationId;
} catch (ServiceException e) { } catch (ServiceException e) {
@ -157,12 +164,16 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
public ComputationId resubmit(ItemDescription itemDescription) public ComputationId resubmit(ItemDescription itemDescription)
throws ServiceException { throws ServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
Map<String, String> properties = StorageUtil.getProperties( Map<String, String> properties = StorageUtil.getProperties(
serviceCredentials.getUserName(), itemDescription.getId()); serviceCredentials.getUserName(), itemDescription.getId());
logger.debug("Properties: " + properties); logger.debug("Properties: " + properties);
SClient smClient = SessionUtil.getSClient(serviceCredentials, session);
SClient smClient = SessionUtil.getSClient(httpRequest,
serviceCredentials);
ComputationId computationId = smClient ComputationId computationId = smClient
.resubmitComputation(properties); .resubmitComputation(properties);
return computationId; return computationId;
@ -181,9 +192,11 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
public ComputationStatus getComputationStatus(ComputationId computationId) public ComputationStatus getComputationStatus(ComputationId computationId)
throws ServiceException { throws ServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); ServiceCredentials serviceCredentials = SessionUtil
SClient smClient = SessionUtil.getSClient(serviceCredentials, session); .getServiceCredentials(httpRequest);
SClient smClient = SessionUtil.getSClient(httpRequest,
serviceCredentials);
ComputationStatus computationStatus = smClient ComputationStatus computationStatus = smClient
.getComputationStatus(computationId); .getComputationStatus(computationId);
return computationStatus; return computationStatus;
@ -203,7 +216,9 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
public void deleteItem(ItemDescription itemDescription) public void deleteItem(ItemDescription itemDescription)
throws ServiceException { throws ServiceException {
try { try {
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
logger.debug("DeleteItem(): " + itemDescription); logger.debug("DeleteItem(): " + itemDescription);
StorageUtil.deleteItem(serviceCredentials.getUserName(), StorageUtil.deleteItem(serviceCredentials.getUserName(),
itemDescription.getId()); itemDescription.getId());
@ -223,7 +238,9 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
public TableItemSimple retrieveTableInformation(Item item) public TableItemSimple retrieveTableInformation(Item item)
throws ServiceException { throws ServiceException {
try { try {
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
logger.debug("retrieveTableInformation(): " + item); logger.debug("retrieveTableInformation(): " + item);
TableReader tableReader = new TableReader(serviceCredentials, item); TableReader tableReader = new TableReader(serviceCredentials, item);
TableItemSimple tableItemSimple = tableReader.getTableItemSimple(); TableItemSimple tableItemSimple = tableReader.getTableItemSimple();
@ -241,7 +258,9 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
@Override @Override
public DataMinerWorkArea getDataMinerWorkArea() throws ServiceException { public DataMinerWorkArea getDataMinerWorkArea() throws ServiceException {
try { try {
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
logger.debug("getDataMinerWorkArea()"); logger.debug("getDataMinerWorkArea()");
DataMinerWorkAreaManager dataMinerWorkAreaManager = new DataMinerWorkAreaManager( DataMinerWorkAreaManager dataMinerWorkAreaManager = new DataMinerWorkAreaManager(
serviceCredentials); serviceCredentials);
@ -261,10 +280,12 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
public String getPublicLink(ItemDescription itemDescription) public String getPublicLink(ItemDescription itemDescription)
throws ServiceException { throws ServiceException {
try { try {
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
logger.debug("GetPublicLink(): " + itemDescription); logger.debug("GetPublicLink(): " + itemDescription);
String link = StorageUtil.getPublicLink(serviceCredentials.getUserName(), String link = StorageUtil.getPublicLink(
itemDescription.getId()); serviceCredentials.getUserName(), itemDescription.getId());
return link; return link;
} catch (ServiceException e) { } catch (ServiceException e) {
@ -281,10 +302,12 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
public String cancelComputation(ComputationId computationId) public String cancelComputation(ComputationId computationId)
throws ServiceException { throws ServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
logger.debug("CancelComputation(): " + computationId); logger.debug("CancelComputation(): " + computationId);
SClient smClient = SessionUtil.getSClient(serviceCredentials, session); SClient smClient = SessionUtil.getSClient(httpRequest,
serviceCredentials);
String result = smClient.cancelComputation(computationId); String result = smClient.cancelComputation(computationId);
// SessionUtil.putSClient(session, smClient); // SessionUtil.putSClient(session, smClient);
return result; return result;
@ -302,10 +325,12 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
public OutputData getOutputDataByComputationId(ComputationId computationId) public OutputData getOutputDataByComputationId(ComputationId computationId)
throws ServiceException { throws ServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
Log.debug("getOutputDataByComputationId: " + computationId); Log.debug("getOutputDataByComputationId: " + computationId);
SClient smClient = SessionUtil.getSClient(serviceCredentials, session); SClient smClient = SessionUtil.getSClient(httpRequest,
serviceCredentials);
OutputData outputData = smClient OutputData outputData = smClient
.getOutputDataByComputationId(computationId); .getOutputDataByComputationId(computationId);
Log.debug("OutputData: " + outputData); Log.debug("OutputData: " + outputData);
@ -326,15 +351,17 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
public ComputationData getComputationData(ItemDescription itemDescription) public ComputationData getComputationData(ItemDescription itemDescription)
throws ServiceException { throws ServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
logger.debug("OutputDataByComputationItemt(): " + itemDescription); logger.debug("OutputDataByComputationItemt(): " + itemDescription);
Map<String, String> properties = StorageUtil.getProperties( Map<String, String> properties = StorageUtil.getProperties(
serviceCredentials.getUserName(), itemDescription.getId()); serviceCredentials.getUserName(), itemDescription.getId());
logger.debug("Properties: " + properties); logger.debug("Properties: " + properties);
SClient smClient = SessionUtil.getSClient(serviceCredentials, session); SClient smClient = SessionUtil.getSClient(httpRequest,
serviceCredentials);
ComputationData computationData = smClient ComputationData computationData = smClient
.getComputationDataByComputationProperties(properties); .getComputationDataByComputationProperties(properties);
return computationData; return computationData;
@ -354,8 +381,9 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
public String cancelComputation(ItemDescription itemDescription) public String cancelComputation(ItemDescription itemDescription)
throws ServiceException { throws ServiceException {
try { try {
HttpSession session = this.getThreadLocalRequest().getSession(); HttpServletRequest httpRequest = this.getThreadLocalRequest();
ServiceCredentials serviceCredentials=SessionUtil.getServiceCredentials(this.getThreadLocalRequest()); ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(httpRequest);
logger.debug("CancelComputation(): " + itemDescription); logger.debug("CancelComputation(): " + itemDescription);
String compId = itemDescription.getName(); String compId = itemDescription.getName();
if (compId == null) { if (compId == null) {
@ -371,7 +399,8 @@ public class DataMinerManagerServiceImpl extends RemoteServiceServlet implements
} }
ComputationId computationId = new ComputationId(); ComputationId computationId = new ComputationId();
computationId.setId(compId); computationId.setId(compId);
SClient smClient = SessionUtil.getSClient(serviceCredentials, session); SClient smClient = SessionUtil.getSClient(httpRequest,
serviceCredentials);
String result = smClient.cancelComputation(computationId); String result = smClient.cancelComputation(computationId);
return result; return result;
} catch (ServiceException e) { } catch (ServiceException e) {

View File

@ -12,7 +12,6 @@ import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.dataminermanager.server.storage.StorageUtil; import org.gcube.portlets.user.dataminermanager.server.storage.StorageUtil;
import org.gcube.portlets.user.dataminermanager.server.util.ServiceCredentials; import org.gcube.portlets.user.dataminermanager.server.util.ServiceCredentials;
import org.gcube.portlets.user.dataminermanager.shared.Constants; import org.gcube.portlets.user.dataminermanager.shared.Constants;
@ -76,13 +75,30 @@ public class DownloadFolderServlet extends HttpServlet {
} }
logger.debug("DownloadFolderServlet session id: " + session.getId()); logger.debug("DownloadFolderServlet session id: " + session.getId());
String scopeGroupId = request.getParameter(Constants.CURR_GROUP_ID); ServiceCredentials serviceCredentials;
String currUserId = request.getParameter(Constants.CURR_USER_ID);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(request, scopeGroupId, currUserId);
ScopeProvider.instance.set(serviceCredentials.getScope()); String scopeGroupId = request.getHeader(Constants.CURR_GROUP_ID);
if (scopeGroupId == null || scopeGroupId.isEmpty()) {
scopeGroupId = request.getParameter(Constants.CURR_GROUP_ID);
if (scopeGroupId == null || scopeGroupId.isEmpty()) {
logger.error("CURR_GROUP_ID is null, it is a mandatory parameter in custom servlet: "
+ scopeGroupId);
throw new ServletException(
"CURR_GROUP_ID is null, it is a mandatory parameter in custom servlet: "
+ scopeGroupId);
}
}
try {
serviceCredentials = SessionUtil.getServiceCredentials(request,
scopeGroupId);
} catch (Exception e) {
logger.error(
"Error retrieving credentials:"
+ e.getLocalizedMessage(), e);
throw new ServletException(e.getLocalizedMessage());
}
String itemId = request String itemId = request
.getParameter(Constants.DOWNLOAD_FOLDER_SERVLET_ITEM_ID_PARAMETER); .getParameter(Constants.DOWNLOAD_FOLDER_SERVLET_ITEM_ID_PARAMETER);

View File

@ -9,7 +9,9 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext; import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.dataminermanager.server.dmservice.SClient; import org.gcube.portlets.user.dataminermanager.server.dmservice.SClient;
import org.gcube.portlets.user.dataminermanager.server.dmservice.SClient4WPSBuilder; import org.gcube.portlets.user.dataminermanager.server.dmservice.SClient4WPSBuilder;
import org.gcube.portlets.user.dataminermanager.server.dmservice.SClientBuilder; import org.gcube.portlets.user.dataminermanager.server.dmservice.SClientBuilder;
@ -18,7 +20,6 @@ import org.gcube.portlets.user.dataminermanager.server.util.ServiceCredentials;
import org.gcube.portlets.user.dataminermanager.shared.Constants; import org.gcube.portlets.user.dataminermanager.shared.Constants;
import org.gcube.portlets.user.dataminermanager.shared.exception.ServiceException; import org.gcube.portlets.user.dataminermanager.shared.exception.ServiceException;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeUser; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
@ -32,14 +33,27 @@ public class SessionUtil {
private static final Logger logger = Logger.getLogger(SessionUtil.class); private static final Logger logger = Logger.getLogger(SessionUtil.class);
/**
*
* @param httpServletRequest
* @return
* @throws TDGWTServiceException
*/
public static ServiceCredentials getServiceCredentials( public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest) throws ServiceException { HttpServletRequest httpServletRequest) throws ServiceException {
return getServiceCredentials(httpServletRequest, null, null); return getServiceCredentials(httpServletRequest, null);
} }
/**
*
* @param httpServletRequest
* @param scopeGroupId
* @return
* @throws TDGWTServiceException
*/
public static ServiceCredentials getServiceCredentials( public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest, String scopeGroupId, HttpServletRequest httpServletRequest, String scopeGroupId)
String currUserId) throws ServiceException { throws ServiceException {
ServiceCredentials sCredentials = null; ServiceCredentials sCredentials = null;
String userName = null; String userName = null;
@ -50,17 +64,29 @@ public class SessionUtil {
if (Constants.DEBUG_MODE) { if (Constants.DEBUG_MODE) {
logger.info("No credential found in session, use test user!"); logger.info("No credential found in session, use test user!");
/*
* InfoLocale infoLocale = getInfoLocale(httpServletRequest, null);
* Locale locale = new Locale(infoLocale.getLanguage());
*
* ResourceBundle messages = ResourceBundle.getBundle(
* StatAlgoImporterServiceMessagesConstants.TDGWTServiceMessages,
* locale);
*/
userName = Constants.DEFAULT_USER; userName = Constants.DEFAULT_USER;
scope = Constants.DEFAULT_SCOPE; scope = Constants.DEFAULT_SCOPE;
token = Constants.DEFAULT_TOKEN; token = Constants.DEFAULT_TOKEN;
logger.info("Set SecurityToken: " + token);
SecurityTokenProvider.instance.set(token);
logger.info("Set ScopeProvider: " + scope);
ScopeProvider.instance.set(scope);
sCredentials = new ServiceCredentials(userName, scope, token); sCredentials = new ServiceCredentials(userName, scope, token);
} else { } else {
logger.info("Retrieving credential in session!"); logger.info("Retrieving credential in session!");
PortalContext pContext = PortalContext.getConfiguration(); PortalContext pContext = PortalContext.getConfiguration();
boolean hasScopeGroupId = false; boolean hasScopeGroupId = false;
boolean hasCurrUserId = false;
if (scopeGroupId != null && !scopeGroupId.isEmpty()) { if (scopeGroupId != null && !scopeGroupId.isEmpty()) {
hasScopeGroupId = true; hasScopeGroupId = true;
@ -69,42 +95,19 @@ public class SessionUtil {
hasScopeGroupId = false; hasScopeGroupId = false;
} }
if (currUserId != null && !currUserId.isEmpty()) {
hasCurrUserId = true;
} else {
hasCurrUserId = false;
}
if (hasScopeGroupId) { if (hasScopeGroupId) {
scope = pContext.getCurrentScope(scopeGroupId); scope = pContext.getCurrentScope(scopeGroupId);
} else { } else {
scope = pContext.getCurrentScope(httpServletRequest); scope = pContext.getCurrentScope(httpServletRequest);
} }
logger.debug("Scope: " + scope);
if (scope == null || scope.isEmpty()) { if (scope == null || scope.isEmpty()) {
String error = "Error retrieving scope: " + scope; String error = "Error retrieving scope: " + scope;
logger.error(error); logger.error(error);
throw new ServiceException(error); throw new ServiceException(error);
} }
GCubeUser gCubeUser = null; GCubeUser gCubeUser = pContext.getCurrentUser(httpServletRequest);
if (hasCurrUserId) {
try {
gCubeUser = new LiferayUserManager().getUserById(Long
.valueOf(currUserId));
} catch (Exception e) {
String error = "Error retrieving gCubeUser for: [userId= "
+ currUserId + ", scope: " + scope + "]";
logger.error(error, e);
throw new ServiceException(error);
}
} else {
gCubeUser = pContext.getCurrentUser(httpServletRequest);
}
if (gCubeUser == null) { if (gCubeUser == null) {
String error = "Error retrieving gCubeUser in scope " + scope String error = "Error retrieving gCubeUser in scope " + scope
@ -114,7 +117,6 @@ public class SessionUtil {
} }
userName = gCubeUser.getUsername(); userName = gCubeUser.getUsername();
logger.debug("UserName: " + userName);
if (userName == null || userName.isEmpty()) { if (userName == null || userName.isEmpty()) {
String error = "Error retrieving username in scope " + scope String error = "Error retrieving username in scope " + scope
@ -123,22 +125,8 @@ public class SessionUtil {
throw new ServiceException(error); throw new ServiceException(error);
} }
if (hasCurrUserId) { token = pContext.getCurrentUserToken(scope, userName);
try {
token = pContext.getCurrentUserToken(scope,
Long.valueOf(currUserId));
} catch (Exception e) {
String error = "Error retrieving token for: [userId= "
+ currUserId + ", scope: " + scope + "]";
logger.error(error, e);
throw new ServiceException(error);
}
} else {
token = pContext.getCurrentUserToken(httpServletRequest);
}
logger.debug("Token: " + token);
if (token == null || token.isEmpty()) { if (token == null || token.isEmpty()) {
String error = "Error retrieving token for " + userName String error = "Error retrieving token for " + userName
+ " in " + scope + ": " + token; + " in " + scope + ": " + token;
@ -155,6 +143,10 @@ public class SessionUtil {
String email = gCubeUser.getEmail(); String email = gCubeUser.getEmail();
if (hasScopeGroupId) { if (hasScopeGroupId) {
logger.info("Set SecurityToken: " + token);
SecurityTokenProvider.instance.set(token);
logger.info("Set ScopeProvider: " + scope);
ScopeProvider.instance.set(scope);
groupId = scopeGroupId; groupId = scopeGroupId;
@ -198,13 +190,16 @@ public class SessionUtil {
return sCredentials; return sCredentials;
} }
public static SClient getSClient(ServiceCredentials serviceCredentials, public static SClient getSClient(HttpServletRequest httpRequest,
HttpSession session) throws Exception { ServiceCredentials serviceCredentials) throws Exception {
if (serviceCredentials == null) { if (serviceCredentials == null) {
logger.error("ServiceCredentials is null!"); logger.error("ServiceCredentials is null!");
throw new ServiceException("Service Credentials is null!"); throw new ServiceException("Service Credentials is null!");
} }
HttpSession session=httpRequest.getSession();
SClient sClient; SClient sClient;
Object obj = session.getAttribute(Constants.SClientMap); Object obj = session.getAttribute(Constants.SClientMap);

View File

@ -8,5 +8,6 @@
<layout-cacheable>false</layout-cacheable> <layout-cacheable>false</layout-cacheable>
<instanceable>false</instanceable> <instanceable>false</instanceable>
<ajaxable>false</ajaxable> <ajaxable>false</ajaxable>
<css-class-wrapper>DataMinerManagerCSS</css-class-wrapper>
</portlet> </portlet>
</liferay-portlet-app> </liferay-portlet-app>