113 lines
3.7 KiB
Java
113 lines
3.7 KiB
Java
/**
|
|
*
|
|
*/
|
|
package org.gcube.portlets.user.workspaceexplorerapp.server;
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
// TODO: Auto-generated Javadoc
|
|
/**
|
|
* The Class WsUtil.
|
|
*
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Sep 13, 2016
|
|
*/
|
|
public class WsUtil {
|
|
|
|
public static final Logger logger = LoggerFactory.getLogger(WsUtil.class);
|
|
public static final String ENVIRONMENT_VARIABLE_SCOPE_NAME = "EnvironmentVariableScope";
|
|
public static final String SESSION_SCOPE = "session_scope";
|
|
|
|
/**
|
|
* Gets the storage hub wrapper.
|
|
*
|
|
* @param httpSession the http session
|
|
* @return the storage hub wrapper
|
|
* @throws Exception the exception
|
|
*/
|
|
public static StorageHubWrapper getStorageHubWrapper(HttpSession httpSession) throws Exception {
|
|
|
|
try {
|
|
String scope = getScope(httpSession);
|
|
// TODO
|
|
String token = "MUST BE PROVIDED";
|
|
logger.debug("Getting " + StorageHubWrapper.class.getSimpleName() +
|
|
" by token: " + token.substring(0, 10) +" MASKED TOKEN" +
|
|
" by using the scope: " + scope);
|
|
|
|
return new StorageHubWrapper(scope, token, false, false, true);
|
|
} catch (Exception e) {
|
|
logger.error("Error during getting storageHub wrapper", e);
|
|
throw new Exception("Error on inizializing the StorageHub");
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Gets the workpace.
|
|
*
|
|
* @param httpSession the http session
|
|
* @return the workpace
|
|
* @throws Exception the exception
|
|
*/
|
|
public static org.gcube.common.storagehubwrapper.server.tohl.Workspace getWorkspace(HttpSession httpSession) throws Exception {
|
|
|
|
try {
|
|
StorageHubWrapper wrapper = getStorageHubWrapper(httpSession);
|
|
return wrapper.getWorkspace();
|
|
} catch (Exception e) {
|
|
logger.error("Error on getting the Workspace", e);
|
|
throw new Exception("Error on getting the Workspace");
|
|
}
|
|
}
|
|
|
|
// /**
|
|
// * Gets the workspace.
|
|
// *
|
|
// * @param httpSession the http session
|
|
// * @return the workspace
|
|
// * @throws InternalErrorException the internal error exception
|
|
// * @throws HomeNotFoundException the home not found exception
|
|
// * @throws WorkspaceFolderNotFoundException the workspace folder not found
|
|
// * exception
|
|
// * @throws UserNotFoundException the user not found exception
|
|
// */
|
|
// public static Workspace getWorkspace(HttpSession httpSession) throws InternalErrorException, HomeNotFoundException,
|
|
// WorkspaceFolderNotFoundException, UserNotFoundException {
|
|
//// ASLSession session = getASLSession(httpSession);
|
|
//
|
|
// String scope = getScope(httpSession);
|
|
// // GET CONTEXT
|
|
// logger.info("Setting scope: " + scope);
|
|
// ScopeProvider.instance.set(scope);
|
|
// return HomeLibrary.getHomeManagerFactory().getHomeManager().getGuestLogin().getWorkspace();
|
|
// }
|
|
|
|
/**
|
|
* Gets the scope.
|
|
*
|
|
* @param httpSession the http session
|
|
* @return the scope
|
|
*/
|
|
public static String getScope(HttpSession httpSession) {
|
|
String scope = (String) httpSession.getAttribute(SESSION_SCOPE);
|
|
logger.info("Variable " + SESSION_SCOPE + " read from httpsession is: " + scope);
|
|
|
|
if (scope == null) {
|
|
logger.info("Variable " + SESSION_SCOPE + " is null reading from web.xml context");
|
|
String variableScopeName = httpSession.getServletContext()
|
|
.getInitParameter(ENVIRONMENT_VARIABLE_SCOPE_NAME);
|
|
logger.info("Found param-value '" + variableScopeName
|
|
+ "' from web context, reading its value from ENVIRONMENT");
|
|
scope = System.getenv(variableScopeName);
|
|
logger.info("Value of " + variableScopeName + " from ENVIRONMENT is: " + scope);
|
|
}
|
|
|
|
httpSession.setAttribute(ENVIRONMENT_VARIABLE_SCOPE_NAME, scope);
|
|
return scope;
|
|
}
|
|
}
|