4d07af18645b1183cc187fdeccd9bf956d25b004
[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(const gss_buffer_t buffer) {
118         parseAssertion(buffer);
119     }
120
121     eap_gss_saml_attr_ctx(const vector<Attribute*>& attributes,
122                           const Assertion *assertion = NULL) {
123         if (assertion != NULL)
124             m_assertion = dynamic_cast<Assertion *>(assertion->clone());
125         if (attributes.size())
126             setAttributes(attributes);
127     }
128
129     eap_gss_saml_attr_ctx(const eap_gss_saml_attr_ctx &ctx) {
130         eap_gss_saml_attr_ctx(ctx.m_attributes, ctx.m_assertion);
131     }
132
133     eap_gss_saml_attr_ctx() {}
134     ~eap_gss_saml_attr_ctx() {
135         for_each(m_attributes.begin(),
136                  m_attributes.end(),
137                  xmltooling::cleanup<Attribute>())
138             ;
139         delete m_assertion;
140     }
141
142     const vector <Attribute *> getAttributes(void) const {
143         return m_attributes;
144     }
145
146     void addAttribute(Attribute *attr, bool copy = true);
147     void setAttributes(const vector<Attribute*> attributes);
148
149     void setAttribute(int complete,
150                       const gss_buffer_t attr,
151                       const gss_buffer_t value);
152     void deleteAttribute(const gss_buffer_t attr);
153
154     int getAttributeIndex(const gss_buffer_t attr) const;
155     const Attribute *getAttribute(const gss_buffer_t attr) const;
156
157     bool getAttribute(const gss_buffer_t attr,
158                       int *authenticated,
159                       int *complete,
160                       gss_buffer_t value,
161                       gss_buffer_t display_value,
162                       int *more);
163
164     const Assertion *getAssertion(void) const {
165         return m_assertion;
166     }
167
168     bool getAssertion(gss_buffer_t buffer);
169
170     DDF marshall() const;
171     static eap_gss_saml_attr_ctx *unmarshall(DDF &in);
172
173     void marshall(gss_buffer_t buffer);
174     static eap_gss_saml_attr_ctx *unmarshall(const gss_buffer_t buffer);
175
176 private:
177     mutable vector<Attribute*> m_attributes;
178     mutable Assertion *m_assertion;
179
180     bool parseAssertion(const gss_buffer_t buffer);
181 };
182
183 static OM_uint32
184 mapException(OM_uint32 *minor, exception &e)
185 {
186     *minor = 0;
187     return GSS_S_FAILURE;
188 }
189
190 bool
191 eap_gss_saml_attr_ctx::parseAssertion(const gss_buffer_t buffer)
192 {
193     DOMDocument *doc;
194     const XMLObjectBuilder *b;
195     DOMElement *elem;
196     XMLObject *xobj;
197     string str((char *)buffer->value, buffer->length);
198     istringstream istream(str);
199
200     doc = XMLToolingConfig::getConfig().getParser().parse(istream);
201     b = XMLObjectBuilder::getDefaultBuilder();
202     elem = doc->getDocumentElement();
203     xobj = b->buildOneFromElement(elem, true);
204
205     m_assertion = dynamic_cast<Assertion *>(xobj);
206
207     return (m_assertion != NULL);
208 }
209
210 static inline void
211 duplicateBuffer(gss_buffer_desc &src, gss_buffer_t dst)
212 {
213     OM_uint32 minor;
214
215     if (GSS_ERROR(duplicateBuffer(&minor, &src, dst)))
216         throw new bad_alloc();
217 }
218
219 static inline void
220 duplicateBuffer(string &str, gss_buffer_t buffer)
221 {
222     gss_buffer_desc tmp;
223
224     tmp.length = str.length();
225     tmp.value = (char *)str.c_str();
226
227     duplicateBuffer(tmp, buffer);
228 }
229
230 DDF
231 eap_gss_saml_attr_ctx::marshall() const
232 {
233     DDF obj(NULL);
234     DDF attrs;
235     DDF assertion;
236
237     obj.addmember("version").integer(1);
238
239     attrs = obj.addmember("attributes").list();
240     for (vector<Attribute*>::const_iterator a = m_attributes.begin();
241          a != m_attributes.end(); ++a) {
242         DDF attr = (*a)->marshall();
243         attrs.add(attr);
244     }
245
246     ostringstream sink;
247     sink << *m_assertion;
248     assertion = obj.addmember("assertion").string(sink.str().c_str());
249
250     return obj;
251 }
252
253 eap_gss_saml_attr_ctx *
254 eap_gss_saml_attr_ctx::unmarshall(DDF &obj)
255 {
256     eap_gss_saml_attr_ctx *ctx = new eap_gss_saml_attr_ctx();
257
258     DDF version = obj["version"];
259     if (version.integer() != 1)
260         return NULL;
261
262     DDF assertion = obj["assertion"];
263     gss_buffer_desc buffer;
264
265     if (!assertion.isnull()) {
266         buffer.length = assertion.strlen();
267         buffer.value = (void *)assertion.string();
268     } else {
269         buffer.length = 0;
270     }
271
272     if (buffer.length != 0)
273         ctx->parseAssertion(&buffer);
274
275     DDF attrs = obj["attributes"];
276     DDF attr = attrs.first();
277     while (!attr.isnull()) {
278         Attribute *attribute = Attribute::unmarshall(attr);
279         ctx->addAttribute(attribute, false);
280         attr = attrs.next();
281     }
282
283     return ctx;
284 }
285
286 void
287 eap_gss_saml_attr_ctx::marshall(gss_buffer_t buffer)
288 {
289     DDF obj = marshall();
290     ostringstream sink;
291     sink << obj;
292     string str = sink.str();
293
294     duplicateBuffer(str, buffer);
295
296     obj.destroy();
297 }
298
299 eap_gss_saml_attr_ctx *
300 eap_gss_saml_attr_ctx::unmarshall(const gss_buffer_t buffer)
301 {
302     eap_gss_saml_attr_ctx *ctx;
303
304     string str((const char *)buffer->value, buffer->length);
305     istringstream source(str);
306     DDF obj(NULL);
307     source >> obj;
308
309     ctx = unmarshall(obj);
310
311     obj.destroy();
312
313     return ctx;
314 }
315
316 bool
317 eap_gss_saml_attr_ctx::getAssertion(gss_buffer_t buffer)
318 {
319     string str;
320
321     if (m_assertion == NULL)
322         return false;
323
324     buffer->value = NULL;
325     buffer->length = 0;
326
327     XMLHelper::serialize(m_assertion->marshall((DOMDocument *)NULL), str);
328
329     duplicateBuffer(str, buffer);
330
331     return true;
332 }
333
334 static Attribute *
335 duplicateAttribute(const Attribute *src)
336 {
337     Attribute *attribute;
338
339     DDF obj = src->marshall();
340     attribute = Attribute::unmarshall(obj);
341     obj.destroy();
342
343     return attribute;
344 }
345
346 static vector <Attribute *>
347 duplicateAttributes(const vector <Attribute *>src)
348 {
349     vector <Attribute *> dst;
350
351     for (vector<Attribute *>::const_iterator a = src.begin();
352          a != src.end();
353          ++a)
354         dst.push_back(duplicateAttribute(*a));
355
356     return dst;
357 }
358
359 void
360 eap_gss_saml_attr_ctx::addAttribute(Attribute *attribute, bool copy)
361 {
362     Attribute *a;
363
364     a = copy ? duplicateAttribute(attribute) : attribute;
365
366     m_attributes.push_back(a);
367 }
368
369 void
370 eap_gss_saml_attr_ctx::setAttributes(const vector<Attribute*> attributes)
371 {
372     for_each(m_attributes.begin(), m_attributes.end(), xmltooling::cleanup<Attribute>());
373     m_attributes = duplicateAttributes(attributes);
374 }
375
376 int
377 eap_gss_saml_attr_ctx::getAttributeIndex(const gss_buffer_t attr) const
378 {
379     int i = 0;
380
381     for (vector<Attribute *>::const_iterator a = getAttributes().begin();
382          a != getAttributes().end();
383          ++a)
384     {
385         for (vector<string>::const_iterator s = (*a)->getAliases().begin();
386              s != (*a)->getAliases().end();
387              ++s) {
388             if (attr->length == (*s).length() &&
389                 memcmp((*s).c_str(), attr->value, attr->length) == 0) {
390                 return i;
391             }
392         }
393     }
394
395     return -1;
396 }
397
398 const Attribute *
399 eap_gss_saml_attr_ctx::getAttribute(const gss_buffer_t attr) const
400 {
401     const Attribute *ret = NULL;
402
403     for (vector<Attribute *>::const_iterator a = getAttributes().begin();
404          a != getAttributes().end();
405          ++a)
406     {
407         for (vector<string>::const_iterator s = (*a)->getAliases().begin();
408              s != (*a)->getAliases().end();
409              ++s) {
410             if (attr->length == (*s).length() &&
411                 memcmp((*s).c_str(), attr->value, attr->length) == 0) {
412                 ret = *a;
413                 break;
414             }
415         }
416         if (ret != NULL)
417             break;
418     }
419
420     return ret;
421 }
422
423 bool
424 eap_gss_saml_attr_ctx::getAttribute(const gss_buffer_t attr,
425                                     int *authenticated,
426                                     int *complete,
427                                     gss_buffer_t value,
428                                     gss_buffer_t display_value,
429                                     int *more)
430 {
431     const Attribute *shibAttr = NULL;
432     gss_buffer_desc buf;
433
434     shibAttr = getAttribute(attr);
435     if (shibAttr == NULL)
436         return false;
437
438     if (*more == -1) {
439         *more = 0;
440     } else if (*more >= (int)shibAttr->valueCount()) {
441         *more = 0;
442         return true;
443     }
444
445     buf.value = (void *)shibAttr->getString(*more);
446     buf.length = strlen((char *)buf.value);
447
448     duplicateBuffer(buf, value);
449  
450     *authenticated = TRUE;
451     *complete = FALSE;
452
453     return true;
454 }
455
456 void
457 eap_gss_saml_attr_ctx::setAttribute(int complete,
458                                     const gss_buffer_t attr,
459                                     const gss_buffer_t value)
460 {
461     string attrStr((char *)attr->value, attr->length);
462     vector <string> ids(1);
463     SimpleAttribute *a;
464
465     ids.push_back(attrStr);
466
467     a = new SimpleAttribute(ids);
468
469     if (value->length != 0) {
470         string valStr((char *)value->value, value->length);
471
472         a->getValues().push_back(valStr);        
473     }
474
475     m_attributes.push_back(a);
476 }
477
478 void
479 eap_gss_saml_attr_ctx::deleteAttribute(const gss_buffer_t attr)
480 {
481     int i;
482
483     i = getAttributeIndex(attr);
484     if (i >= 0)
485         m_attributes.erase(m_attributes.begin() + i);
486 }
487
488 OM_uint32
489 samlReleaseAttrContext(OM_uint32 *minor,
490                        struct eap_gss_saml_attr_ctx **pCtx)
491 {
492     try {
493         delete *pCtx;
494         *pCtx = NULL;
495     } catch (exception &e) {
496         return mapException(minor, e);
497     }
498
499     return GSS_S_COMPLETE;
500 }
501
502 OM_uint32
503 samlCreateAttrContext(OM_uint32 *minor,
504                       gss_buffer_t buffer,
505                       gss_name_t acceptorName,
506                       struct eap_gss_saml_attr_ctx **pCtx,
507                       time_t *pExpiryTime)
508 {
509     OM_uint32 major, tmpMinor;
510     eap_gss_saml_attr_ctx *ctx = NULL;
511     SPConfig &conf = SPConfig::getConfig();
512     ServiceProvider *sp;
513     const Application *app;
514     MetadataProvider *m;
515     gss_buffer_desc nameBuf;
516     const XMLCh *issuer = NULL;
517     saml2::NameID *subjectName = NULL;
518     saml2::Assertion *assertion;
519     ResolutionContext *resolverContext;
520
521     nameBuf.length = 0;
522     nameBuf.value = NULL;
523
524     conf.setFeatures(SPConfig::Metadata             |
525                      SPConfig::Trust                |
526                      SPConfig::AttributeResolution  |
527                      SPConfig::Credentials          |
528                      SPConfig::OutOfProcess);
529     if (!conf.init())
530         return GSS_S_FAILURE;
531     if (!conf.instantiate())
532         return GSS_S_FAILURE;
533
534     sp = conf.getServiceProvider();
535     sp->lock();
536
537     major = gss_display_name(minor, acceptorName, &nameBuf, NULL);
538     if (GSS_ERROR(major))
539         goto cleanup;
540
541     app = sp->getApplication((const char *)nameBuf.value);
542     if (app == NULL) {
543         major = GSS_S_FAILURE;
544         goto cleanup;
545     }
546
547     try {
548         ctx = new eap_gss_saml_attr_ctx(buffer);
549
550         if (assertion->getIssuer() != NULL)
551             issuer = assertion->getIssuer()->getName();
552         if (assertion->getSubject() != NULL)
553             subjectName = assertion->getSubject()->getNameID();
554         if (assertion->getConditions())
555             *pExpiryTime = assertion->getConditions()->getNotOnOrAfter()->getEpoch();
556
557         m = app->getMetadataProvider();
558         xmltooling::Locker mlocker(m);
559         MetadataProviderCriteria mc(*app, issuer,
560                                     &IDPSSODescriptor::ELEMENT_QNAME,
561                                     samlconstants::SAML20P_NS);
562         pair<const EntityDescriptor *, const RoleDescriptor *> site =
563             m->getEntityDescriptor(mc);
564         if (!site.first) {
565             auto_ptr_char temp(issuer);
566             throw MetadataException("Unable to locate metadata for IdP ($1).",
567                                     params(1,temp.get()));
568         }
569         vector<const Assertion*> tokens(1, assertion);
570         GSSEAPResolver gssResolver(NULL, (const char *)nameBuf.value);
571         resolverContext = gssResolver.resolveAttributes(*app, site.second,
572                                                         samlconstants::SAML20P_NS,
573                                                         NULL, subjectName, NULL,
574                                                         NULL, &tokens);
575         ctx->setAttributes(resolverContext->getResolvedAttributes());
576     } catch (exception &ex) {
577         major = mapException(minor, ex);
578         goto cleanup;
579     }
580
581     major = GSS_S_COMPLETE;
582     *pCtx = ctx;
583
584 cleanup:
585     sp->unlock();
586     conf.term();
587
588     if (GSS_ERROR(major))
589         delete ctx;
590     gss_release_buffer(&tmpMinor, &nameBuf);
591
592     return major;
593 }
594
595 OM_uint32
596 samlGetAttributeTypes(OM_uint32 *minor,
597                       const struct eap_gss_saml_attr_ctx *ctx,
598                       void *data,
599                       OM_uint32 (*addAttribute)(OM_uint32 *, void *, gss_buffer_t))
600 {
601     OM_uint32 major = GSS_S_COMPLETE;
602
603     if (ctx == NULL)
604         return GSS_S_COMPLETE;
605
606     for (vector<Attribute*>::const_iterator a = ctx->getAttributes().begin();
607         a != ctx->getAttributes().end();
608         ++a)
609     {
610         gss_buffer_desc attribute;
611
612         attribute.value = (void *)((*a)->getId());
613         attribute.length = strlen((char *)attribute.value);
614
615         major = addAttribute(minor, data, &attribute);
616         if (GSS_ERROR(major))
617             break;
618     }
619
620     return major;
621 }
622
623 /*
624  * SAML implementation of gss_get_name_attribute
625  */
626 OM_uint32
627 samlGetAttribute(OM_uint32 *minor,
628                  struct eap_gss_saml_attr_ctx *ctx,
629                  gss_buffer_t attr,
630                  int *authenticated,
631                  int *complete,
632                  gss_buffer_t value,
633                  gss_buffer_t display_value,
634                  int *more)
635 {
636     if (ctx == NULL)
637         return GSS_S_UNAVAILABLE;
638
639     if (!ctx->getAttribute(attr, authenticated, complete,
640                            value, display_value, more))
641         return GSS_S_UNAVAILABLE;
642
643     return GSS_S_COMPLETE;
644 }
645
646 OM_uint32
647 samlSetAttribute(OM_uint32 *minor,
648                  struct eap_gss_saml_attr_ctx *ctx,
649                  int complete,
650                  gss_buffer_t attr,
651                  gss_buffer_t value)
652 {
653     try {
654         ctx->setAttribute(complete, attr, value);
655     } catch (exception &e) {
656         return mapException(minor, e);
657     }
658
659     return GSS_S_COMPLETE;
660 }
661
662 OM_uint32
663 samlDeleteAttribute(OM_uint32 *minor,
664                     struct eap_gss_saml_attr_ctx *ctx,
665                     gss_buffer_t attr)
666 {
667     try {
668         ctx->deleteAttribute(attr);
669     } catch (exception &e) {
670         return mapException(minor, e);
671     }
672
673     return GSS_S_COMPLETE;
674 }
675
676 /*
677  * In order to implement gss_export_name and gss_export_sec_context,
678  * we need to serialise a resolved attribute context to a buffer.
679  */
680 OM_uint32
681 samlExportAttrContext(OM_uint32 *minor,
682                       struct eap_gss_saml_attr_ctx *ctx,
683                       gss_buffer_t buffer)
684 {
685     try {
686         ctx->marshall(buffer);
687     } catch (exception &e) {
688         return mapException(minor, e);
689     }        
690
691     return GSS_S_COMPLETE;
692 }
693
694 /*
695  * In order to implement gss_import_name and gss_import_sec_context,
696  * we need to deserialise a resolved attribute context from a buffer.
697  */
698 OM_uint32
699 samlImportAttrContext(OM_uint32 *minor,
700                       gss_buffer_t buffer,
701                       struct eap_gss_saml_attr_ctx **pCtx)
702 {
703     try {
704         *pCtx = eap_gss_saml_attr_ctx::unmarshall(buffer);
705     } catch (exception &e) {
706         return mapException(minor, e);
707     }
708
709     return GSS_S_COMPLETE;
710 }
711
712 OM_uint32
713 samlGetAssertion(OM_uint32 *minor,
714                  struct eap_gss_saml_attr_ctx *ctx,
715                  gss_buffer_t assertion)
716 {
717     try {
718         ctx->getAssertion(assertion);
719     } catch (exception &e) {
720         return mapException(minor, e);
721     }
722
723     return GSS_S_COMPLETE;
724 }
725
726 OM_uint32
727 samlDuplicateAttrContext(OM_uint32 *minor,
728                          const struct eap_gss_saml_attr_ctx *in,
729                          struct eap_gss_saml_attr_ctx **out)
730 {
731     try {
732         *out = new eap_gss_saml_attr_ctx(*in);
733     } catch (exception &e) {
734         return mapException(minor, e);
735     }
736
737     return GSS_S_COMPLETE;
738 }
739
740 OM_uint32
741 samlMapNameToAny(OM_uint32 *minor,
742                  const struct eap_gss_saml_attr_ctx *ctx,
743                  int authenticated,
744                  gss_buffer_t type_id,
745                  gss_any_t *output)
746 {
747     if (bufferEqualString(type_id, "shibsp::Attribute")) {
748         vector <Attribute *>v = duplicateAttributes(ctx->getAttributes());
749
750         *output = (gss_any_t)new vector <Attribute *>(v);
751     } else if (bufferEqualString(type_id, "opensaml::Assertion")) {
752         *output = (gss_any_t)ctx->getAssertion()->clone();
753     } else {
754         *output = (gss_any_t)NULL;
755         return GSS_S_UNAVAILABLE;
756     }
757
758     return GSS_S_COMPLETE;
759 }
760
761 OM_uint32
762 samlReleaseAnyNameMapping(OM_uint32 *minor,
763                           const struct eap_gss_saml_attr_ctx *ctx,
764                           gss_buffer_t type_id,
765                           gss_any_t *input)
766 {
767     if (bufferEqualString(type_id, "vector<shibsp::Attribute>")) {
768         vector <Attribute *> *v = ((vector <Attribute *> *)*input);
769         delete v;
770     } else if (bufferEqualString(type_id, "opensaml::Assertion")) {
771         delete (Assertion *)*input;
772     } else {
773         return GSS_S_UNAVAILABLE;
774     }
775
776     *input = (gss_any_t)NULL;
777     return GSS_S_COMPLETE;
778 }