%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.utils.Sessions" %>
<%@ page import="org.crosswire.webtools.RightsAndRoles" %>
<%@ page import="org.crosswire.webtools.RightsAndRoles.User" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%@ page import="org.crosswire.webtools.*" %>
<%!
@Description(value = "Check if session is established and not stale.", name = "auth/session/check")
public static class MyParameters extends Parameters {
@Description(value = "Show usage for this web service", example = "true", defaultValue = "false")
public Boolean help = false;
@Description(value = "internal")
public String r = null;
@Description(value = "internal")
public String ir = null;
}
%>
<%
MyParameters params = new MyParameters().loadFromRequest(request, response, false);
if (params.help) {
params.format = "html";
}
else if (params.getErrors().size() == 0) {
try {
String sessionHash = null;
if (params.getUser() != null) sessionHash = RightsAndRoles.getInstance().getCurrentSession(request, response);
String iframeResponse = params.ir;
if (iframeResponse != null) {
response.setContentType("text/html");
if (sessionHash == null) sessionHash = "";
String callback = iframeResponse.replace("{s}", sessionHash);
if (callback.equals(iframeResponse)) callback = iframeResponse + "(" + sessionHash + ");";
%>
<%
return;
}
String redirURL = params.r;
if (redirURL != null) {
redirURL += (redirURL.indexOf("?") > -1) ? "&" : "?";
redirURL += "vmrcreSession="+sessionHash;
response.sendRedirect(redirURL);
return;
}
if (sessionHash != null) {
User u = params.getUser();
u.setAttribute("sessionHash", sessionHash);
Serializer.output(response, out, params, u);
return;
}
params.addError(0, "no open session");
} catch (Exception e) {
e.printStackTrace();
params.addError(-7, "exception:" + e.toString());
}
}
Serializer.reportErrors(request, response, out, params, true);
%>