should be ok

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/session-checker@93887 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-03-31 10:50:54 +00:00
parent bd032a0ecb
commit 90fd49f074
2 changed files with 24 additions and 34 deletions

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>session-checker</artifactId> <artifactId>session-checker</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>0.2.0-SNAPSHOT</version> <version>0.2.4-SNAPSHOT</version>
<name>gCube Session Checker Widget</name> <name>gCube Session Checker Widget</name>
<description> <description>
gCube Session Checker Widget is a GWT Widget that can be used to automatically check if the session expired. gCube Session Checker Widget is a GWT Widget that can be used to automatically check if the session expired.
@ -64,6 +64,11 @@
<artifactId>aslcore</artifactId> <artifactId>aslcore</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<!-- Generate compiled stuff in the folder used for developing mode --> <!-- Generate compiled stuff in the folder used for developing mode -->
@ -94,7 +99,7 @@
<module>org.gcube.portlets.widgets.sessionchecker.client.SessionChecker</module> <module>org.gcube.portlets.widgets.sessionchecker.client.SessionChecker</module>
</configuration> </configuration>
<goals> <goals>
<!-- <goal>compile</goal> --> <!-- <goal>compile</goal> -->
<!-- <goal>test</goal> --> <!-- <goal>test</goal> -->
</goals> </goals>
</execution> </execution>

View File

@ -11,6 +11,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.service.UserLocalServiceUtil;
/** /**
* The server side implementation of the RPC service. * The server side implementation of the RPC service.
@ -20,43 +21,37 @@ public class SessionCheckerServiceImpl extends RemoteServiceServlet implements
private static final Logger _log = LoggerFactory.getLogger(SessionCheckerServiceImpl.class); private static final Logger _log = LoggerFactory.getLogger(SessionCheckerServiceImpl.class);
private static final String FIRST_TIME = "FIRST_TIME_DEV_MODE";
/** /**
* the current ASLSession * the current ASLSession
* @return . * @return .
*/ */
private ASLSession getASLSession() { private ASLSession getASLSession() {
try {
String sessionID = this.getThreadLocalRequest().getSession().getId(); String sessionID = this.getThreadLocalRequest().getSession().getId();
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE); String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
return SessionManager.getInstance().getASLSession(sessionID, user); SessionManager manager = SessionManager.getInstance();
} ASLSession toReturn = manager.getASLSession(sessionID, user);
catch (NullPointerException e) { return toReturn;
_log.warn("Session is null, perhaps you refreshed your application");
return null;
}
} }
@Override @Override
public SessionInfoBean checkSession() { public SessionInfoBean checkSession() {
if (isFirstTime() == null) ASLSession session = null;
setFirstTimeCheck(true); try {
session = getASLSession();
ASLSession session = getASLSession(); if (session == null || session.getUsername() == null) {
if (session == null) UserLocalServiceUtil.getService();
return new SessionInfoBean("","", true); //you are in development mode and refreshed the browser _log.warn("Liferay Portal Detected but session Expired");
return new SessionInfoBean("",""); //tells session expired
}
}
catch (Exception e) {
_log.warn("Stopping session polling as you are in dev mode (am I wrong?)");
return new SessionInfoBean("","", true); //tells that you are in development mode
}
String user = session.getUsername(); String user = session.getUsername();
String scope = session.getScope(); String scope = session.getScope();
//check devMode
if (user == null && isFirstTime()) {
_log.warn("Stopping session polling as you are in dev mode (I think, am I wrong?)");
return new SessionInfoBean("","", true); //tells that you are in development mode (you must be unless you're session expires in less than a minute)
}
//else //else
setFirstTimeCheck(false);
_log.trace("Session check OK for " + user + " at " + new Date()); _log.trace("Session check OK for " + user + " at " + new Date());
if (user == null || user.compareTo("") == 0) { if (user == null || user.compareTo("") == 0) {
_log.warn("User is null at " + new Date()); _log.warn("User is null at " + new Date());
@ -67,14 +62,4 @@ public class SessionCheckerServiceImpl extends RemoteServiceServlet implements
return new SessionInfoBean(session.getUsername(), session.getScope()); return new SessionInfoBean(session.getUsername(), session.getScope());
} }
private void setFirstTimeCheck(boolean isFirstTime) {
//_log.trace("setFirstTimeCheck " + isFirstTime);
this.getThreadLocalRequest().getSession().setAttribute(FIRST_TIME, isFirstTime);
}
private Boolean isFirstTime() {
Boolean toReturn = (Boolean) this.getThreadLocalRequest().getSession().getAttribute(FIRST_TIME);
//_log.trace("isFirstTime() " + toReturn);
return toReturn;
}
} }