READY FOR TESTING
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/widgets/session-checker@93479 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e007395e4e
commit
4016d716a4
|
@ -24,6 +24,7 @@
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -11,7 +11,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>war</packaging>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>gCube Session Checker Widget</name>
|
<name>gCube Session Checker Widget</name>
|
||||||
<description>
|
<description>
|
||||||
|
|
|
@ -1,14 +1,28 @@
|
||||||
package org.gcube.portlets.widgets.sessionchecker.client;
|
package org.gcube.portlets.widgets.sessionchecker.client;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog;
|
||||||
|
import org.gcube.portlets.widgets.sessionchecker.client.bundle.CheckSessionBundle;
|
||||||
|
import org.gcube.portlets.widgets.sessionchecker.client.elements.Div;
|
||||||
import org.gcube.portlets.widgets.sessionchecker.shared.SessionInfoBean;
|
import org.gcube.portlets.widgets.sessionchecker.shared.SessionInfoBean;
|
||||||
|
|
||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.dom.client.Style.Display;
|
||||||
import com.google.gwt.user.client.Timer;
|
import com.google.gwt.user.client.Timer;
|
||||||
import com.google.gwt.user.client.Window;
|
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
import com.google.gwt.user.client.ui.HTML;
|
||||||
|
import com.google.gwt.user.client.ui.HasAlignment;
|
||||||
|
import com.google.gwt.user.client.ui.RootPanel;
|
||||||
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
|
||||||
public class CheckSession {
|
public class CheckSession {
|
||||||
private final int MILLI_SECONDS = 60 * 1000; //60 seconds
|
private final int MILLI_SECONDS = 45 * 1000; //45 seconds
|
||||||
|
|
||||||
|
//for css and images
|
||||||
|
private CheckSessionBundle images = GWT.create(CheckSessionBundle.class);
|
||||||
|
|
||||||
|
static {
|
||||||
|
CheckSessionBundle.INSTANCE.css().ensureInjected();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Create a remote service proxy to talk to the server-side Greeting service.
|
* Create a remote service proxy to talk to the server-side Greeting service.
|
||||||
*/
|
*/
|
||||||
|
@ -18,15 +32,23 @@ public class CheckSession {
|
||||||
private String scope;
|
private String scope;
|
||||||
private Timer t;
|
private Timer t;
|
||||||
|
|
||||||
private static CheckSession singleton;
|
//needed to mask the page when session id up!
|
||||||
|
private Div maskDiv = new Div();
|
||||||
|
|
||||||
|
private static CheckSession singleton;
|
||||||
|
|
||||||
public static CheckSession getInstance() {
|
public static CheckSession getInstance() {
|
||||||
if (singleton == null)
|
if (singleton == null)
|
||||||
singleton = new CheckSession();
|
singleton = new CheckSession();
|
||||||
return singleton;
|
return singleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CheckSession() {
|
private CheckSession() {
|
||||||
|
|
||||||
|
addMaskDiv2DOM();
|
||||||
|
maskDiv.setStyleName("div-mask");
|
||||||
|
|
||||||
|
//polling timer
|
||||||
t = new Timer() {
|
t = new Timer() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -34,15 +56,22 @@ public class CheckSession {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(SessionInfoBean result) {
|
public void onSuccess(SessionInfoBean result) {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
|
||||||
username = result.getUsername();
|
username = result.getUsername();
|
||||||
scope = result.getScope();
|
scope = result.getScope();
|
||||||
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) ) {
|
||||||
Window.alert("Session Expired");
|
mask(true);
|
||||||
|
stopPolling();
|
||||||
|
showLogoutDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
GWT.log("result null");
|
||||||
|
stopPolling();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) { }
|
public void onFailure(Throwable caught) { }
|
||||||
|
@ -50,7 +79,43 @@ public class CheckSession {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addMaskDiv2DOM() {
|
||||||
|
RootPanel.get().insert(maskDiv, 0);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* set visible the masking div setting/unsetting css display property
|
||||||
|
* @param mask
|
||||||
|
*/
|
||||||
|
private void mask(boolean mask) {
|
||||||
|
GWT.log("Masking");
|
||||||
|
if (mask)
|
||||||
|
maskDiv.getElement().getStyle().setDisplay(Display.BLOCK);
|
||||||
|
else
|
||||||
|
maskDiv.getElement().getStyle().setDisplay(Display.NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showLogoutDialog() {
|
||||||
|
GCubeDialog dlg = new GCubeDialog();
|
||||||
|
dlg.setText("Your Session Expired!");
|
||||||
|
|
||||||
|
VerticalPanel topPanel = new VerticalPanel();
|
||||||
|
topPanel.setPixelSize(420, 290);
|
||||||
|
|
||||||
|
topPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER);
|
||||||
|
|
||||||
|
HTML toShow = new HTML("<div style=\"margin-top: 40px;\">"
|
||||||
|
+ "<img style=\"margin: 0; vertical-align: middle; \" src='" + images.expired().getSafeUri().asString() + "'>"
|
||||||
|
+ "</div><div style=\"font-size: 18px; height: 20px; padding-top: 20px;\">"
|
||||||
|
+ "Please <a href=\"javascript: location.reload();\">reload<a/> this page.</div>");
|
||||||
|
|
||||||
|
|
||||||
|
topPanel.add(toShow);
|
||||||
|
dlg.add(topPanel);
|
||||||
|
dlg.center();
|
||||||
|
dlg.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return username;
|
||||||
|
|
|
@ -8,5 +8,6 @@ import com.google.gwt.core.client.EntryPoint;
|
||||||
public class SessionChecker implements EntryPoint {
|
public class SessionChecker implements EntryPoint {
|
||||||
|
|
||||||
public void onModuleLoad() {
|
public void onModuleLoad() {
|
||||||
|
CheckSession.getInstance().startPolling();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
@external div-mask;
|
||||||
|
|
||||||
|
.div-mask {
|
||||||
|
position: fixed;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
background-color: rgba(0,0,0,.15);
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
display: none;
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.gcube.portlets.widgets.sessionchecker.client.bundle;
|
||||||
|
|
||||||
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.resources.client.ClientBundle;
|
||||||
|
import com.google.gwt.resources.client.CssResource;
|
||||||
|
import com.google.gwt.resources.client.ImageResource;
|
||||||
|
|
||||||
|
public interface CheckSessionBundle extends ClientBundle {
|
||||||
|
|
||||||
|
public static final CheckSessionBundle INSTANCE = GWT.create(CheckSessionBundle.class);
|
||||||
|
|
||||||
|
@Source("CheckSession.css")
|
||||||
|
public CssResource css();
|
||||||
|
|
||||||
|
@Source("session_expired.jpg")
|
||||||
|
ImageResource expired();
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 5.0 KiB |
|
@ -0,0 +1,27 @@
|
||||||
|
package org.gcube.portlets.widgets.sessionchecker.client.elements;
|
||||||
|
|
||||||
|
import com.google.gwt.user.client.DOM;
|
||||||
|
import com.google.gwt.user.client.ui.HTML;
|
||||||
|
import com.google.gwt.user.client.ui.HasText;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Massimiliano Assante, ISTI-CNR
|
||||||
|
* @version 0.1 Sep 2012
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Div extends HTML implements HasText {
|
||||||
|
|
||||||
|
public Div() {
|
||||||
|
super(DOM.createElement("div"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Div(String text) {
|
||||||
|
this();
|
||||||
|
setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAttribute(String name, String value) {
|
||||||
|
super.getElement().setAttribute(name, value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,11 +24,8 @@ public class SessionCheckerServiceImpl extends RemoteServiceServlet implements
|
||||||
* @return .
|
* @return .
|
||||||
*/
|
*/
|
||||||
private ASLSession getASLSession() {
|
private ASLSession getASLSession() {
|
||||||
System.out.println("\n\n\n*****+ ASL checksession");
|
|
||||||
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);
|
||||||
|
|
||||||
System.out.println("ASL checksession ID = " +sessionID);
|
|
||||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue