#include <xmltooling/util/XMLHelper.h>
using namespace shibsp;
+using namespace xmltooling::logging;
using namespace xmltooling;
using namespace std;
namespace shibsp {
SHIBSP_DLLLOCAL PluginManager<ServiceProvider,string,const DOMElement*>::Factory XMLServiceProviderFactory;
- long SHIBSP_DLLLOCAL sendError(SPRequest& request, const Application* app, const char* page, TemplateParameters& tp, bool mayRedirect=true)
+ long SHIBSP_DLLLOCAL sendError(
+ Category& log, SPRequest& request, const Application* app, const char* page, TemplateParameters& tp, bool mayRedirect=true
+ )
{
// The properties we need can be set in the RequestMap, or the Errors element.
bool mderror = dynamic_cast<const opensaml::saml2md::MetadataException*>(tp.getRichException())!=NULL;
redirectErrors = settings.first->getString("redirectErrors");
}
catch (exception& ex) {
- request.log(SPRequest::SPError, ex.what());
+ log.error(ex.what());
}
if (mayRedirect) {
return request.sendResponse(msg, HTTPResponse::XMLTOOLING_HTTP_STATUS_UNAUTHORIZED);
}
- string errstr = string("sendError could not process error template (") + page + ")";
- request.log(SPRequest::SPError, errstr);
+ log.error("sendError could not process error template (%s)", page);
istringstream msg("Internal Server Error. Please contact the site administrator.");
return request.sendError(msg);
}
#ifdef _DEBUG
xmltooling::NDC ndc("doAuthentication");
#endif
+ Category& log = Category::getInstance(SHIBSP_LOGCAT".ServiceProvider");
const Application* app=NULL;
string targetURL = request.getRequestURL();
else {
TemplateParameters tp;
tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
- return make_pair(true,sendError(request, app, "ssl", tp, false));
+ return make_pair(true,sendError(log, request, app, "ssl", tp, false));
}
}
}
session = request.getSession();
}
catch (exception& e) {
- request.log(SPRequest::SPWarn, string("error during session lookup: ") + e.what());
+ log.warn("error during session lookup: %s", e.what());
// If it's not a retryable session failure, we throw to the outer handler for reporting.
if (dynamic_cast<opensaml::RetryableProfileException*>(&e)==NULL)
throw;
const Handler* initiator=NULL;
if (requireSessionWith.first) {
initiator=app->getSessionInitiatorById(requireSessionWith.second);
- if (!initiator)
+ if (!initiator) {
throw ConfigurationException(
- "No session initiator found with id ($1), check requireSessionWith command.",
- params(1,requireSessionWith.second)
+ "No session initiator found with id ($1), check requireSessionWith command.", params(1,requireSessionWith.second)
);
+ }
}
else {
initiator=app->getDefaultSessionInitiator();
// We're done. Everything is okay. Nothing to report. Nothing to do..
// Let the caller decide how to proceed.
- request.log(SPRequest::SPDebug, "doAuthentication succeeded");
+ log.debug("doAuthentication succeeded");
return make_pair(false,0L);
}
catch (exception& e) {
TemplateParameters tp(&e);
tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
- return make_pair(true,sendError(request, app, "session", tp));
+ return make_pair(true,sendError(log, request, app, "session", tp));
}
}
#ifdef _DEBUG
xmltooling::NDC ndc("doAuthorization");
#endif
+ Category& log = Category::getInstance(SHIBSP_LOGCAT".ServiceProvider");
const Application* app=NULL;
string targetURL = request.getRequestURL();
session = request.getSession(false);
}
catch (exception& e) {
- request.log(SPRequest::SPWarn, string("unable to obtain session to pass to access control provider: ") + e.what());
+ log.warn("unable to obtain session to pass to access control provider: %s", e.what());
}
Locker acllock(settings.second);
switch (settings.second->authorized(request,session)) {
case AccessControl::shib_acl_true:
- request.log(SPRequest::SPDebug, "access control provider granted access");
+ log.debug("access control provider granted access");
return make_pair(true,request.returnOK());
case AccessControl::shib_acl_false:
{
- request.log(SPRequest::SPWarn, "access control provider denied access");
+ log.warn("access control provider denied access");
TemplateParameters tp;
tp.m_map["requestURL"] = targetURL;
- return make_pair(true,sendError(request, app, "access", tp, false));
+ return make_pair(true,sendError(log, request, app, "access", tp, false));
}
default:
catch (exception& e) {
TemplateParameters tp(&e);
tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
- return make_pair(true,sendError(request, app, "access", tp));
+ return make_pair(true,sendError(log, request, app, "access", tp));
}
}
#ifdef _DEBUG
xmltooling::NDC ndc("doExport");
#endif
+ Category& log = Category::getInstance(SHIBSP_LOGCAT".ServiceProvider");
const Application* app=NULL;
string targetURL = request.getRequestURL();
session = request.getSession(false);
}
catch (exception& e) {
- request.log(SPRequest::SPWarn, string("unable to obtain session to export to request: ") + e.what());
+ log.warn("unable to obtain session to export to request: %s", e.what());
// If we have to have a session, then this is a fatal error.
if (requireSession)
throw;
const PropertySet* sessions=app->getPropertySet("Sessions");
pair<bool,const char*> exportLocation = sessions ? sessions->getString("exportLocation") : pair<bool,const char*>(false,NULL);
if (!exportLocation.first)
- request.log(SPRequest::SPWarn, "can't export assertions without an exportLocation Sessions property");
+ log.warn("can't export assertions without an exportLocation Sessions property");
else {
const URLEncoder* encoder = XMLToolingConfig::getConfig().getURLEncoder();
string exportName = "Shib-Assertion-00";
catch (exception& e) {
TemplateParameters tp(&e);
tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
- return make_pair(true,sendError(request, app, "session", tp));
+ return make_pair(true,sendError(log, request, app, "session", tp));
}
}
#ifdef _DEBUG
xmltooling::NDC ndc("doHandler");
#endif
+ Category& log = Category::getInstance(SHIBSP_LOGCAT".ServiceProvider");
const Application* app=NULL;
string targetURL = request.getRequestURL();
RequestMapper::Settings settings = request.getRequestSettings();
app = &(request.getApplication());
+ // If not SSL, check to see if we should block or redirect it.
+ if (!request.isSecure()) {
+ pair<bool,const char*> redirectToSSL = settings.first->getString("redirectToSSL");
+ if (redirectToSSL.first) {
+#ifdef HAVE_STRCASECMP
+ if (!strcasecmp("GET",request.getMethod()) || !strcasecmp("HEAD",request.getMethod())) {
+#else
+ if (!stricmp("GET",request.getMethod()) || !stricmp("HEAD",request.getMethod())) {
+#endif
+ // Compute the new target URL
+ string redirectURL = string("https://") + request.getHostname();
+ if (strcmp(redirectToSSL.second,"443")) {
+ redirectURL = redirectURL + ':' + redirectToSSL.second;
+ }
+ redirectURL += request.getRequestURI();
+ return make_pair(true, request.sendRedirect(redirectURL.c_str()));
+ }
+ else {
+ TemplateParameters tp;
+ tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
+ return make_pair(true,sendError(log, request, app, "ssl", tp, false));
+ }
+ }
+ }
+
const char* handlerURL=request.getHandlerURL(targetURL.c_str());
if (!handlerURL)
throw ConfigurationException("Cannot determine handler from resource URL, check configuration.");
catch (exception& e) {
TemplateParameters tp(&e);
tp.m_map["requestURL"] = targetURL.substr(0,targetURL.find('?'));
- return make_pair(true,sendError(request, app, "session", tp));
+ return make_pair(true,sendError(log, request, app, "session", tp));
}
}