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:
parent
bd032a0ecb
commit
90fd49f074
9
pom.xml
9
pom.xml
|
@ -12,7 +12,7 @@
|
|||
<groupId>org.gcube.portlets.widgets</groupId>
|
||||
<artifactId>session-checker</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.2.0-SNAPSHOT</version>
|
||||
<version>0.2.4-SNAPSHOT</version>
|
||||
<name>gCube Session Checker Widget</name>
|
||||
<description>
|
||||
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>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>portal-service</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<!-- Generate compiled stuff in the folder used for developing mode -->
|
||||
|
@ -94,7 +99,7 @@
|
|||
<module>org.gcube.portlets.widgets.sessionchecker.client.SessionChecker</module>
|
||||
</configuration>
|
||||
<goals>
|
||||
<!-- <goal>compile</goal> -->
|
||||
<!-- <goal>compile</goal> -->
|
||||
<!-- <goal>test</goal> -->
|
||||
</goals>
|
||||
</execution>
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||
|
||||
/**
|
||||
* 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 String FIRST_TIME = "FIRST_TIME_DEV_MODE";
|
||||
|
||||
/**
|
||||
* the current ASLSession
|
||||
* @return .
|
||||
*/
|
||||
private ASLSession getASLSession() {
|
||||
try {
|
||||
String sessionID = this.getThreadLocalRequest().getSession().getId();
|
||||
String user = (String) this.getThreadLocalRequest().getSession().getAttribute(ScopeHelper.USERNAME_ATTRIBUTE);
|
||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||
}
|
||||
catch (NullPointerException e) {
|
||||
_log.warn("Session is null, perhaps you refreshed your application");
|
||||
return null;
|
||||
}
|
||||
SessionManager manager = SessionManager.getInstance();
|
||||
ASLSession toReturn = manager.getASLSession(sessionID, user);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SessionInfoBean checkSession() {
|
||||
if (isFirstTime() == null)
|
||||
setFirstTimeCheck(true);
|
||||
|
||||
ASLSession session = getASLSession();
|
||||
if (session == null)
|
||||
return new SessionInfoBean("","", true); //you are in development mode and refreshed the browser
|
||||
|
||||
ASLSession session = null;
|
||||
try {
|
||||
session = getASLSession();
|
||||
if (session == null || session.getUsername() == null) {
|
||||
UserLocalServiceUtil.getService();
|
||||
_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 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
|
||||
setFirstTimeCheck(false);
|
||||
_log.trace("Session check OK for " + user + " at " + new Date());
|
||||
if (user == null || user.compareTo("") == 0) {
|
||||
_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());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue