logging updated
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/session-checker@93542 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
27c7afcaa5
commit
bd032a0ecb
|
@ -17,7 +17,7 @@ import com.google.gwt.user.client.ui.RootPanel;
|
||||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
|
||||||
public class CheckSession {
|
public class CheckSession {
|
||||||
private final int MILLI_SECONDS = 45 * 1000; //45 seconds
|
private final int MILLI_SECONDS = 55 * 1000; //(milli)seconds
|
||||||
|
|
||||||
//for css and images
|
//for css and images
|
||||||
private CheckSessionBundle images = GWT.create(CheckSessionBundle.class);
|
private CheckSessionBundle images = GWT.create(CheckSessionBundle.class);
|
||||||
|
@ -92,7 +92,7 @@ public class CheckSession {
|
||||||
boolean userValid = ( username != null) ? true : false;
|
boolean userValid = ( username != null) ? true : false;
|
||||||
boolean scopeValid = (scope != null) ? true : false;
|
boolean scopeValid = (scope != null) ? true : false;
|
||||||
|
|
||||||
if (! (userValid && scopeValid) ) {
|
if (! (userValid && scopeValid) ) { //if session expired
|
||||||
mask(true);
|
mask(true);
|
||||||
stopPolling();
|
stopPolling();
|
||||||
if (showSessionExpiredDialog) {
|
if (showSessionExpiredDialog) {
|
||||||
|
@ -106,6 +106,10 @@ public class CheckSession {
|
||||||
eventBus.fireEvent(new SessionTimeoutEvent(result));
|
eventBus.fireEvent(new SessionTimeoutEvent(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (result.isDevMode()) {
|
||||||
|
GWT.log("Stopping polling because i think you're in development mode and not in a real portal");
|
||||||
|
stopPolling();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
GWT.log("result null");
|
GWT.log("result null");
|
||||||
|
|
|
@ -17,32 +17,64 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class SessionCheckerServiceImpl extends RemoteServiceServlet implements SessionCheckerService {
|
public class SessionCheckerServiceImpl extends RemoteServiceServlet implements SessionCheckerService {
|
||||||
|
|
||||||
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);
|
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||||
|
}
|
||||||
|
catch (NullPointerException e) {
|
||||||
|
_log.warn("Session is null, perhaps you refreshed your application");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SessionInfoBean checkSession() {
|
public SessionInfoBean checkSession() {
|
||||||
|
if (isFirstTime() == null)
|
||||||
|
setFirstTimeCheck(true);
|
||||||
|
|
||||||
ASLSession session = getASLSession();
|
ASLSession session = getASLSession();
|
||||||
|
if (session == null)
|
||||||
|
return new SessionInfoBean("","", true); //you are in development mode and refreshed the browser
|
||||||
|
|
||||||
String user = session.getUsername();
|
String user = session.getUsername();
|
||||||
String scope = session.getScope();
|
String scope = session.getScope();
|
||||||
_log.trace("Session checked for " + user + " at " + new Date());
|
|
||||||
|
//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) {
|
if (user == null || user.compareTo("") == 0) {
|
||||||
_log.warn("User is null at " + new Date());
|
_log.warn("User is null at " + new Date());
|
||||||
}
|
}
|
||||||
if (scope == null || scope.compareTo("") == 0) {
|
if (scope == null || scope.compareTo("") == 0) {
|
||||||
_log.warn("Scope is null at " + new Date());
|
_log.warn("Scope is null at " + new Date());
|
||||||
}
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ public class SessionInfoBean implements Serializable {
|
||||||
|
|
||||||
private String username;
|
private String username;
|
||||||
private String scope;
|
private String scope;
|
||||||
|
private boolean isDevMode;
|
||||||
|
|
||||||
public SessionInfoBean() {
|
public SessionInfoBean() {
|
||||||
super();
|
super();
|
||||||
|
@ -20,6 +20,15 @@ public class SessionInfoBean implements Serializable {
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public SessionInfoBean(String username, String scope, boolean isDevMode) {
|
||||||
|
super();
|
||||||
|
this.username = username;
|
||||||
|
this.scope = scope;
|
||||||
|
this.isDevMode = isDevMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return username;
|
||||||
|
@ -39,6 +48,16 @@ public class SessionInfoBean implements Serializable {
|
||||||
public void setScope(String scope) {
|
public void setScope(String scope) {
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isDevMode() {
|
||||||
|
return isDevMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setDevMode(boolean isDevMode) {
|
||||||
|
this.isDevMode = isDevMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue