Fix DDF usage nits
[mech_eap.git] / util_saml.cpp
1 /*
2  * Copyright (c) 2010, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 /*
33  * Copyright 2001-2009 Internet2
34  * 
35  * Licensed under the Apache License, Version 2.0 (the "License");
36  * you may not use this file except in compliance with the License.
37  * You may obtain a copy of the License at
38  *
39  *     http://www.apache.org/licenses/LICENSE-2.0
40  *
41  * Unless required by applicable law or agreed to in writing, software
42  * distributed under the License is distributed on an "AS IS" BASIS,
43  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44  * See the License for the specific language governing permissions and
45  * limitations under the License.
46  */
47
48 #include <gssapi/gssapi.h>
49 #include <gssapi/gssapi_ext.h>
50 #include "util.h"
51
52 #include <shibsp/Application.h>
53 #include <shibsp/exceptions.h>
54 #include <shibsp/SPConfig.h>
55 #include <shibsp/ServiceProvider.h>
56 #include <shibsp/attribute/Attribute.h>
57 #include <shibsp/attribute/SimpleAttribute.h>
58 #include <shibsp/attribute/resolver/ResolutionContext.h>
59 #include <shibsp/handler/AssertionConsumerService.h>
60 #include <shibsp/metadata/MetadataProviderCriteria.h>
61 #include <shibsp/util/SPConstants.h>
62
63 #include <saml/saml1/core/Assertions.h>
64 #include <saml/saml2/core/Assertions.h>
65 #include <saml/saml2/metadata/Metadata.h>
66 #include <xercesc/util/XMLUniDefs.hpp>
67 #include <xmltooling/XMLToolingConfig.h>
68 #include <xmltooling/util/XMLHelper.h>
69
70 using namespace shibsp;
71 using namespace opensaml::saml2md;
72 using namespace opensaml;
73 using namespace xmltooling::logging;
74 using namespace xmltooling;
75 using namespace xercesc;
76 using namespace std;
77
78 class GSSEAPResolver : public shibsp::AssertionConsumerService
79 {
80 public:
81     GSSEAPResolver(const DOMElement *e, const char *appId)
82         : shibsp::AssertionConsumerService(e, appId, Category::getInstance(SHIBSP_LOGCAT".GSSEAPResolver")) {
83     }
84     virtual ~GSSEAPResolver() {}
85
86     ResolutionContext* resolveAttributes (
87         const Application& application,
88         const RoleDescriptor* issuer,
89         const XMLCh* protocol,
90         const saml1::NameIdentifier* v1nameid,
91         const saml2::NameID* nameid,
92         const XMLCh* authncontext_class,
93         const XMLCh* authncontext_decl,
94         const vector<const Assertion*>* tokens
95         ) const {
96             return shibsp::AssertionConsumerService::resolveAttributes(
97                     application, issuer, protocol, v1nameid,
98                     nameid, authncontext_class, authncontext_decl, tokens
99             );
100     }
101
102 private:
103     void implementProtocol(
104         const Application& application,
105         const HTTPRequest& httpRequest,
106         HTTPResponse& httpResponse,
107         SecurityPolicy& policy,
108         const PropertySet* settings,
109         const XMLObject& xmlObject
110         ) const {
111             throw FatalProfileException("Should never be called.");
112     }
113 };
114
115 struct eap_gss_saml_attr_ctx {
116 public:
117     eap_gss_saml_attr_ctx();
118     eap_gss_saml_attr_ctx(const gss_buffer_t buffer);
119     eap_gss_saml_attr_ctx(const Assertion *assertion);
120
121     eap_gss_saml_attr_ctx(const vector<Attribute*>& attributes,
122                           const Assertion *assertion);
123
124     eap_gss_saml_attr_ctx(const eap_gss_saml_attr_ctx &ctx) {
125         eap_gss_saml_attr_ctx(ctx.m_attributes, ctx.m_assertion);
126     }
127
128     ~eap_gss_saml_attr_ctx();
129
130     const vector <Attribute *> getAttributes(void) const {
131         return m_attributes;
132     }
133
134     void addAttribute(Attribute *attr, bool copy = true);
135     void setAttributes(const vector<Attribute*> attributes);
136
137     void setAttribute(int complete,
138                       const gss_buffer_t attr,
139                       const gss_buffer_t value);
140     void deleteAttribute(const gss_buffer_t attr);
141
142     int getAttributeIndex(const gss_buffer_t attr) const;
143     const Attribute *getAttribute(const gss_buffer_t attr) const;
144
145     bool getAttribute(const gss_buffer_t attr,
146                       int *authenticated,
147                       int *complete,
148                       gss_buffer_t value,
149                       gss_buffer_t display_value,
150                       int *more);
151
152     const Assertion *getAssertion(void) const {
153         return m_assertion;
154     }
155
156     bool getAssertion(gss_buffer_t buffer);
157
158     DDF marshall() const;
159     static eap_gss_saml_attr_ctx *unmarshall(DDF &in);
160
161     void marshall(gss_buffer_t buffer);
162     static eap_gss_saml_attr_ctx *unmarshall(const gss_buffer_t buffer);
163
164 private:
165     mutable vector<Attribute*> m_attributes;
166     mutable Assertion *m_assertion;
167
168     bool parseAssertion(const gss_buffer_t buffer);
169 };
170
171 eap_gss_saml_attr_ctx::eap_gss_saml_attr_ctx(const vector<Attribute*>& attributes,
172                                              const Assertion *assertion)
173 {
174     m_assertion = dynamic_cast<Assertion *>(assertion->clone());
175     setAttributes(attributes);
176 }
177
178 eap_gss_saml_attr_ctx::~eap_gss_saml_attr_ctx()
179 {
180     for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());
181     delete m_assertion;
182 }
183
184 eap_gss_saml_attr_ctx::eap_gss_saml_attr_ctx(const gss_buffer_t buffer)
185 {
186     parseAssertion(buffer);
187 }
188
189 static OM_uint32
190 mapException(OM_uint32 *minor, exception &e)
191 {
192     return GSS_S_FAILURE;
193 }
194
195 bool
196 eap_gss_saml_attr_ctx::parseAssertion(const gss_buffer_t buffer)
197 {
198     DOMDocument *doc;
199     const XMLObjectBuilder *b;
200     DOMElement *elem;
201     XMLObject *xobj;
202     string str((char *)buffer->value, buffer->length);
203     istringstream istream(str);
204
205     doc = XMLToolingConfig::getConfig().getParser().parse(istream);
206     b = XMLObjectBuilder::getDefaultBuilder();
207     elem = doc->getDocumentElement();
208     xobj = b->buildOneFromElement(elem, true);
209
210     m_assertion = dynamic_cast<Assertion *>(xobj);
211
212     return (m_assertion != NULL);
213 }
214
215 static inline void
216 duplicateBuffer(gss_buffer_desc &src, gss_buffer_t dst)
217 {
218     OM_uint32 minor;
219
220     if (GSS_ERROR(duplicateBuffer(&minor, &src, dst)))
221         throw new bad_alloc();
222 }
223
224 static inline void
225 duplicateBuffer(string &str, gss_buffer_t buffer)
226 {
227     gss_buffer_desc tmp;
228
229     tmp.length = str.length();
230     tmp.value = (char *)str.c_str();
231
232     duplicateBuffer(tmp, buffer);
233 }
234
235 DDF
236 eap_gss_saml_attr_ctx::marshall() const
237 {
238     DDF obj(NULL);
239     DDF attrs;
240     DDF assertion;
241
242     obj.addmember("version").integer(1);
243
244     attrs = obj.addmember("attributes").list();
245     for (vector<Attribute*>::const_iterator a = m_attributes.begin();
246          a != m_attributes.end(); ++a) {
247         DDF attr = (*a)->marshall();
248         attrs.add(attr);
249     }
250
251     ostringstream sink;
252     sink << *m_assertion;
253     assertion = obj.addmember("assertion").string(sink.str().c_str());
254
255     return obj;
256 }
257
258 eap_gss_saml_attr_ctx *
259 eap_gss_saml_attr_ctx::unmarshall(DDF &obj)
260 {
261     eap_gss_saml_attr_ctx *ctx = new eap_gss_saml_attr_ctx();
262
263     DDF version = obj["version"];
264     if (version.integer() != 1)
265         return NULL;
266
267     DDF assertion = obj["assertion"];
268     gss_buffer_desc buffer;
269
270     if (!assertion.isnull()) {
271         buffer.length = assertion.strlen();
272         buffer.value = (void *)assertion.string();
273     } else {
274         buffer.length = 0;
275     }
276
277     if (buffer.length != 0)
278         ctx->parseAssertion(&buffer);
279
280     DDF attrs = obj["attributes"];
281     DDF attr = attrs.first();
282     while (!attr.isnull()) {
283         Attribute *attribute = Attribute::unmarshall(attr);
284         ctx->addAttribute(attribute, false);
285         attr = attrs.next();
286     }
287
288     return ctx;
289 }
290
291 void
292 eap_gss_saml_attr_ctx::marshall(gss_buffer_t buffer)
293 {
294     DDF obj = marshall();
295     ostringstream sink;
296     sink << obj;
297     string str = sink.str();
298
299     duplicateBuffer(str, buffer);
300
301     obj.destroy();
302 }
303
304 eap_gss_saml_attr_ctx *
305 eap_gss_saml_attr_ctx::unmarshall(const gss_buffer_t buffer)
306 {
307     eap_gss_saml_attr_ctx *ctx;
308
309     string str((const char *)buffer->value, buffer->length);
310     istringstream source(str);
311     DDF obj(NULL);
312     source >> obj;
313
314     ctx = unmarshall(obj);
315
316     obj.destroy();
317
318     return ctx;
319 }
320
321 bool
322 eap_gss_saml_attr_ctx::getAssertion(gss_buffer_t buffer)
323 {
324     string str;
325
326     if (m_assertion == NULL)
327         return false;
328
329     buffer->value = NULL;
330     buffer->length = 0;
331
332     XMLHelper::serialize(m_assertion->marshall((DOMDocument *)NULL), str);
333
334     duplicateBuffer(str, buffer);
335
336     return true;
337 }
338
339 static Attribute *
340 duplicateAttribute(const Attribute *src)
341 {
342     Attribute *attribute;
343
344     DDF obj = src->marshall();
345     attribute = Attribute::unmarshall(obj);
346     obj.destroy();
347
348     return attribute;
349 }
350
351 static vector <Attribute *>
352 duplicateAttributes(const vector <Attribute *>src)
353 {
354     vector <Attribute *> dst;
355
356     for (vector<Attribute *>::const_iterator a = src.begin();
357          a != src.end();
358          ++a)
359         dst.push_back(duplicateAttribute(*a));
360
361     return dst;
362 }
363
364 void
365 eap_gss_saml_attr_ctx::addAttribute(Attribute *attribute, bool copy)
366 {
367     Attribute *a;
368
369     a = copy ? duplicateAttribute(attribute) : attribute;
370
371     m_attributes.push_back(a);
372 }
373
374 void
375 eap_gss_saml_attr_ctx::setAttributes(const vector<Attribute*> attributes)
376 {
377     for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());
378     m_attributes = duplicateAttributes(attributes);
379 }
380
381 int
382 eap_gss_saml_attr_ctx::getAttributeIndex(const gss_buffer_t attr) const
383 {
384     int i = 0;
385
386     for (vector<Attribute *>::const_iterator a = getAttributes().begin();
387          a != getAttributes().end();
388          ++a)
389     {
390         for (vector<string>::const_iterator s = (*a)->getAliases().begin();
391              s != (*a)->getAliases().end();
392              ++s) {
393             if (attr->length == (*s).length() &&
394                 memcmp((*s).c_str(), attr->value, attr->length) == 0) {
395                 return i;
396             }
397         }
398     }
399
400     return -1;
401 }
402
403 const Attribute *
404 eap_gss_saml_attr_ctx::getAttribute(const gss_buffer_t attr) const
405 {
406     const Attribute *ret = NULL;
407
408     for (vector<Attribute *>::const_iterator a = getAttributes().begin();
409          a != getAttributes().end();
410          ++a)
411     {
412         for (vector<string>::const_iterator s = (*a)->getAliases().begin();
413              s != (*a)->getAliases().end();
414              ++s) {
415             if (attr->length == (*s).length() &&
416                 memcmp((*s).c_str(), attr->value, attr->length) == 0) {
417                 ret = *a;
418                 break;
419             }
420         }
421         if (ret != NULL)
422             break;
423     }
424
425     return ret;
426 }
427
428 bool
429 eap_gss_saml_attr_ctx::getAttribute(const gss_buffer_t attr,
430                                     int *authenticated,
431                                     int *complete,
432                                     gss_buffer_t value,
433                                     gss_buffer_t display_value,
434                                     int *more)
435 {
436     const Attribute *shibAttr = NULL;
437     gss_buffer_desc buf;
438
439     shibAttr = getAttribute(attr);
440     if (shibAttr == NULL)
441         return false;
442
443     if (*more == -1) {
444         *more = 0;
445     } else if (*more >= (int)shibAttr->valueCount()) {
446         *more = 0;
447         return true;
448     }
449
450     buf.value = (void *)shibAttr->getString(*more);
451     buf.length = strlen((char *)buf.value);
452
453     duplicateBuffer(buf, value);
454  
455     *authenticated = TRUE;
456     *complete = FALSE;
457
458     return true;
459 }
460
461 void
462 eap_gss_saml_attr_ctx::setAttribute(int complete,
463                                     const gss_buffer_t attr,
464                                     const gss_buffer_t value)
465 {
466     string attrStr((char *)attr->value, attr->length);
467     vector <string> ids(1);
468     SimpleAttribute *a;
469
470     ids.push_back(attrStr);
471
472     a = new SimpleAttribute(ids);
473
474     if (value->length != 0) {
475         string valStr((char *)value->value, value->length);
476
477         a->getValues().push_back(valStr);        
478     }
479
480     m_attributes.push_back(a);
481 }
482
483 void
484 eap_gss_saml_attr_ctx::deleteAttribute(const gss_buffer_t attr)
485 {
486     int i;
487
488     i = getAttributeIndex(attr);
489     if (i >= 0)
490         m_attributes.erase(m_attributes.begin() + i);
491 }
492
493 OM_uint32
494 samlReleaseAttrContext(OM_uint32 *minor,
495                        struct eap_gss_saml_attr_ctx **pCtx)
496 {
497     eap_gss_saml_attr_ctx *ctx = *pCtx;
498
499     if (ctx != NULL) {
500         delete ctx;
501         *pCtx = NULL;
502     }
503
504     *minor = 0;
505     return GSS_S_COMPLETE;
506 }
507
508 OM_uint32
509 samlCreateAttrContext(OM_uint32 *minor,
510                       gss_buffer_t buffer,
511                       gss_name_t acceptorName,
512                       struct eap_gss_saml_attr_ctx **pCtx)
513 {
514     OM_uint32 major, tmpMinor;
515     eap_gss_saml_attr_ctx *ctx = NULL;
516     SPConfig &conf = SPConfig::getConfig();
517     ServiceProvider *sp;
518     const Application *app;
519     MetadataProvider *m;
520     gss_buffer_desc nameBuf;
521     const XMLCh *issuer = NULL;
522     saml2::NameID *subjectName = NULL;
523     saml2::Assertion *assertion;
524     ResolutionContext *resolverContext;
525
526     nameBuf.length = 0;
527     nameBuf.value = NULL;
528
529     conf.setFeatures(SPConfig::Metadata             |
530                      SPConfig::Trust                |
531                      SPConfig::AttributeResolution  |
532                      SPConfig::Credentials          |
533                      SPConfig::OutOfProcess);
534     if (!conf.init())
535         return GSS_S_FAILURE;
536     if (!conf.instantiate())
537         return GSS_S_FAILURE;
538
539     sp = conf.getServiceProvider();
540     sp->lock();
541
542     major = gss_display_name(minor, acceptorName, &nameBuf, NULL);
543     if (GSS_ERROR(major))
544         goto cleanup;
545
546     app = sp->getApplication((const char *)nameBuf.value);
547     if (app == NULL) {
548         major = GSS_S_FAILURE;
549         goto cleanup;
550     }
551
552     try {
553         ctx = new eap_gss_saml_attr_ctx(buffer);
554
555         if (assertion->getIssuer() != NULL)
556             issuer = assertion->getIssuer()->getName();
557         if (assertion->getSubject() != NULL)
558             subjectName = assertion->getSubject()->getNameID();
559
560         m = app->getMetadataProvider();
561         xmltooling::Locker mlocker(m);
562         MetadataProviderCriteria mc(*app, issuer,
563                                     &IDPSSODescriptor::ELEMENT_QNAME,
564                                     samlconstants::SAML20P_NS);
565         pair<const EntityDescriptor *, const RoleDescriptor *> site =
566             m->getEntityDescriptor(mc);
567         if (!site.first) {
568             auto_ptr_char temp(issuer);
569             throw MetadataException("Unable to locate metadata for IdP ($1).",
570                                     params(1,temp.get()));
571         }
572         vector<const Assertion*> tokens(1, assertion);
573         GSSEAPResolver gssResolver(NULL, (const char *)nameBuf.value);
574         resolverContext = gssResolver.resolveAttributes(*app, site.second,
575                                                         samlconstants::SAML20P_NS,
576                                                         NULL, subjectName, NULL,
577                                                         NULL, &tokens);
578         ctx->setAttributes(resolverContext->getResolvedAttributes());
579     } catch (exception &ex) {
580         major = mapException(minor, ex);
581         goto cleanup;
582     }
583
584     major = GSS_S_COMPLETE;
585     *pCtx = ctx;
586
587 cleanup:
588     sp->unlock();
589     conf.term();
590
591     if (GSS_ERROR(major))
592         delete ctx;
593     gss_release_buffer(&tmpMinor, &nameBuf);
594
595     return major;
596 }
597
598 OM_uint32
599 samlGetAttributeTypes(OM_uint32 *minor,
600                       const struct eap_gss_saml_attr_ctx *ctx,
601                       void *data,
602                       OM_uint32 (*addAttribute)(OM_uint32 *, void *, gss_buffer_t))
603 {
604     OM_uint32 major = GSS_S_COMPLETE;
605
606     if (ctx == NULL)
607         return GSS_S_COMPLETE;
608
609     for (vector<Attribute*>::const_iterator a = ctx->getAttributes().begin();
610         a != ctx->getAttributes().end();
611         ++a)
612     {
613         gss_buffer_desc attribute;
614
615         attribute.value = (void *)((*a)->getId());
616         attribute.length = strlen((char *)attribute.value);
617
618         major = addAttribute(minor, data, &attribute);
619         if (GSS_ERROR(major))
620             break;
621     }
622
623     return major;
624 }
625
626 /*
627  * SAML implementation of gss_get_name_attribute
628  */
629 OM_uint32
630 samlGetAttribute(OM_uint32 *minor,
631                  struct eap_gss_saml_attr_ctx *ctx,
632                  gss_buffer_t attr,
633                  int *authenticated,
634                  int *complete,
635                  gss_buffer_t value,
636                  gss_buffer_t display_value,
637                  int *more)
638 {
639     if (ctx == NULL)
640         return GSS_S_UNAVAILABLE;
641
642     if (!ctx->getAttribute(attr, authenticated, complete,
643                            value, display_value, more))
644         return GSS_S_UNAVAILABLE;
645
646     return GSS_S_COMPLETE;
647 }
648
649 OM_uint32
650 samlSetAttribute(OM_uint32 *minor,
651                  struct eap_gss_saml_attr_ctx *ctx,
652                  int complete,
653                  gss_buffer_t attr,
654                  gss_buffer_t value)
655 {
656     try {
657         ctx->setAttribute(complete, attr, value);
658     } catch (exception &e) {
659         return mapException(minor, e);
660     }
661
662     return GSS_S_COMPLETE;
663 }
664
665 OM_uint32
666 samlDeleteAttribute(OM_uint32 *minor,
667                     struct eap_gss_saml_attr_ctx *ctx,
668                     gss_buffer_t attr)
669 {
670     try {
671         ctx->deleteAttribute(attr);
672     } catch (exception &e) {
673         return mapException(minor, e);
674     }
675
676     return GSS_S_COMPLETE;
677 }
678
679 /*
680  * In order to implement gss_export_name and gss_export_sec_context,
681  * we need to serialise a resolved attribute context to a buffer.
682  */
683 OM_uint32
684 samlExportAttrContext(OM_uint32 *minor,
685                       struct eap_gss_saml_attr_ctx *ctx,
686                       gss_buffer_t buffer)
687 {
688     try {
689         ctx->marshall(buffer);
690     } catch (exception &e) {
691         return mapException(minor, e);
692     }        
693
694     return GSS_S_COMPLETE;
695 }
696
697 /*
698  * In order to implement gss_import_name and gss_import_sec_context,
699  * we need to deserialise a resolved attribute context from a buffer.
700  */
701 OM_uint32
702 samlImportAttrContext(OM_uint32 *minor,
703                       gss_buffer_t buffer,
704                       struct eap_gss_saml_attr_ctx **pCtx)
705 {
706     try {
707         *pCtx = eap_gss_saml_attr_ctx::unmarshall(buffer);
708     } catch (exception &e) {
709         return mapException(minor, e);
710     }
711
712     return GSS_S_COMPLETE;
713 }
714
715 OM_uint32
716 samlGetAssertion(OM_uint32 *minor,
717                  struct eap_gss_saml_attr_ctx *ctx,
718                  gss_buffer_t assertion)
719 {
720     try {
721         ctx->getAssertion(assertion);
722     } catch (exception &e) {
723         return mapException(minor, e);
724     }
725
726     return GSS_S_COMPLETE;
727 }
728
729 OM_uint32
730 samlDuplicateAttrContext(OM_uint32 *minor,
731                          const struct eap_gss_saml_attr_ctx *in,
732                          struct eap_gss_saml_attr_ctx **out)
733 {
734     try {
735         *out = new eap_gss_saml_attr_ctx(*in);
736     } catch (exception &e) {
737         return mapException(minor, e);
738     }
739
740     return GSS_S_COMPLETE;
741 }
742
743 OM_uint32
744 samlMapNametoAny(OM_uint32 *minor,
745                  const struct eap_gss_saml_attr_ctx *ctx,
746                  int authenticated,
747                  gss_buffer_t type_id,
748                  gss_any_t *output)
749 {
750     if (bufferEqualString(type_id, "shibsp::Attribute")) {
751         vector <Attribute *>v = duplicateAttributes(ctx->getAttributes());
752
753         *output = (gss_any_t)new vector <Attribute *>(v);
754     } else if (bufferEqualString(type_id, "opensaml::Assertion")) {
755         *output = (gss_any_t)ctx->getAssertion()->clone();
756     } else {
757         *output = (gss_any_t)NULL;
758         return GSS_S_UNAVAILABLE;
759     }
760
761     return GSS_S_COMPLETE;
762 }
763
764 OM_uint32
765 samlReleaseAnyNameMapping(OM_uint32 *minor,
766                           const struct eap_gss_saml_attr_ctx *ctx,
767                           gss_buffer_t type_id,
768                           gss_any_t *input)
769 {
770     if (bufferEqualString(type_id, "vector<shibsp::Attribute>")) {
771         vector <Attribute *> *v = ((vector <Attribute *> *)*input);
772         delete v;
773     } else if (bufferEqualString(type_id, "opensaml::Assertion")) {
774         delete (Assertion *)*input;
775     } else {
776         return GSS_S_UNAVAILABLE;
777     }
778
779     *input = (gss_any_t)NULL;
780     return GSS_S_COMPLETE;
781 }