X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=nsapi_shib%2Fnsapi_shib.cpp;h=77190182a35c3a70b9eeec48a899966d040dde77;hb=87f8c5b1383ce267075073f2184f282450e16e09;hp=d837aaaccc158afc566b376d484799a7a71ffdeb;hpb=35e3737b1e1e9f5b4c58a81a7fcf60b72c3a5f9c;p=shibboleth%2Fsp.git diff --git a/nsapi_shib/nsapi_shib.cpp b/nsapi_shib/nsapi_shib.cpp index d837aaa..7719018 100644 --- a/nsapi_shib/nsapi_shib.cpp +++ b/nsapi_shib/nsapi_shib.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005 Internet2 + * Copyright 2001-2007 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,24 +14,38 @@ * limitations under the License. */ -/* nsapi_shib.cpp - Shibboleth NSAPI filter +/** + * nsapi_shib.cpp + * + * Shibboleth NSAPI filter + */ + +#define SHIBSP_LITE - Scott Cantor - 12/13/04 -*/ +#if defined (_MSC_VER) || defined(__BORLANDC__) +# include "config_win32.h" +#else +# include "config.h" +#endif -#include "config_win32.h" +#ifdef WIN32 +# define _CRT_NONSTDC_NO_DEPRECATE 1 +# define _CRT_SECURE_NO_DEPRECATE 1 +#endif -// SAML Runtime -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include #include #include -#include #ifdef WIN32 # include @@ -48,31 +62,36 @@ extern "C" #include } +using namespace shibsp; +using namespace xmltooling; using namespace std; -using namespace saml; -using namespace shibboleth; -using namespace shibtarget; // macros to output text to client #define NET_WRITE(str) \ if (IO_ERROR==net_write(sn->csd,str,strlen(str))) return REQ_EXIT namespace { - ShibTargetConfig* g_Config=NULL; + SPConfig* g_Config=NULL; string g_ServerName; string g_ServerScheme; + string g_unsetHeaderValue; + bool g_checkSpoofing = true; + bool g_catchAll = false; + + static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h); + static const XMLCh validate[] = UNICODE_LITERAL_8(v,a,l,i,d,a,t,e); } -PlugManager::Factory SunRequestMapFactory; +PluginManager::Factory SunRequestMapFactory; extern "C" NSAPI_PUBLIC void nsapi_shib_exit(void*) { if (g_Config) - g_Config->shutdown(); + g_Config->term(); g_Config = NULL; } -extern "C" NSAPI_PUBLIC int nsapi_shib_init(pblock* pb, Session* sn, Request* rq) +extern "C" NSAPI_PUBLIC int nsapi_shib_init(pblock* pb, ::Session* sn, Request* rq) { // Save off a default hostname for this virtual server. char* name=pblock_findval("server-name",pb); @@ -100,203 +119,270 @@ extern "C" NSAPI_PUBLIC int nsapi_shib_init(pblock* pb, Session* sn, Request* rq log_error(LOG_INFORM,"nsapi_shib_init",sn,rq,"nsapi_shib loaded for host (%s)",g_ServerName.c_str()); -#ifndef _DEBUG - try { -#endif - const char* schemadir=pblock_findval("shib-schemas",pb); - if (!schemadir) - schemadir=getenv("SHIBSCHEMAS"); - if (!schemadir) - schemadir=SHIB_SCHEMAS; - const char* config=pblock_findval("shib-config",pb); - if (!config) - config=getenv("SHIBCONFIG"); - if (!config) - config=SHIB_CONFIG; - g_Config=&ShibTargetConfig::getConfig(); - g_Config->setFeatures( - ShibTargetConfig::Listener | - ShibTargetConfig::Metadata | - ShibTargetConfig::AAP | - ShibTargetConfig::RequestMapper | - ShibTargetConfig::LocalExtensions | - ShibTargetConfig::Logging - ); - if (!g_Config->init(schemadir)) { - g_Config=NULL; - pblock_nvinsert("error","unable to initialize Shibboleth libraries",pb); - return REQ_ABORTED; - } + const char* schemadir=pblock_findval("shib-schemas",pb); + const char* prefix=pblock_findval("shib-prefix",pb); + + g_Config=&SPConfig::getConfig(); + g_Config->setFeatures( + SPConfig::Listener | + SPConfig::Caching | + SPConfig::RequestMapping | + SPConfig::InProcess | + SPConfig::Logging | + SPConfig::Handlers + ); + if (!g_Config->init(schemadir,prefix)) { + g_Config=NULL; + pblock_nvinsert("error","unable to initialize Shibboleth libraries",pb); + return REQ_ABORTED; + } - SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::NativeRequestMapType,&SunRequestMapFactory); - // We hijack the legacy type so that 1.2 config files will load this plugin - SAMLConfig::getConfig().getPlugMgr().regFactory(shibtarget::XML::LegacyRequestMapType,&SunRequestMapFactory); + g_Config->RequestMapperManager.registerFactory(XML_REQUEST_MAPPER,&SunRequestMapFactory); - if (!g_Config->load(config)) { - g_Config=NULL; - pblock_nvinsert("error","unable to initialize load Shibboleth configuration",pb); - return REQ_ABORTED; - } + const char* config=pblock_findval("shib-config",pb); + if (!config) + config=getenv("SHIBSP_CONFIG"); + if (!config) + config=SHIBSP_CONFIG; - daemon_atrestart(nsapi_shib_exit,NULL); -#ifndef _DEBUG + try { + xercesc::DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument(); + XercesJanitor docjanitor(dummydoc); + xercesc::DOMElement* dummy = dummydoc->createElementNS(NULL,path); + auto_ptr_XMLCh src(config); + dummy->setAttributeNS(NULL,path,src.get()); + dummy->setAttributeNS(NULL,validate,xmlconstants::XML_ONE); + + g_Config->setServiceProvider(g_Config->ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy)); + g_Config->getServiceProvider()->init(); } - catch (...) { + catch (exception& ex) { + pblock_nvinsert("error",ex.what(),pb); + g_Config->term(); g_Config=NULL; - pblock_nvinsert("error","caught exception, unable to initialize Shibboleth libraries",pb); return REQ_ABORTED; } -#endif + + daemon_atrestart(nsapi_shib_exit,NULL); + + ServiceProvider* sp=g_Config->getServiceProvider(); + Locker locker(sp); + const PropertySet* props=sp->getPropertySet("Local"); + if (props) { + pair unsetValue=props->getString("unsetHeaderValue"); + if (unsetValue.first) + g_unsetHeaderValue = unsetValue.second; + pair flag=props->getBool("checkSpoofing"); + g_checkSpoofing = !flag.first || flag.second; + flag=props->getBool("catchAll"); + g_catchAll = flag.first && flag.second; + } return REQ_PROCEED; } /********************************************************************************/ // NSAPI Shib Target Subclass -class ShibTargetNSAPI : public ShibTarget +class ShibTargetNSAPI : public AbstractSPRequest { + mutable string m_body; + mutable bool m_gotBody,m_firsttime; + mutable vector m_certs; + set m_allhttp; + public: - ShibTargetNSAPI(pblock* pb, Session* sn, Request* rq) { - m_pb = pb; - m_sn = sn; - m_rq = rq; + pblock* m_pb; + ::Session* m_sn; + Request* m_rq; + + ShibTargetNSAPI(pblock* pb, ::Session* sn, Request* rq) + : AbstractSPRequest(SHIBSP_LOGCAT".NSAPI"), m_gotBody(false), m_firsttime(true), m_pb(pb), m_sn(sn), m_rq(rq) { - // Get everything but hostname... const char* uri=pblock_findval("uri", rq->reqpb); const char* qstr=pblock_findval("query", rq->reqpb); - int port=server_portnum; - const char* scheme=security_active ? "https" : "http"; - const char* host=NULL; - - string url; - if (uri) - url=uri; - if (qstr) - url=url + '?' + qstr; - + + if (qstr) { + string temp = string(uri) + '?' + qstr; + setRequestURI(temp.c_str()); + } + else { + setRequestURI(uri); + } + + // See if this is the first time we've run. + qstr = pblock_findval("auth-type", rq->vars); + if (qstr && !strcmp(qstr, "shibboleth")) + m_firsttime = false; + if (!m_firsttime || rq->orig_rq) + log(SPDebug, "nsapi_shib function running more than once"); + } + ~ShibTargetNSAPI() { } + + const char* getScheme() const { + return security_active ? "https" : "http"; + } + const char* getHostname() const { #ifdef vs_is_default_vs // This is 6.0 or later, so we can distinguish requests to name-based vhosts. - if (!vs_is_default_vs) + if (!vs_is_default_vs(request_get_vs(m_rq))) // The beauty here is, a non-default vhost can *only* be accessed if the client // specified the exact name in the Host header. So we can trust the Host header. - host=pblock_findval("host", rq->headers); + return pblock_findval("host", m_rq->headers); else #endif // In other cases, we're going to rely on the initialization process... - host=g_ServerName.c_str(); - + return g_ServerName.c_str(); + } + int getPort() const { + return server_portnum; + } + const char* getMethod() const { + return pblock_findval("method", m_rq->reqpb); + } + string getContentType() const { char* content_type = ""; - request_header("content-type", &content_type, sn, rq); - - const char *remote_ip = pblock_findval("ip", sn->client); - const char *method = pblock_findval("method", rq->reqpb); - - init(scheme, host, port, url.c_str(), content_type, remote_ip, method); + request_header("content-type", &content_type, m_sn, m_rq); + return content_type; } - ~ShibTargetNSAPI() {} - - virtual void log(ShibLogLevel level, const string &msg) { - ShibTarget::log(level,msg); - if (level==LogLevelError) - log_error(LOG_FAILURE, "nsapi_shib", m_sn, m_rq, const_cast(msg.c_str())); + long getContentLength() const { + if (m_gotBody) + return m_body.length(); + char* content_length=""; + request_header("content-length", &content_length, m_sn, m_rq); + return atoi(content_length); } - virtual string getCookies(void) const { - char *cookies = NULL; - if (request_header("cookie", &cookies, m_sn, m_rq) == REQ_ABORTED) - throw("error accessing cookie header"); - return string(cookies ? cookies : ""); + string getRemoteAddr() const { + return pblock_findval("ip", m_sn->client); } - virtual void setCookie(const string &name, const string &value) { - string cookie = name + '=' + value; - pblock_nvinsert("Set-Cookie", cookie.c_str(), m_rq->srvhdrs); + void log(SPLogLevel level, const string& msg) const { + AbstractSPRequest::log(level,msg); + if (level>=SPError) + log_error(LOG_FAILURE, "nsapi_shib", m_sn, m_rq, const_cast(msg.c_str())); } - virtual string getArgs(void) { - const char *q = pblock_findval("query", m_rq->reqpb); - return string(q ? q : ""); + const char* getQueryString() const { + return pblock_findval("query", m_rq->reqpb); } - virtual string getPostData(void) { + const char* getRequestBody() const { + if (m_gotBody) + return m_body.c_str(); char* content_length=NULL; - if (request_header("content-length", &content_length, m_sn, m_rq)!=REQ_PROCEED || - atoi(content_length) > 1024*1024) // 1MB? - throw FatalProfileException("Blocked too-large a submission to profile endpoint."); + if (request_header("content-length", &content_length, m_sn, m_rq)!=REQ_PROCEED || atoi(content_length) > 1024*1024) // 1MB? + throw opensaml::SecurityPolicyException("Blocked request body exceeding 1M size limit."); else { char ch=IO_EOF+1; int cl=atoi(content_length); - string cgistr; + m_gotBody=true; while (cl && ch != IO_EOF) { ch=netbuf_getc(m_sn->inbuf); - // Check for error. if(ch==IO_ERROR) break; - cgistr += ch; + m_body += ch; cl--; } if (cl) - throw FatalProfileException("Error reading profile submission from browser."); - return cgistr; + throw IOException("Error reading request body from browser."); + return m_body.c_str(); } } - virtual void clearHeader(const string &name) { - param_free(pblock_remove(name.c_str(), m_rq->headers)); + void clearHeader(const char* rawname, const char* cginame) { + if (g_checkSpoofing && m_firsttime && !m_rq->orig_rq) { + if (m_allhttp.empty()) { + // Populate the set of client-supplied headers for spoof checking. + const pb_entry* entry; + for (int i=0; iheaders->hsize; ++i) { + entry = m_rq->headers->ht[i]; + while (entry) { + string cgiversion("HTTP_"); + const char* pch = entry->param->name; + while (*pch) { + cgiversion += (isalnum(*pch) ? toupper(*pch) : '_'); + pch++; + } + m_allhttp.insert(cgiversion); + entry = entry->next; + } + } + } + if (m_allhttp.count(cginame) > 0) + throw opensaml::SecurityPolicyException("Attempt to spoof header ($1) was detected.", params(1, rawname)); + } + param_free(pblock_remove(rawname, m_rq->headers)); + pblock_nvinsert(rawname, g_unsetHeaderValue.c_str(), m_rq->headers); } - virtual void setHeader(const string &name, const string &value) { - pblock_nvinsert(name.c_str(), value.c_str() ,m_rq->headers); + void setHeader(const char* name, const char* value) { + param_free(pblock_remove(name, m_rq->headers)); + pblock_nvinsert(name, value, m_rq->headers); } - virtual string getHeader(const string &name) { - char *hdr = NULL; - if (request_header(const_cast(name.c_str()), &hdr, m_sn, m_rq) != REQ_PROCEED) - hdr = NULL; + string getHeader(const char* name) const { + // NSAPI headers tend to be lower case. We'll special case "cookie" since it's used a lot. + char* hdr = NULL; + int cookie = strcmp(name, "Cookie"); + if (cookie == 0) + name = "cookie"; + if (request_header(const_cast(name), &hdr, m_sn, m_rq) != REQ_PROCEED) { + // We didn't get a hit, so we'll try a lower-casing operation, unless we already did... + if (cookie == 0) + return ""; + string n; + while (*name) + n += tolower(*(name++)); + if (request_header(const_cast(n.c_str()), &hdr, m_sn, m_rq) != REQ_PROCEED) + return ""; + } return string(hdr ? hdr : ""); } - virtual void setRemoteUser(const string &user) { - pblock_nvinsert("remote-user", user.c_str(), m_rq->headers); - pblock_nvinsert("auth-user", user.c_str(), m_rq->vars); + void setRemoteUser(const char* user) { + pblock_nvinsert("auth-user", user, m_rq->vars); } - virtual string getRemoteUser(void) { - return getHeader("remote-user"); + string getRemoteUser() const { + const char* ru = pblock_findval("auth-user", m_rq->vars); + return ru ? ru : ""; + } + void setResponseHeader(const char* name, const char* value) { + pblock_nvinsert(name, value, m_rq->srvhdrs); } - virtual void* sendPage( - const string& msg, - int code=200, - const string& content_type="text/html", - const saml::Iterator& headers=EMPTY(header_t) - ) { - param_free(pblock_remove("content-type", m_rq->srvhdrs)); - pblock_nvinsert("content-type", content_type.c_str(), m_rq->srvhdrs); - pblock_nninsert("content-length", msg.length(), m_rq->srvhdrs); - pblock_nvinsert("connection","close",m_rq->srvhdrs); - while (headers.hasNext()) { - const header_t& h=headers.next(); - pblock_nvinsert(h.first.c_str(), h.second.c_str(), m_rq->srvhdrs); + long sendResponse(istream& in, long status) { + string msg; + char buf[1024]; + while (in) { + in.read(buf,1024); + msg.append(buf,in.gcount()); } - protocol_status(m_sn, m_rq, code, NULL); + pblock_nvinsert("connection","close",m_rq->srvhdrs); + pblock_nninsert("content-length", msg.length(), m_rq->srvhdrs); + protocol_status(m_sn, m_rq, status, NULL); protocol_start_response(m_sn, m_rq); net_write(m_sn->csd,const_cast(msg.c_str()),msg.length()); - return (void*)REQ_EXIT; + return REQ_EXIT; } - virtual void* sendRedirect(const string& url) { + long sendRedirect(const char* url) { param_free(pblock_remove("content-type", m_rq->srvhdrs)); pblock_nninsert("content-length", 0, m_rq->srvhdrs); pblock_nvinsert("expires", "01-Jan-1997 12:00:00 GMT", m_rq->srvhdrs); pblock_nvinsert("cache-control", "private,no-store,no-cache", m_rq->srvhdrs); - pblock_nvinsert("location", url.c_str(), m_rq->srvhdrs); + pblock_nvinsert("location", url, m_rq->srvhdrs); + pblock_nvinsert("connection","close",m_rq->srvhdrs); protocol_status(m_sn, m_rq, PROTOCOL_REDIRECT, NULL); protocol_start_response(m_sn, m_rq); - return (void*)REQ_ABORTED; + return REQ_ABORTED; + } + long returnDecline() { return REQ_NOACTION; } + long returnOK() { return REQ_PROCEED; } + const vector& getClientCertificates() const { + if (m_certs.empty()) { + const char* cert = pblock_findval("auth-cert", m_rq->vars); + if (cert) + m_certs.push_back(cert); + } + return m_certs; } - virtual void* returnDecline(void) { return (void*)REQ_NOACTION; } - virtual void* returnOK(void) { return (void*)REQ_PROCEED; } - - pblock* m_pb; - Session* m_sn; - Request* m_rq; }; /********************************************************************************/ -int WriteClientError(Session* sn, Request* rq, char* func, char* msg) +int WriteClientError(::Session* sn, Request* rq, char* func, char* msg) { log_error(LOG_FAILURE,func,sn,rq,msg); protocol_status(sn,rq,PROTOCOL_SERVER_ERROR,msg); @@ -305,19 +391,17 @@ int WriteClientError(Session* sn, Request* rq, char* func, char* msg) #undef FUNC #define FUNC "shibboleth" -extern "C" NSAPI_PUBLIC int nsapi_shib(pblock* pb, Session* sn, Request* rq) +extern "C" NSAPI_PUBLIC int nsapi_shib(pblock* pb, ::Session* sn, Request* rq) { ostringstream threadid; threadid << "[" << getpid() << "] nsapi_shib" << '\0'; - saml::NDC ndc(threadid.str().c_str()); + xmltooling::NDC ndc(threadid.str().c_str()); -#ifndef _DEBUG try { -#endif ShibTargetNSAPI stn(pb, sn, rq); // Check user authentication - pair res = stn.doCheckAuthN(); + pair res = stn.getServiceProvider().doAuthentication(stn); if (res.first) return (int)res.second; // user authN was okay -- export the assertions now @@ -325,104 +409,107 @@ extern "C" NSAPI_PUBLIC int nsapi_shib(pblock* pb, Session* sn, Request* rq) // This seems to be required in order to eventually set // the auth-user var. pblock_nvinsert("auth-type","shibboleth",rq->vars); - res = stn.doExportAssertions(); + res = stn.getServiceProvider().doExport(stn); if (res.first) return (int)res.second; // Check the Authorization - res = stn.doCheckAuthZ(); + res = stn.getServiceProvider().doAuthorization(stn); if (res.first) return (int)res.second; // this user is ok. return REQ_PROCEED; - -#ifndef _DEBUG + } + catch (exception& e) { + log_error(LOG_FAILURE,FUNC,sn,rq,const_cast(e.what())); + return WriteClientError(sn, rq, FUNC, "Shibboleth module threw an exception, see web server log for error."); } catch (...) { - return WriteClientError(sn, rq, FUNC, "threw an uncaught exception."); + log_error(LOG_FAILURE,FUNC,sn,rq,const_cast("Shibboleth module threw an unknown exception.")); + if (g_catchAll) + return WriteClientError(sn, rq, FUNC, "Shibboleth module threw an unknown exception."); + throw; } -#endif } #undef FUNC #define FUNC "shib_handler" -extern "C" NSAPI_PUBLIC int shib_handler(pblock* pb, Session* sn, Request* rq) +extern "C" NSAPI_PUBLIC int shib_handler(pblock* pb, ::Session* sn, Request* rq) { ostringstream threadid; threadid << "[" << getpid() << "] shib_handler" << '\0'; - saml::NDC ndc(threadid.str().c_str()); + xmltooling::NDC ndc(threadid.str().c_str()); -#ifndef _DEBUG try { -#endif ShibTargetNSAPI stn(pb, sn, rq); - pair res = stn.doHandler(); + pair res = stn.getServiceProvider().doHandler(stn); if (res.first) return (int)res.second; return WriteClientError(sn, rq, FUNC, "Shibboleth handler did not do anything."); - -#ifndef _DEBUG + } + catch (exception& e) { + log_error(LOG_FAILURE,FUNC,sn,rq,const_cast(e.what())); + return WriteClientError(sn, rq, FUNC, "Shibboleth handler threw an exception, see web server log for error."); } catch (...) { - return WriteClientError(sn, rq, FUNC, "Filter threw an unknown exception."); + if (g_catchAll) + return WriteClientError(sn, rq, FUNC, "Shibboleth handler threw an unknown exception."); + throw; } -#endif } -class SunRequestMapper : public virtual IRequestMapper, public virtual IPropertySet +class SunRequestMapper : public virtual RequestMapper, public virtual PropertySet { public: - SunRequestMapper(const DOMElement* e); + SunRequestMapper(const xercesc::DOMElement* e); ~SunRequestMapper() { delete m_mapper; delete m_stKey; delete m_propsKey; } - void lock() { m_mapper->lock(); } + Lockable* lock() { return m_mapper->lock(); } void unlock() { m_stKey->setData(NULL); m_propsKey->setData(NULL); m_mapper->unlock(); } - Settings getSettings(ShibTarget* st) const; + Settings getSettings(const HTTPRequest& request) const; + const PropertySet* getParent() const { return NULL; } + void setParent(const PropertySet*) {} pair getBool(const char* name, const char* ns=NULL) const; pair getString(const char* name, const char* ns=NULL) const; pair getXMLString(const char* name, const char* ns=NULL) const; pair getUnsignedInt(const char* name, const char* ns=NULL) const; pair getInt(const char* name, const char* ns=NULL) const; - const IPropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:target:config:1.0") const; - const DOMElement* getElement() const; + void getAll(map& properties) const; + const PropertySet* getPropertySet(const char* name, const char* ns="urn:mace:shibboleth:2.0:native:sp:config") const; + const xercesc::DOMElement* getElement() const; private: - IRequestMapper* m_mapper; + RequestMapper* m_mapper; ThreadKey* m_stKey; ThreadKey* m_propsKey; }; -IPlugIn* SunRequestMapFactory(const DOMElement* e) +RequestMapper* SunRequestMapFactory(const xercesc::DOMElement* const & e) { return new SunRequestMapper(e); } -SunRequestMapper::SunRequestMapper(const DOMElement* e) : m_mapper(NULL), m_stKey(NULL), m_propsKey(NULL) +SunRequestMapper::SunRequestMapper(const xercesc::DOMElement* e) : m_mapper(NULL), m_stKey(NULL), m_propsKey(NULL) { - IPlugIn* p=SAMLConfig::getConfig().getPlugMgr().newPlugin(shibtarget::XML::XMLRequestMapType,e); - m_mapper=dynamic_cast(p); - if (!m_mapper) { - delete p; - throw UnsupportedExtensionException("Embedded request mapper plugin was not of correct type."); - } + m_mapper = SPConfig::getConfig().RequestMapperManager.newPlugin(XML_REQUEST_MAPPER,e); m_stKey=ThreadKey::create(NULL); m_propsKey=ThreadKey::create(NULL); } -IRequestMapper::Settings SunRequestMapper::getSettings(ShibTarget* st) const +RequestMapper::Settings SunRequestMapper::getSettings(const HTTPRequest& request) const { - Settings s=m_mapper->getSettings(st); - m_stKey->setData(dynamic_cast(st)); + Settings s=m_mapper->getSettings(request); + m_stKey->setData((void*)dynamic_cast(&request)); m_propsKey->setData((void*)s.first); - return pair(this,s.second); + return pair(this,s.second); } pair SunRequestMapper::getBool(const char* name, const char* ns) const { - ShibTargetNSAPI* stn=reinterpret_cast(m_stKey->getData()); - const IPropertySet* s=reinterpret_cast(m_propsKey->getData()); + const ShibTargetNSAPI* stn=reinterpret_cast(m_stKey->getData()); + const PropertySet* s=reinterpret_cast(m_propsKey->getData()); if (stn && !ns && name) { // Override boolean properties. const char* param=pblock_findval(name,stn->m_pb); @@ -434,8 +521,8 @@ pair SunRequestMapper::getBool(const char* name, const char* ns) cons pair SunRequestMapper::getString(const char* name, const char* ns) const { - ShibTargetNSAPI* stn=reinterpret_cast(m_stKey->getData()); - const IPropertySet* s=reinterpret_cast(m_propsKey->getData()); + const ShibTargetNSAPI* stn=reinterpret_cast(m_stKey->getData()); + const PropertySet* s=reinterpret_cast(m_propsKey->getData()); if (stn && !ns && name) { // Override string properties. if (!strcmp(name,"authType")) @@ -451,30 +538,63 @@ pair SunRequestMapper::getString(const char* name, const char* pair SunRequestMapper::getXMLString(const char* name, const char* ns) const { - const IPropertySet* s=reinterpret_cast(m_propsKey->getData()); + const PropertySet* s=reinterpret_cast(m_propsKey->getData()); return s ? s->getXMLString(name,ns) : pair(false,NULL); } pair SunRequestMapper::getUnsignedInt(const char* name, const char* ns) const { - const IPropertySet* s=reinterpret_cast(m_propsKey->getData()); + const ShibTargetNSAPI* stn=reinterpret_cast(m_stKey->getData()); + const PropertySet* s=reinterpret_cast(m_propsKey->getData()); + if (stn && !ns && name) { + // Override int properties. + const char* param=pblock_findval(name,stn->m_pb); + if (param) + return pair(true,strtol(param,NULL,10)); + } return s ? s->getUnsignedInt(name,ns) : pair(false,0); } pair SunRequestMapper::getInt(const char* name, const char* ns) const { - const IPropertySet* s=reinterpret_cast(m_propsKey->getData()); + const ShibTargetNSAPI* stn=reinterpret_cast(m_stKey->getData()); + const PropertySet* s=reinterpret_cast(m_propsKey->getData()); + if (stn && !ns && name) { + // Override int properties. + const char* param=pblock_findval(name,stn->m_pb); + if (param) + return pair(true,atoi(param)); + } return s ? s->getInt(name,ns) : pair(false,0); } -const IPropertySet* SunRequestMapper::getPropertySet(const char* name, const char* ns) const +void SunRequestMapper::getAll(map& properties) const +{ + const ShibTargetNSAPI* stn=reinterpret_cast(m_stKey->getData()); + const PropertySet* s=reinterpret_cast(m_propsKey->getData()); + if (s) + s->getAll(properties); + if (!stn) + return; + properties["authType"] = "shibboleth"; + const pb_entry* entry; + for (int i=0; im_pb->hsize; ++i) { + entry = stn->m_pb->ht[i]; + while (entry) { + properties[entry->param->name] = entry->param->value; + entry = entry->next; + } + } +} + +const PropertySet* SunRequestMapper::getPropertySet(const char* name, const char* ns) const { - const IPropertySet* s=reinterpret_cast(m_propsKey->getData()); + const PropertySet* s=reinterpret_cast(m_propsKey->getData()); return s ? s->getPropertySet(name,ns) : NULL; } -const DOMElement* SunRequestMapper::getElement() const +const xercesc::DOMElement* SunRequestMapper::getElement() const { - const IPropertySet* s=reinterpret_cast(m_propsKey->getData()); + const PropertySet* s=reinterpret_cast(m_propsKey->getData()); return s ? s->getElement() : NULL; }