no putting user header in Production mode

This commit is contained in:
Francesco Mangiacrapa 2024-05-06 12:31:13 +02:00
parent 13c271ca37
commit 9ec3696203
1 changed files with 13 additions and 6 deletions

View File

@ -20,6 +20,7 @@ import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.GeoportalServiceIdentityProxy;
import org.gcube.portlets.user.geoportaldataviewer.server.util.SessionUtil;
import org.gcube.portlets.user.uriresolvermanager.geoportal.GeoportalExporterAPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -47,7 +48,7 @@ public class GeoportalExporterActionServlet extends HttpServlet {
super.init();
logger.trace(GeoportalExporterActionServlet.class.getSimpleName() + " ready.");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
logger.info("doPost Called");
@ -64,7 +65,8 @@ public class GeoportalExporterActionServlet extends HttpServlet {
*/
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
logger.info("doGet Called");
sendError(resp, "The request cannot be served (via http GET). Please retry by using the Export facility provided by Data-Viewer UI");
sendError(resp,
"The request cannot be served (via http GET). Please retry by using the Export facility provided by Data-Viewer UI");
}
/**
@ -80,8 +82,9 @@ public class GeoportalExporterActionServlet extends HttpServlet {
String ucdID = req.getParameter(GeoportalDataViewerConstants.UCD_ID_PARAMETER);
String contextID = req.getParameter(GeoportalDataViewerConstants.CONTEXT_ID_PARAMETER);
String userID = req.getParameter(GeoportalDataViewerConstants.USER_ID_PARAMETER);
logger.info("serveRequest called with [projectID: " + projectID + ", ucdID: " + ucdID + ", contextID: " + contextID
+ ", userID: " + userID + "]");
// logger.info("serveRequest called with [projectID: " + projectID + ", ucdID: " + ucdID + ", contextID: " + contextID+"]");
logger.info("serveRequest called with [projectID: " + projectID + ", ucdID: " + ucdID + ", contextID: "
+ contextID + ", userID: " + userID + "]");
if (contextID == null || contextID.isEmpty())
sendError(resp, "Bad Request. No context found!");
@ -94,7 +97,10 @@ public class GeoportalExporterActionServlet extends HttpServlet {
// Setting header required to {@PortalContext}
MutableHttpServletRequest mutableRequest = new MutableHttpServletRequest(req);
mutableRequest.putHeader(PortalContext.VRE_ID_ATTR_NAME, contextID);
mutableRequest.putHeader(PortalContext.USER_ID_ATTR_NAME, userID);
if (!SessionUtil.isIntoPortal()) {
logger.info("DEBUG MODE, putting header "+PortalContext.USER_ID_ATTR_NAME);
mutableRequest.putHeader(PortalContext.USER_ID_ATTR_NAME, userID);
}
ScopeProvider.instance.set(scope);
GeoportalServiceIdentityProxy identity = new GeoportalServiceIdentityProxy(mutableRequest);
String theToken = identity.getToken();
@ -104,7 +110,8 @@ public class GeoportalExporterActionServlet extends HttpServlet {
GeoportalExporterAPI geoportalExporterAPI = new GeoportalExporterAPI();
URL urlRequest = geoportalExporterAPI.exportProject("pdf", ucdID, projectID, false);
String urlToRedirect = urlRequest.toString();
logger.info("Performing request to {} with identity description {}", urlToRedirect, identity.getDescription());
logger.info("Performing request to {} with identity description {}", urlToRedirect,
identity.getDescription());
logger.info("Token is {}", theToken.substring(0, 20) + "_MASKED_TOKEN");
InputStream is = performHttpRequestToSGService(urlToRedirect, theIdentity, theToken);