+ request.setResponseHeader("Expires","Wed, 01 Jan 1997 12:00:00 GMT");
+ request.setResponseHeader("Cache-Control","private,no-store,no-cache,max-age=0");
+ if (m_contentType == "application/json") {
+ request.setContentType(m_contentType.c_str());
+ return doJSON(request);
+ }
+ request.setContentType("text/html; charset=UTF-8");
+ return doHTML(request);
+}
+
+pair<bool,long> SessionHandler::doJSON(SPRequest& request) const
+{
+ stringstream s;
+
+ Session* session = nullptr;
+ try {
+ session = request.getSession(); // caches the locked session in the request so it's unlocked automatically
+ if (!session) {
+ s << "{}" << endl;
+ return make_pair(true, request.sendResponse(s));
+ }
+ }
+ catch (std::exception& ex) {
+ m_log.info("exception accessing user session: %s", ex.what());
+ s << "{}" << endl;
+ return make_pair(true, request.sendError(s));
+ }
+
+ s << "{ ";
+ s << "\"expiration\": ";
+ if (session->getExpiration())
+ s << ((session->getExpiration() - time(nullptr)) / 60);
+ else
+ s << 0;
+
+ if (session->getClientAddress()) {
+ s << ", \"client_address\": ";
+ json_safe(s, session->getClientAddress());
+ }
+
+ if (session->getProtocol()) {
+ s << ", \"protocol\": ";
+ json_safe(s, session->getProtocol());
+ }
+
+ pair<bool,bool> stdvars = request.getRequestSettings().first->getBool("exportStdVars");
+ if (!stdvars.first || stdvars.second) {
+ if (session->getEntityID()) {
+ s << ", \"identity_provider\": ";
+ json_safe(s, session->getEntityID());
+ }
+
+ if (session->getAuthnInstant()) {
+ s << ", \"authn_instant\": ";
+ json_safe(s, session->getAuthnInstant());
+ }