- try {
- DOMDocument *doc;
- const XMLObjectBuilder *b;
- DOMElement *elem;
- XMLObject *xobj;
- string samlBuf((char *)buffer->value, buffer->length);
- istringstream samlIn(samlBuf);
-
- doc = XMLToolingConfig::getConfig().getParser().parse(samlIn);
- b = XMLObjectBuilder::getDefaultBuilder();
- elem = doc->getDocumentElement();
- xobj = b->buildOneFromElement(elem, true);
-
- *pAssertion = dynamic_cast<saml2::Assertion *>(xobj);
- if (*pAssertion == NULL) {
- /* TODO minor_status */
- return GSS_S_BAD_NAME;
+ DDF version = obj["version"];
+ if (version.integer() != 1)
+ return NULL;
+
+ DDF assertion = obj["assertion"];
+ gss_buffer_desc buffer;
+
+ if (!assertion.isnull()) {
+ buffer.length = assertion.strlen();
+ buffer.value = (void *)assertion.string();
+ } else {
+ buffer.length = 0;
+ }
+
+ if (buffer.length != 0)
+ ctx->parseAssertion(&buffer);
+
+ DDF attrs = obj["attributes"];
+ DDF attr = attrs.first();
+ while (!attr.isnull()) {
+ Attribute *attribute = Attribute::unmarshall(attr);
+ ctx->addAttribute(attribute, false);
+ attr = attrs.next();
+ }
+
+ return ctx;
+}
+
+void
+gss_eap_saml_attr_ctx::marshall(gss_buffer_t buffer)
+{
+ DDF obj = marshall();
+ ostringstream sink;
+ sink << obj;
+ string str = sink.str();
+
+ duplicateBuffer(str, buffer);
+
+ obj.destroy();
+}
+
+gss_eap_saml_attr_ctx *
+gss_eap_saml_attr_ctx::unmarshall(const gss_buffer_t buffer)
+{
+ gss_eap_saml_attr_ctx *ctx;
+
+ string str((const char *)buffer->value, buffer->length);
+ istringstream source(str);
+ DDF obj(NULL);
+ source >> obj;
+
+ ctx = unmarshall(obj);
+
+ obj.destroy();
+
+ return ctx;
+}
+
+bool
+gss_eap_saml_attr_ctx::getAssertion(gss_buffer_t buffer)
+{
+ string str;
+
+ if (m_assertion == NULL)
+ return false;
+
+ buffer->value = NULL;
+ buffer->length = 0;
+
+ XMLHelper::serialize(m_assertion->marshall((DOMDocument *)NULL), str);
+
+ duplicateBuffer(str, buffer);
+
+ return true;
+}
+
+static Attribute *
+duplicateAttribute(const Attribute *src)
+{
+ Attribute *attribute;
+
+ DDF obj = src->marshall();
+ attribute = Attribute::unmarshall(obj);
+ obj.destroy();
+
+ return attribute;
+}
+
+static vector <Attribute *>
+duplicateAttributes(const vector <Attribute *>src)
+{
+ vector <Attribute *> dst;
+
+ for (vector<Attribute *>::const_iterator a = src.begin();
+ a != src.end();
+ ++a)
+ dst.push_back(duplicateAttribute(*a));
+
+ return dst;
+}
+
+void
+gss_eap_saml_attr_ctx::addAttribute(Attribute *attribute, bool copy)
+{
+ Attribute *a;
+
+ a = copy ? duplicateAttribute(attribute) : attribute;
+
+ m_attributes.push_back(a);
+}
+
+void
+gss_eap_saml_attr_ctx::setAttributes(const vector<Attribute*> attributes)
+{
+ for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());
+ m_attributes = attributes;
+}
+
+int
+gss_eap_saml_attr_ctx::getAttributeIndex(const gss_buffer_t attr) const
+{
+ int i = 0;
+
+ for (vector<Attribute *>::const_iterator a = getAttributes().begin();
+ a != getAttributes().end();
+ ++a)
+ {
+ for (vector<string>::const_iterator s = (*a)->getAliases().begin();
+ s != (*a)->getAliases().end();
+ ++s) {
+ if (attr->length == (*s).length() &&
+ memcmp((*s).c_str(), attr->value, attr->length) == 0) {
+ return i;
+ }