map<string,string> g_mapAttribNameToHeader;
map<string,string> g_mapAttribRuleToHeader;
- map<xstring,string> g_mapAttribNames;
}
extern "C" const char*
// Create the RPC Handle TLS key.
rpc_handle_key=ThreadKey::create(destroy_handle);
- // Transcode the attribute names we know about for quick handling map access.
- for (map<string,string>::const_iterator i=g_mapAttribNameToHeader.begin();
- i!=g_mapAttribNameToHeader.end(); i++)
- {
- auto_ptr<XMLCh> temp(XMLString::transcode(i->first.c_str()));
- g_mapAttribNames[temp.get()]=i->first;
- }
-
ap_log_error(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,s,"shibrm_child_init() done");
}
hname=wrapper->getHeader();
if (!hname)
{
- map<xstring,string>::const_iterator iname=g_mapAttribNames.find(attr->getName());
- if (iname!=g_mapAttribNames.end())
- hname=g_mapAttribNameToHeader[iname->second].c_str();
+ auto_ptr<char> tname(XMLString::transcode(attr->getName()));
+ map<string,string>::const_iterator iname=g_mapAttribNameToHeader.find(tname.get());
+ if (iname!=g_mapAttribNameToHeader.end())
+ hname=iname->second.c_str();
}
if (hname)
{
m_subject = s->getSubject();
- xstring name = m_subject->getName();
- xstring qual = m_subject->getNameQualifier();
+ const XMLCh* name = m_subject->getName();
+ const XMLCh* qual = m_subject->getNameQualifier();
- auto_ptr<char> h(XMLString::transcode(name.c_str()));
- auto_ptr<char> d(XMLString::transcode(qual.c_str()));
+ auto_ptr<char> h(XMLString::transcode(name));
+ auto_ptr<char> d(XMLString::transcode(qual));
m_handle = h.get();
m_originSite = d.get();
Iterator<SAMLCondition*> conds=as->getConditions();
while (conds.hasNext())
{
- SAMLAudienceRestrictionCondition* cond=dynaptr(SAMLAudienceRestrictionCondition,conds.next());
+ SAMLAudienceRestrictionCondition* cond=dynamic_cast<SAMLAudienceRestrictionCondition*>(conds.next());
if (!cond->eval(ShibTargetConfig::getConfig().getPolicies()))
{
m_priv->log->warn("Assertion failed AudienceRestrictionCondition check, skipping it...");
int status;
string error_msg;
- xstring origin;
+ XMLCh* origin;
SAMLException* except;
};
rpcerror_init();
- if (originSite) origin = originSite;
+ origin = XMLString::replicate(originSite);
if (status == SHIBRPC_SAML_EXCEPTION) {
istringstream estr(msg);
log.error ("Caught exception building SAMLException!");
log.error ("XML: %s", msg);
}
- if (dynaptr(ContentTypeException, except)!=NULL)
+ if (dynamic_cast<ContentTypeException*>(except)!=NULL)
error_msg =
"We were unable to contact your identity provider and cannot grant "
"access at this time. Please contact your provider's help desk or "
{
if (except)
delete except;
+ if (origin)
+ XMLString::release(&origin);
}
RPCError::RPCError(ShibRpcError* error)
string RPCError::getOriginErrorURL()
{
string res="No URL Available";
- if (!m_priv->origin.empty())
+ if (m_priv->origin)
{
- OriginMetadata mapper(m_priv->origin.c_str());
+ OriginMetadata mapper(m_priv->origin);
if (!mapper.fail())
{
const char* temp=mapper->getErrorURL();
string RPCError::getOriginContactName()
{
string res="No Name Available";
- if (!m_priv->origin.empty())
+ if (m_priv->origin)
{
- OriginMetadata mapper(m_priv->origin.c_str());
+ OriginMetadata mapper(m_priv->origin);
Iterator<const IContactInfo*> i=
mapper.fail() ? EMPTY(const IContactInfo*) : mapper->getContacts();
while (i.hasNext())
string RPCError::getOriginContactEmail()
{
string res="No Email Available";
- if (!m_priv->origin.empty())
+ if (m_priv->origin)
{
- OriginMetadata mapper(m_priv->origin.c_str());
+ OriginMetadata mapper(m_priv->origin);
Iterator<const IContactInfo*> i=
mapper.fail() ? EMPTY(const IContactInfo*) : mapper->getContacts();
while (i.hasNext())
class SHIBTARGET_EXPORTS ShibTargetException : public std::exception
{
public:
- explicit ShibTargetException() { m_code = SHIBRPC_OK; }
- explicit ShibTargetException(ShibRpcStatus code, const char* msg,
- const XMLCh* origin = NULL)
- { m_code = code; if (msg) m_msg=msg; if (origin) m_origin = origin; }
- explicit ShibTargetException(ShibRpcStatus code, const std::string& msg,
- const XMLCh* origin = NULL) : m_msg(msg)
- { m_code=code; if(origin) m_origin = origin; }
- virtual ~ShibTargetException() throw () {}
+ explicit ShibTargetException() : m_origin(NULL), m_code(SHIBRPC_OK) {}
+ explicit ShibTargetException(ShibRpcStatus code, const char* msg, const XMLCh* origin = NULL) : m_code(code)
+ { if (msg) m_msg=msg; m_origin = XMLString::replicate(origin); }
+ explicit ShibTargetException(ShibRpcStatus code, const std::string& msg, const XMLCh* origin = NULL) : m_msg(msg)
+ { m_code=code; m_origin = XMLString::replicate(origin); }
+ virtual ~ShibTargetException() throw () { if (m_origin) XMLString::release(&m_origin); }
virtual const char* what() const throw () { return (m_msg.c_str()); }
virtual ShibRpcStatus which() const throw () { return (m_code); }
- virtual const XMLCh* where() const throw () { return m_origin.c_str(); }
+ virtual const XMLCh* where() const throw () { return m_origin; }
private:
- ShibRpcStatus m_code;
- std::string m_msg;
- saml::xstring m_origin;
+ ShibRpcStatus m_code;
+ std::string m_msg;
+ XMLCh* m_origin;
};
class RPCErrorPriv;
};
SiteRule m_anySiteRule;
- map<xstring,SiteRule> m_siteMap;
+#ifdef HAVE_GOOD_STL
+ typedef map<xstring,SiteRule> sitemap_t;
+#else
+ typedef map<string,SiteRule> sitemap_t;
+#endif
+ sitemap_t m_siteMap;
};
vector<const IAttributeRule*> m_attrs;
map<string,const IAttributeRule*> m_aliasMap;
- map<xstring,AttributeRule*> m_attrMap;
+#ifdef HAVE_GOOD_STL
+ typedef map<xstring,AttributeRule*> attrmap_t;
+#else
+ typedef map<string,AttributeRule*> attrmap_t;
+#endif
+ attrmap_t m_attrMap;
DOMDocument* m_doc;
};
for (int i=0; nlist && i<nlist->getLength(); i++)
{
AttributeRule* rule=new AttributeRule(static_cast<DOMElement*>(nlist->item(i)));
- m_attrMap[xstring(rule->getName()) + chBang + chBang + (rule->getNamespace() ? rule->getNamespace() : Constants::SHIB_ATTRIBUTE_NAMESPACE_URI)]=rule;
+#ifdef HAVE_GOOD_STL
+ xstring key=rule->getName();
+ key=key + chBang + chBang + (rule->getNamespace() ? rule->getNamespace() : Constants::SHIB_ATTRIBUTE_NAMESPACE_URI);
+#else
+ auto_ptr<char> aname(XMLString::transcode(rule->getName()));
+ string key(aname.get());
+ key+="!!";
+ if (rule->getNamespace())
+ {
+ auto_ptr<char> ans(XMLString::transcode(rule->getNamespace()));
+ key+=ans.get();
+ }
+ else
+ key+="urn:mace:shibboleth:1.0:attributeNamespace:uri";
+#endif
+ m_attrMap[key]=rule;
m_attrs.push_back(rule);
if (rule->getAlias())
m_aliasMap[rule->getAlias()]=rule;
catch (SAMLException& e)
{
log.errorStream() << "XML error while parsing AAP: " << e.what() << CategoryStream::ENDLINE;
- for (map<xstring,AttributeRule*>::iterator i=m_attrMap.begin(); i!=m_attrMap.end(); i++)
+ for (attrmap_t::iterator i=m_attrMap.begin(); i!=m_attrMap.end(); i++)
delete i->second;
if (m_doc)
m_doc->release();
catch (...)
{
log.error("Unexpected error while parsing AAP");
- for (map<xstring,AttributeRule*>::iterator i=m_attrMap.begin(); i!=m_attrMap.end(); i++)
+ for (attrmap_t::iterator i=m_attrMap.begin(); i!=m_attrMap.end(); i++)
delete i->second;
if (m_doc)
m_doc->release();
XMLAAPImpl::~XMLAAPImpl()
{
- for (map<xstring,AttributeRule*>::iterator i=m_attrMap.begin(); i!=m_attrMap.end(); i++)
+ for (attrmap_t::iterator i=m_attrMap.begin(); i!=m_attrMap.end(); i++)
{
SAMLAttribute::unregFactory(i->second->getName(),i->second->getNamespace());
delete i->second;
void XMLAAPImpl::regAttributes() const
{
- for (map<xstring,AttributeRule*>::const_iterator i=m_attrMap.begin(); i!=m_attrMap.end(); i++)
+ for (attrmap_t::const_iterator i=m_attrMap.begin(); i!=m_attrMap.end(); i++)
{
SAMLAttributeFactory* f=ShibConfig::getConfig().getAttributeFactory(i->second->getFactory());
if (f)
DOMNodeList* slist = e->getElementsByTagNameNS(XML::SHIB_NS,SHIB_L(SiteRule));
for (int k=0; slist && k<slist->getLength(); k++)
{
- m_siteMap[static_cast<DOMElement*>(slist->item(k))->getAttributeNS(NULL,SHIB_L(Name))]=SiteRule();
- SiteRule& srule=m_siteMap[static_cast<DOMElement*>(slist->item(k))->getAttributeNS(NULL,SHIB_L(Name))];
+ const XMLCh* srulename=static_cast<DOMElement*>(slist->item(k))->getAttributeNS(NULL,SHIB_L(Name));
+#ifdef HAVE_GOOD_STL
+ m_siteMap[srulename]=SiteRule();
+ SiteRule& srule=m_siteMap[srulename];
+#else
+ auto_ptr<char> srulename2(XMLString::transcode(srulename));
+ m_siteMap[srulename2.get()]=SiteRule();
+ SiteRule& srule=m_siteMap[srulename2.get()];
+#endif
// Process Scope elements.
DOMNodeList* vlist = static_cast<DOMElement*>(slist->item(k))->getElementsByTagNameNS(XML::SHIB_NS,SHIB_L(Scope));
const IAttributeRule* XMLAAP::lookup(const XMLCh* attrName, const XMLCh* attrNamespace) const
{
- map<xstring,XMLAAPImpl::AttributeRule*>::const_iterator i=m_impl->m_attrMap.find(
- xstring(attrName) + chBang + chBang + (attrNamespace ? attrNamespace : Constants::SHIB_ATTRIBUTE_NAMESPACE_URI)
- );
+#ifdef HAVE_GOOD_STL
+ xstring key=attrName;
+ key=key + chBang + chBang + (attrNamespace ? attrNamespace : Constants::SHIB_ATTRIBUTE_NAMESPACE_URI);
+#else
+ auto_ptr<char> aname(XMLString::transcode(attrName));
+ string key=aname.get();
+ key+="!!";
+ if (attrNamespace)
+ {
+ auto_ptr<char> ans(XMLString::transcode(attrNamespace));
+ key+=ans.get();
+ }
+ else
+ key+="urn:mace:shibboleth:1.0:attributeNamespace:uri";
+#endif
+ XMLAAPImpl::attrmap_t::const_iterator i=m_impl->m_attrMap.find(key);
return (i==m_impl->m_attrMap.end()) ? NULL : i->second;
}
log.warn("scope checking does not permit XPath rules");
}
- map<xstring,SiteRule>::const_iterator srule=m_siteMap.find(originSite);
+#ifdef HAVE_GOOD_STL
+ const XMLCh* os=originSite;
+#else
+ auto_ptr<char> pos(XMLString::transcode(originSite));
+ const char* os=pos.get();
+#endif
+ sitemap_t::const_iterator srule=m_siteMap.find(os);
if (srule!=m_siteMap.end())
{
// Site-specific denials...
log.warn("implementation does not support XPath value rules");
}
- map<xstring,SiteRule>::const_iterator srule=m_siteMap.find(originSite);
+#ifdef HAVE_GOOD_STL
+ const XMLCh* os=originSite;
+#else
+ auto_ptr<char> pos(XMLString::transcode(originSite));
+ const char* os=pos.get();
+#endif
+ sitemap_t::const_iterator srule=m_siteMap.find(os);
if (srule==m_siteMap.end())
{
if (log.isWarnEnabled())
throw MalformedException(SAMLException::RESPONDER,"ScopedAttribute() requires the number of scopes to equal the number of values");
while (scopes.hasNext())
- m_values.push_back(scopes.next());
+ m_scopes.push_back(XMLString::replicate(scopes.next()));
}
ScopedAttribute::ScopedAttribute(DOMElement* e) : SimpleAttribute(e) {}
-ScopedAttribute::~ScopedAttribute() {}
+ScopedAttribute::~ScopedAttribute()
+{
+ if (m_bOwnStrings)
+ {
+ for (vector<const XMLCh*>::iterator i=m_scopes.begin(); i!=m_scopes.end(); i++)
+ {
+ XMLCh* p = const_cast<XMLCh*>(*i);
+ XMLString::release(&p);
+ }
+ }
+
+ // We always own any scoped values we've built.
+ for (vector<const XMLCh*>::iterator i=m_scopedValues.begin(); i!=m_scopedValues.end(); i++)
+ {
+ XMLCh* p = const_cast<XMLCh*>(*i);
+ XMLString::release(&p);
+ }
+}
bool ScopedAttribute::addValue(DOMElement* e)
{
- static XMLCh empty[] = {chNull};
if (SAMLAttribute::addValue(e))
{
DOMAttr* scope=e->getAttributeNodeNS(NULL,SHIB_L(Scope));
- m_scopes.push_back(scope ? scope->getNodeValue() : empty);
+ m_scopes.push_back(scope ? scope->getNodeValue() : &chNull);
return true;
}
return false;
}
-Iterator<xstring> ScopedAttribute::getValues() const
+Iterator<const XMLCh*> ScopedAttribute::getValues() const
{
+ static XMLCh at[]={chAt, chNull};
+
if (m_scopedValues.empty())
{
- vector<xstring>::const_iterator j=m_scopes.begin();
- for (vector<xstring>::const_iterator i=m_values.begin(); i!=m_values.end(); i++, j++)
- m_scopedValues.push_back((*i) + chAt + (!j->empty() ? (*j) : m_originSite));
+ vector<const XMLCh*>::const_iterator j=m_scopes.begin();
+ for (vector<const XMLCh*>::const_iterator i=m_values.begin(); i!=m_values.end(); i++, j++)
+ {
+ const XMLCh* scope=((*j) ? (*j) : m_originSite);
+ XMLCh* temp=new XMLCh[XMLString::stringLen(*i) + XMLString::stringLen(scope) + 2];
+ temp[0]=chNull;
+ XMLString::catString(temp,*i);
+ XMLString::catString(temp,at);
+ XMLString::catString(temp,scope);
+ m_scopedValues.push_back(temp);
+ }
}
- return Iterator<xstring>(m_scopedValues);
+ return m_scopedValues;
}
Iterator<string> ScopedAttribute::getSingleByteValues() const
getValues();
if (m_sbValues.empty())
{
- for (vector<xstring>::const_iterator i=m_scopedValues.begin(); i!=m_scopedValues.end(); i++)
+ for (vector<const XMLCh*>::const_iterator i=m_scopedValues.begin(); i!=m_scopedValues.end(); i++)
{
- auto_ptr<char> temp(toUTF8(i->c_str()));
+ auto_ptr<char> temp(toUTF8(*i));
if (temp.get())
m_sbValues.push_back(temp.get());
}
SAMLObject* ScopedAttribute::clone() const
{
- ScopedAttribute* dest=new ScopedAttribute(m_name,m_namespace,m_lifetime);
- dest->m_values.assign(m_values.begin(),m_values.end());
- dest->m_scopes.assign(m_scopes.begin(),m_scopes.end());
- return dest;
+ return new ScopedAttribute(m_name,m_namespace,m_lifetime,m_scopes,m_values);
}
DOMNode* ScopedAttribute::toDOM(DOMDocument* doc,bool xmlns) const
{
if (n->getNodeType()==DOMNode::ELEMENT_NODE)
{
- static_cast<DOMElement*>(n)->setAttributeNS(NULL,SHIB_L(Scope),m_scopes[i].c_str());
+ static_cast<DOMElement*>(n)->setAttributeNS(NULL,SHIB_L(Scope),m_scopes[i]);
i++;
}
n=n->getNextSibling();
vector<const XMLCh*> m_groups;
};
- std::map<saml::xstring,OriginSite*> m_sites;
+#ifdef HAVE_GOOD_STL
+ typedef map<xstring,OriginSite*> sitemap_t;
+#else
+ typedef map<string,OriginSite*> sitemap_t;
+#endif
+ sitemap_t m_sites;
DOMDocument* m_doc;
};
OriginSite* os_obj =
new OriginSite(os_name,static_cast<DOMElement*>(nlist->item(i))->getAttributeNS(NULL,XML::Literals::ErrorURL));
+#ifdef HAVE_GOOD_STL
m_sites[os_name]=os_obj;
-
+#else
+ auto_ptr<char> os_name2(XMLString::transcode(os_name));
+ m_sites[os_name2.get()]=os_obj;
+#endif
+
// Record all the SiteGroups containing this site.
DOMNode* group=nlist->item(i)->getParentNode();
while (group && group->getNodeType()==DOMNode::ELEMENT_NODE)
catch (SAMLException& e)
{
log.errorStream() << "XML error while parsing site configuration: " << e.what() << CategoryStream::ENDLINE;
- for (map<xstring,OriginSite*>::iterator i=m_sites.begin(); i!=m_sites.end(); i++)
+ for (sitemap_t::iterator i=m_sites.begin(); i!=m_sites.end(); i++)
delete i->second;
if (m_doc)
m_doc->release();
catch (...)
{
log.error("Unexpected error while parsing site configuration");
- for (map<xstring,OriginSite*>::iterator i=m_sites.begin(); i!=m_sites.end(); i++)
+ for (sitemap_t::iterator i=m_sites.begin(); i!=m_sites.end(); i++)
delete i->second;
if (m_doc)
m_doc->release();
XMLMetadataImpl::~XMLMetadataImpl()
{
- for (map<xstring,OriginSite*>::iterator i=m_sites.begin(); i!=m_sites.end(); i++)
+ for (sitemap_t::iterator i=m_sites.begin(); i!=m_sites.end(); i++)
delete i->second;
if (m_doc)
m_doc->release();
const ISite* XMLMetadata::lookup(const XMLCh* site) const
{
- map<xstring,XMLMetadataImpl::OriginSite*>::const_iterator i=m_impl->m_sites.find(site);
+#ifdef HAVE_GOOD_STL
+ XMLMetadataImpl::sitemap_t::const_iterator i=m_impl->m_sites.find(site);
+#else
+ auto_ptr<char> temp(XMLString::transcode(site));
+ XMLMetadataImpl::sitemap_t::const_iterator i=m_impl->m_sites.find(temp.get());
+#endif
return (i==m_impl->m_sites.end()) ? NULL : i->second;
}
class SHIB_EXPORTS name : public saml::base \
{ \
public: \
- name(const char* msg) : saml::base(msg) {RTTI(name); m_typename=#name;} \
- name(const std::string& msg) : saml::base(msg) {RTTI(name); m_typename=#name;} \
- name(const saml::Iterator<saml::QName>& codes, const char* msg) : saml::base(codes,msg) {RTTI(name); m_typename=#name;} \
- name(const saml::Iterator<saml::QName>& codes, const std::string& msg) : saml::base(codes, msg) {RTTI(name); m_typename=#name;} \
- name(const saml::QName& code, const char* msg) : saml::base(code,msg) {RTTI(name); m_typename=#name;} \
- name(const saml::QName& code, const std::string& msg) : saml::base(code, msg) {RTTI(name); m_typename=#name;} \
- name(DOMElement* e) : saml::base(e) {RTTI(name); m_typename=#name;} \
- name(std::istream& in) : saml::base(in) {RTTI(name); m_typename=#name;} \
+ name(const char* msg) : saml::base(msg) {RTTI(name);} \
+ name(const std::string& msg) : saml::base(msg) {RTTI(name);} \
+ name(const saml::Iterator<saml::QName>& codes, const char* msg) : saml::base(codes,msg) {RTTI(name);} \
+ name(const saml::Iterator<saml::QName>& codes, const std::string& msg) : saml::base(codes, msg) {RTTI(name);} \
+ name(const saml::QName& code, const char* msg) : saml::base(code,msg) {RTTI(name);} \
+ name(const saml::QName& code, const std::string& msg) : saml::base(code, msg) {RTTI(name);} \
+ name(DOMElement* e) : saml::base(e) {RTTI(name);} \
+ name(std::istream& in) : saml::base(in) {RTTI(name);} \
virtual ~name() throw () {} \
}
const unsigned short RTTI_UnsupportedProtocolException= RTTI_EXTENSION_BASE;
const unsigned short RTTI_MetadataException= RTTI_EXTENSION_BASE+1;
# endif
- template class SHIB_EXPORTS saml::Iterator<std::pair<saml::xstring,bool> >;
- template class SHIB_EXPORTS saml::ArrayIterator<std::pair<saml::xstring,bool> >;
+// template class SHIB_EXPORTS saml::Iterator<std::pair<saml::xstring,bool> >;
+// template class SHIB_EXPORTS saml::ArrayIterator<std::pair<saml::xstring,bool> >;
template class SHIB_EXPORTS saml::Iterator<const IContactInfo*>;
template class SHIB_EXPORTS saml::ArrayIterator<const IContactInfo*>;
template class SHIB_EXPORTS saml::Iterator<const IAuthority*>;
virtual DOMNode* toDOM(DOMDocument* doc=NULL, bool xmlns=true) const;
virtual saml::SAMLObject* clone() const;
- virtual saml::Iterator<saml::xstring> getValues() const;
+ virtual saml::Iterator<const XMLCh*> getValues() const;
virtual saml::Iterator<std::string> getSingleByteValues() const;
protected:
virtual bool addValue(DOMElement* e);
- std::vector<saml::xstring> m_scopes;
- mutable std::vector<saml::xstring> m_scopedValues;
+ std::vector<const XMLCh*> m_scopes;
+ mutable std::vector<const XMLCh*> m_scopedValues;
};
class SHIB_EXPORTS ShibPOSTProfile
{
SAMLAttribute* attr=attrs.next();
cout << "Attribute Name: "; xmlout(cout,attr->getName()); cout << endl;
- Iterator<xstring> vals=attr->getValues();
+ Iterator<const XMLCh*> vals=attr->getValues();
while (vals.hasNext())
{
cout << "Attribute Value: ";
- xmlout(cout,vals.next().c_str());
+ xmlout(cout,vals.next());
cout << endl;
}
}