user timeout session management generating a SessionExpiredException in order to show the session checker dialog and redirect to login

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@100252 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-09-29 13:13:02 +00:00
parent ddf6dc33c4
commit 6a96111918
7 changed files with 202 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.Result;
import org.gcube.portlets.user.databasesmanager.client.datamodel.Row; import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SamplingResultWithFileFromServlet; import org.gcube.portlets.user.databasesmanager.client.datamodel.SamplingResultWithFileFromServlet;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet; import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet;
import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException;
import com.extjs.gxt.ui.client.data.PagingLoadConfig; import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult; import com.extjs.gxt.ui.client.data.PagingLoadResult;
@ -56,7 +57,7 @@ public interface GWTdbManagerService extends RemoteService {
Boolean removeComputation(String submitQueryUID) throws Exception; Boolean removeComputation(String submitQueryUID) throws Exception;
void refreshDataOnServer(String submitQueryUID); void refreshDataOnServer(String submitQueryUID) throws Exception;
GeneralOutputFromServlet refreshDataTree(String ElementType, GeneralOutputFromServlet refreshDataTree(String ElementType,
LinkedHashMap<String, String> inputData, FileModel element) throws Exception; LinkedHashMap<String, String> inputData, FileModel element) throws Exception;

View File

@ -34,6 +34,8 @@ import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SubmitQ
import org.gcube.portlets.user.databasesmanager.client.resources.Images; import org.gcube.portlets.user.databasesmanager.client.resources.Images;
import org.gcube.portlets.user.databasesmanager.client.toolbar.GxtToolbarFunctionality; import org.gcube.portlets.user.databasesmanager.client.toolbar.GxtToolbarFunctionality;
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet; import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import com.extjs.gxt.ui.client.Style; import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.Style.LayoutRegion; import com.extjs.gxt.ui.client.Style.LayoutRegion;
@ -404,6 +406,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
rootLogger.log(Level.SEVERE, rootLogger.log(Level.SEVERE,
"FAILURE RPC LoadTables"); "FAILURE RPC LoadTables");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
// caught.printStackTrace(); // caught.printStackTrace();
callback.onFailure(caught); callback.onFailure(caught);
// hide the dialog // hide the dialog
@ -840,6 +848,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
rootLogger rootLogger
.log(Level.SEVERE, "FAILURE RPC submitQuery "); .log(Level.SEVERE, "FAILURE RPC submitQuery ");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
// Listener<MessageBoxEvent> l = new // Listener<MessageBoxEvent> l = new
// Listener<MessageBoxEvent>() { // Listener<MessageBoxEvent>() {
// public void handleEvent(MessageBoxEvent ce) { // public void handleEvent(MessageBoxEvent ce) {
@ -995,6 +1009,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
rootLogger.log(Level.SEVERE, rootLogger.log(Level.SEVERE,
"FAILURE RPC loadSubmitQueryResult"); "FAILURE RPC loadSubmitQueryResult");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() { Listener<MessageBoxEvent> l = new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent ce) { public void handleEvent(MessageBoxEvent ce) {
@ -1184,6 +1204,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
rootLogger.log(Level.SEVERE, rootLogger.log(Level.SEVERE,
"FAILURE RPC refreshDataOnServer"); "FAILURE RPC refreshDataOnServer");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
} }
@Override @Override
@ -1277,6 +1303,13 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage()); // Window.alert(caught.getMessage());
rootLogger.log(Level.SEVERE, "FAILURE RPC sample"); rootLogger.log(Level.SEVERE, "FAILURE RPC sample");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
if (caught.getMessage() if (caught.getMessage()
.contains("Result not available")) { .contains("Result not available")) {
MessageBox.alert("Warning ", "<br/>Message:" MessageBox.alert("Warning ", "<br/>Message:"
@ -1415,6 +1448,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage()); // Window.alert(caught.getMessage());
rootLogger.log(Level.SEVERE, "FAILURE RPC smartSample"); rootLogger.log(Level.SEVERE, "FAILURE RPC smartSample");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
if (caught.getMessage() if (caught.getMessage()
.contains("The table has 0 rows")) { .contains("The table has 0 rows")) {
MessageBox.alert("Warning ", "<br/>Message:" MessageBox.alert("Warning ", "<br/>Message:"
@ -1518,6 +1557,13 @@ public class GxtBorderLayoutPanel extends ContentPanel {
// Window.alert(caught.getMessage()); // Window.alert(caught.getMessage());
rootLogger rootLogger
.log(Level.SEVERE, "FAILURE RPC randomSample"); .log(Level.SEVERE, "FAILURE RPC randomSample");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
if (caught.getMessage() if (caught.getMessage()
.contains("Result not available")) { .contains("Result not available")) {
MessageBox.alert("Warning ", "<br/>Message:" MessageBox.alert("Warning ", "<br/>Message:"
@ -1572,6 +1618,13 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage()); // Window.alert(caught.getMessage());
rootLogger.log(Level.SEVERE, "FAILURE RPC parseResult"); rootLogger.log(Level.SEVERE, "FAILURE RPC parseResult");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
MessageBox.alert("Error ", MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null); "<br/>Message:" + caught.getMessage(), null);
@ -1922,6 +1975,13 @@ public class GxtBorderLayoutPanel extends ContentPanel {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
rootLogger.log(Level.SEVERE, rootLogger.log(Level.SEVERE,
"FAILURE RPC getTableDetails"); "FAILURE RPC getTableDetails");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
MessageBox.alert("Error ", MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null); "<br/>Message:" + caught.getMessage(), null);

View File

@ -33,6 +33,8 @@ import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbstractImagePrototype; import com.google.gwt.user.client.ui.AbstractImagePrototype;
import org.gcube.portlets.user.databasesmanager.client.datamodel.GeneralOutputFromServlet; import org.gcube.portlets.user.databasesmanager.client.datamodel.GeneralOutputFromServlet;
import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
//class that implements the tree object //class that implements the tree object
public class GxtTreePanel extends LayoutContainer { public class GxtTreePanel extends LayoutContainer {
@ -481,6 +483,13 @@ public class GxtTreePanel extends LayoutContainer {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage()); // Window.alert(caught.getMessage());
rootLogger.log(Level.SEVERE, "FAILURE RPC getResource"); rootLogger.log(Level.SEVERE, "FAILURE RPC getResource");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
MessageBox.alert("Error ", MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null); "<br/>Message:" + caught.getMessage(), null);
@ -520,6 +529,13 @@ public class GxtTreePanel extends LayoutContainer {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage()); // Window.alert(caught.getMessage());
rootLogger.log(Level.SEVERE, "FAILURE RPC getDBInfo"); rootLogger.log(Level.SEVERE, "FAILURE RPC getDBInfo");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
MessageBox.alert("Error ", MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null); "<br/>Message:" + caught.getMessage(), null);
@ -684,6 +700,13 @@ public class GxtTreePanel extends LayoutContainer {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
// Window.alert(caught.getMessage()); // Window.alert(caught.getMessage());
rootLogger.log(Level.SEVERE, "FAILURE RPC getDBSchema"); rootLogger.log(Level.SEVERE, "FAILURE RPC getDBSchema");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
MessageBox.alert("Error ", MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null); "<br/>Message:" + caught.getMessage(), null);
@ -884,6 +907,12 @@ public class GxtTreePanel extends LayoutContainer {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
rootLogger.log(Level.SEVERE, "FAILURE refreshDataTree"); rootLogger.log(Level.SEVERE, "FAILURE refreshDataTree");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
MessageBox.alert("Error ", MessageBox.alert("Error ",
"<br/>Message:" + caught.getMessage(), null); "<br/>Message:" + caught.getMessage(), null);

View File

@ -21,6 +21,8 @@ import org.gcube.portlets.user.databasesmanager.client.events.interfaces.Selecte
import org.gcube.portlets.user.databasesmanager.client.form.GxtFormSubmitQuery; import org.gcube.portlets.user.databasesmanager.client.form.GxtFormSubmitQuery;
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet; import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
import org.gcube.portlets.user.databasesmanager.client.utils.UIDGenerator; import org.gcube.portlets.user.databasesmanager.client.utils.UIDGenerator;
import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException;
import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
import com.extjs.gxt.ui.client.Style.ButtonArrowAlign; import com.extjs.gxt.ui.client.Style.ButtonArrowAlign;
import com.extjs.gxt.ui.client.Style.ButtonScale; import com.extjs.gxt.ui.client.Style.ButtonScale;
@ -341,6 +343,13 @@ public class GxtToolbarFunctionality {
rootLogger rootLogger
.log(Level.SEVERE, .log(Level.SEVERE,
"FAILURE RPC removeComputation"); "FAILURE RPC removeComputation");
if(caught instanceof SessionExpiredException){
rootLogger.log(Level.INFO, "Session expired");
CheckSession.showLogoutDialog();
return;
}
} }
}); });
} }

View File

@ -68,6 +68,8 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet; import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet;
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet; import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil; import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil;
import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException;
import com.extjs.gxt.ui.client.data.BasePagingLoadResult; import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoadConfig; import com.extjs.gxt.ui.client.data.PagingLoadConfig;
import com.extjs.gxt.ui.client.data.PagingLoadResult; import com.extjs.gxt.ui.client.data.PagingLoadResult;
@ -264,6 +266,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// to get resources from IS // to get resources from IS
@Override @Override
public List<FileModel> getResource() throws Exception { public List<FileModel> getResource() throws Exception {
//session check
if(isSessionExpired())
throw new SessionExpiredException();
// initialize variables with application startup // initialize variables with application startup
initVariables(); initVariables();
@ -354,6 +360,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
@Override @Override
public LinkedHashMap<String, FileModel> getDBInfo(String resourceName) public LinkedHashMap<String, FileModel> getDBInfo(String resourceName)
throws Exception { throws Exception {
//session check
if(isSessionExpired())
throw new SessionExpiredException();
// data input // data input
List<Parameter> inputParameters = new ArrayList<Parameter>(); List<Parameter> inputParameters = new ArrayList<Parameter>();
// data output // data output
@ -452,6 +462,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
@Override @Override
public List<FileModel> getDBSchema(LinkedHashMap<String, String> dataInput) public List<FileModel> getDBSchema(LinkedHashMap<String, String> dataInput)
throws Exception { throws Exception {
//session check
if(isSessionExpired())
throw new SessionExpiredException();
// data input // data input
List<Parameter> inputParameters = new ArrayList<Parameter>(); List<Parameter> inputParameters = new ArrayList<Parameter>();
@ -744,6 +758,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// //
// previousSchema = currentSchema; // previousSchema = currentSchema;
// session.setAttribute("previousSchema", previousSchema); // session.setAttribute("previousSchema", previousSchema);
//session check
if(isSessionExpired())
throw new SessionExpiredException();
List<Result> result = new ArrayList<>(); List<Result> result = new ArrayList<>();
@ -814,6 +832,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
LinkedHashMap<String, String> dataDB, String query, LinkedHashMap<String, String> dataDB, String query,
boolean valueReadOnlyQuery, boolean smartCorrectionQuery, boolean valueReadOnlyQuery, boolean smartCorrectionQuery,
String language, String UID) throws Exception { String language, String UID) throws Exception {
//session check
if(isSessionExpired())
throw new SessionExpiredException();
logger.info("dbmanager-> Dialect used for smart correction: " logger.info("dbmanager-> Dialect used for smart correction: "
+ language); + language);
@ -968,6 +990,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
public SamplingResultWithFileFromServlet sample( public SamplingResultWithFileFromServlet sample(
LinkedHashMap<String, String> dataInput, String elementType) LinkedHashMap<String, String> dataInput, String elementType)
throws Exception { throws Exception {
//session check
if(isSessionExpired())
throw new SessionExpiredException();
// data input // data input
List<Parameter> inputParameters = new ArrayList<Parameter>(); List<Parameter> inputParameters = new ArrayList<Parameter>();
// output sample result // output sample result
@ -1071,6 +1097,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
public SamplingResultWithFileFromServlet smartSample( public SamplingResultWithFileFromServlet smartSample(
LinkedHashMap<String, String> dataInput, String elementType) LinkedHashMap<String, String> dataInput, String elementType)
throws Exception { throws Exception {
//session check
if(isSessionExpired())
throw new SessionExpiredException();
// data input // data input
List<Parameter> inputParameters = new ArrayList<Parameter>(); List<Parameter> inputParameters = new ArrayList<Parameter>();
// output sample result // output sample result
@ -1174,6 +1204,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
public SamplingResultWithFileFromServlet randomSample( public SamplingResultWithFileFromServlet randomSample(
LinkedHashMap<String, String> dataInput, String elementType) LinkedHashMap<String, String> dataInput, String elementType)
throws Exception { throws Exception {
//session check
if(isSessionExpired())
throw new SessionExpiredException();
// data input // data input
List<Parameter> inputParameters = new ArrayList<Parameter>(); List<Parameter> inputParameters = new ArrayList<Parameter>();
@ -1277,6 +1311,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
@Override @Override
public LinkedHashMap<String, FileModel> getTableDetails( public LinkedHashMap<String, FileModel> getTableDetails(
LinkedHashMap<String, String> dataInput) throws Exception { LinkedHashMap<String, String> dataInput) throws Exception {
//session check
if(isSessionExpired())
throw new SessionExpiredException();
// data input // data input
List<Parameter> inputParameters = new ArrayList<Parameter>(); List<Parameter> inputParameters = new ArrayList<Parameter>();
// data ouptut // data ouptut
@ -1343,6 +1382,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// parse result for Submit query // parse result for Submit query
public PagingLoadResult<Row> loadSubmitResult(PagingLoadConfig config, public PagingLoadResult<Row> loadSubmitResult(PagingLoadConfig config,
List<String> listAttributes, String UID) throws Exception { List<String> listAttributes, String UID) throws Exception {
//session check
if(isSessionExpired())
throw new SessionExpiredException();
// System.out.println("Server - loadSubmitResultMethod"); // System.out.println("Server - loadSubmitResultMethod");
// data parsed // data parsed
List<Row> data = new ArrayList<Row>(); List<Row> data = new ArrayList<Row>();
@ -1420,6 +1464,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
@Override @Override
public List<Row> parseCVSString(List<Result> result, List<String> attrNames) public List<Row> parseCVSString(List<Result> result, List<String> attrNames)
throws Exception { throws Exception {
//session check
if(isSessionExpired())
throw new SessionExpiredException();
List<Row> rows = new ArrayList<Row>(); List<Row> rows = new ArrayList<Row>();
@ -1915,6 +1963,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// remove the computation // remove the computation
public Boolean removeComputation(String uidSubmitQuery) throws Exception { public Boolean removeComputation(String uidSubmitQuery) throws Exception {
// System.out.println("server UID: " + uidSubmitQuery); // System.out.println("server UID: " + uidSubmitQuery);
//session check
if(isSessionExpired())
throw new SessionExpiredException();
String computationId = null; String computationId = null;
if ((uidSubmitQuery != null) && (!(uidSubmitQuery.equals("")))) { if ((uidSubmitQuery != null) && (!(uidSubmitQuery.equals("")))) {
@ -1960,7 +2013,12 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
return (new Boolean(true)); return (new Boolean(true));
} }
public void refreshDataOnServer(String submitQueryUID) { public void refreshDataOnServer(String submitQueryUID) throws Exception{
//session check
if(isSessionExpired())
throw new SessionExpiredException();
if ((submitQueryUID != null) && (!submitQueryUID.equals(""))) { if ((submitQueryUID != null) && (!submitQueryUID.equals(""))) {
removeResultParsed(submitQueryUID); removeResultParsed(submitQueryUID);
removeResult(submitQueryUID); removeResult(submitQueryUID);
@ -1981,6 +2039,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
public GeneralOutputFromServlet refreshDataTree(String ElementType, public GeneralOutputFromServlet refreshDataTree(String ElementType,
LinkedHashMap<String, String> inputData, FileModel element) LinkedHashMap<String, String> inputData, FileModel element)
throws Exception { throws Exception {
//session check
if(isSessionExpired())
throw new SessionExpiredException();
// // call the method related to the element selected // // call the method related to the element selected
// //
@ -2134,4 +2196,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
return fileName; return fileName;
} }
//to check if the session is expired
private boolean isSessionExpired() throws Exception {
return SessionUtil.isSessionExpired(this.getThreadLocalRequest().getSession());
}
} }

View File

@ -12,6 +12,7 @@ import org.gcube.data.analysis.statisticalmanager.proxies.StatisticalManagerData
import org.gcube.data.analysis.statisticalmanager.proxies.StatisticalManagerFactory; import org.gcube.data.analysis.statisticalmanager.proxies.StatisticalManagerFactory;
import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
/** /**
* @author "Angela Italiano angela.italiano@isti.cnr.it" * @author "Angela Italiano angela.italiano@isti.cnr.it"
* *
@ -19,6 +20,9 @@ import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper;
public class SessionUtil { public class SessionUtil {
protected static Logger logger = Logger.getLogger(SessionUtil.class); protected static Logger logger = Logger.getLogger(SessionUtil.class);
public static final String TEST_USER = "test.user";
public static final String USER = "database.manager";
public static ASLSession getAslSession(HttpSession httpSession) { public static ASLSession getAslSession(HttpSession httpSession) {
String sessionID = httpSession.getId(); String sessionID = httpSession.getId();
@ -28,7 +32,7 @@ public class SessionUtil {
if (user == null) { if (user == null) {
// user = "loredana.liccardo"; // user = "loredana.liccardo";
user = "database.manager"; user = USER;
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, user); httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, user);
ScopeProvider.instance.set("/gcube/devsec/devVRE"); ScopeProvider.instance.set("/gcube/devsec/devVRE");
ASLSession session = SessionManager.getInstance().getASLSession( ASLSession session = SessionManager.getInstance().getASLSession(
@ -46,6 +50,26 @@ public class SessionUtil {
return session; return session;
} }
public static boolean isSessionExpired(HttpSession httpSession) throws Exception {
logger.info("session validating...");
//READING USERNAME FROM ASL SESSION
String userUsername = getAslSession(httpSession).getUsername();
if(userUsername.compareToIgnoreCase(USER)==0){
logger.error("session is expired! username is: "+SessionUtil.USER);
return true; //is USER, session is expired
}
if(userUsername.compareToIgnoreCase(TEST_USER)==0){
logger.error("session is expired! username is: "+SessionUtil.TEST_USER);
return true; //is TEST_USER, session is expired
}
logger.info("session is valid! current username is: "+userUsername);
return false;
}
public static StatisticalManagerFactory getFactory(HttpSession httpSession) { public static StatisticalManagerFactory getFactory(HttpSession httpSession) {
ASLSession session = getAslSession(httpSession); ASLSession session = getAslSession(httpSession);

View File

@ -0,0 +1,9 @@
package org.gcube.portlets.user.databasesmanager.shared;
public class SessionExpiredException extends Exception{
public SessionExpiredException() {
super("Session expired");
}
}