Change krbCred member to reauthCred to better clarify purpose
[moonshot.git] / moonshot / mech_eap / util_saml.cpp
1 /*
2  * Copyright (c) 2011, 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 /*
34  * SAML attribute provider implementation.
35  */
36
37 #include "gssapiP_eap.h"
38
39 #include <sstream>
40
41 #include <xercesc/util/XMLUniDefs.hpp>
42 #include <xmltooling/unicode.h>
43 #include <xmltooling/XMLToolingConfig.h>
44 #include <xmltooling/util/XMLHelper.h>
45 #include <xmltooling/util/ParserPool.h>
46 #include <xmltooling/util/DateTime.h>
47
48 #include <saml/exceptions.h>
49 #include <saml/saml1/core/Assertions.h>
50 #include <saml/saml2/core/Assertions.h>
51 #include <saml/saml2/metadata/Metadata.h>
52 #include <saml/saml2/metadata/MetadataProvider.h>
53
54 using namespace xmltooling;
55 using namespace opensaml::saml2md;
56 using namespace opensaml;
57 using namespace xercesc;
58 using namespace std;
59
60 static const XMLCh
61 base64Binary[] = {'b','a','s','e','6','4','B','i','n','a','r','y',0};
62
63 /*
64  * gss_eap_saml_assertion_provider is for retrieving the underlying
65  * assertion.
66  */
67 gss_eap_saml_assertion_provider::gss_eap_saml_assertion_provider(void)
68 {
69     m_assertion = NULL;
70     m_authenticated = false;
71 }
72
73 gss_eap_saml_assertion_provider::~gss_eap_saml_assertion_provider(void)
74 {
75     delete m_assertion;
76 }
77
78 bool
79 gss_eap_saml_assertion_provider::initWithExistingContext(const gss_eap_attr_ctx *manager,
80                                                          const gss_eap_attr_provider *ctx)
81 {
82     /* Then we may be creating from an existing attribute context */
83     const gss_eap_saml_assertion_provider *saml;
84
85     assert(m_assertion == NULL);
86
87     if (!gss_eap_attr_provider::initWithExistingContext(manager, ctx))
88         return false;
89
90     saml = static_cast<const gss_eap_saml_assertion_provider *>(ctx);
91     setAssertion(saml->getAssertion(), saml->authenticated());
92
93     return true;
94 }
95
96 bool
97 gss_eap_saml_assertion_provider::initWithGssContext(const gss_eap_attr_ctx *manager,
98                                                     const gss_cred_id_t gssCred,
99                                                     const gss_ctx_id_t gssCtx)
100 {
101     const gss_eap_radius_attr_provider *radius;
102     gss_buffer_desc value = GSS_C_EMPTY_BUFFER;
103     int authenticated, complete;
104     OM_uint32 minor;
105
106     assert(m_assertion == NULL);
107
108     if (!gss_eap_attr_provider::initWithGssContext(manager, gssCred, gssCtx))
109         return false;
110
111     /*
112      * XXX TODO we need to support draft-howlett-radius-saml-attr-00
113      */
114     radius = static_cast<const gss_eap_radius_attr_provider *>
115         (m_manager->getProvider(ATTR_TYPE_RADIUS));
116     if (radius != NULL &&
117         radius->getFragmentedAttribute(PW_SAML_AAA_ASSERTION,
118                                        VENDORPEC_UKERNA,
119                                        &authenticated, &complete, &value)) {
120         setAssertion(&value, authenticated);
121         gss_release_buffer(&minor, &value);
122     } else {
123         m_assertion = NULL;
124     }
125
126     return true;
127 }
128
129 void
130 gss_eap_saml_assertion_provider::setAssertion(const saml2::Assertion *assertion,
131                                               bool authenticated)
132 {
133
134     delete m_assertion;
135
136     if (assertion != NULL) {
137 #ifdef __APPLE__
138         m_assertion = (saml2::Assertion *)((void *)assertion->clone());
139 #else
140         m_assertion = dynamic_cast<saml2::Assertion *>(assertion->clone());
141 #endif
142         m_authenticated = authenticated;
143     } else {
144         m_assertion = NULL;
145         m_authenticated = false;
146     }
147 }
148
149 void
150 gss_eap_saml_assertion_provider::setAssertion(const gss_buffer_t buffer,
151                                               bool authenticated)
152 {
153     delete m_assertion;
154
155     m_assertion = parseAssertion(buffer);
156     m_authenticated = (m_assertion != NULL && authenticated);
157 }
158
159 saml2::Assertion *
160 gss_eap_saml_assertion_provider::parseAssertion(const gss_buffer_t buffer)
161 {
162     string str((char *)buffer->value, buffer->length);
163     istringstream istream(str);
164     DOMDocument *doc;
165     const XMLObjectBuilder *b;
166
167     try {
168         doc = XMLToolingConfig::getConfig().getParser().parse(istream);
169         if (doc == NULL)
170             return NULL;
171
172         b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
173
174 #ifdef __APPLE__
175         return (saml2::Assertion *)((void *)b->buildFromDocument(doc));
176 #else
177         return dynamic_cast<saml2::Assertion *>(b->buildFromDocument(doc));
178 #endif
179     } catch (exception &e) {
180         return NULL;
181     }
182 }
183
184 bool
185 gss_eap_saml_assertion_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute,
186                                                    void *data) const
187 {
188     bool ret;
189
190     /* just add the prefix */
191     if (m_assertion != NULL)
192         ret = addAttribute(m_manager, this, GSS_C_NO_BUFFER, data);
193     else
194         ret = true;
195
196     return ret;
197 }
198
199 bool
200 gss_eap_saml_assertion_provider::setAttribute(int complete GSSEAP_UNUSED,
201                                               const gss_buffer_t attr,
202                                               const gss_buffer_t value)
203 {
204     if (attr == GSS_C_NO_BUFFER || attr->length == 0) {
205         setAssertion(value);
206         return true;
207     }
208
209     return false;
210 }
211
212 bool
213 gss_eap_saml_assertion_provider::deleteAttribute(const gss_buffer_t value GSSEAP_UNUSED)
214 {
215     delete m_assertion;
216     m_assertion = NULL;
217     m_authenticated = false;
218
219     return true;
220 }
221
222 time_t
223 gss_eap_saml_assertion_provider::getExpiryTime(void) const
224 {
225     saml2::Conditions *conditions;
226     time_t expiryTime = 0;
227
228     if (m_assertion == NULL)
229         return 0;
230
231     conditions = m_assertion->getConditions();
232
233     if (conditions != NULL && conditions->getNotOnOrAfter() != NULL)
234         expiryTime = conditions->getNotOnOrAfter()->getEpoch();
235
236     return expiryTime;
237 }
238
239 OM_uint32
240 gss_eap_saml_assertion_provider::mapException(OM_uint32 *minor,
241                                               std::exception &e) const
242 {
243     if (typeid(e) == typeid(SecurityPolicyException))
244         *minor = GSSEAP_SAML_SEC_POLICY_FAILURE;
245     else if (typeid(e) == typeid(BindingException))
246         *minor = GSSEAP_SAML_BINDING_FAILURE;
247     else if (typeid(e) == typeid(ProfileException))
248         *minor = GSSEAP_SAML_PROFILE_FAILURE;
249     else if (typeid(e) == typeid(FatalProfileException))
250         *minor = GSSEAP_SAML_FATAL_PROFILE_FAILURE;
251     else if (typeid(e) == typeid(RetryableProfileException))
252         *minor = GSSEAP_SAML_RETRY_PROFILE_FAILURE;
253     else if (typeid(e) == typeid(MetadataException))
254         *minor = GSSEAP_SAML_METADATA_FAILURE;
255     else
256         return GSS_S_CONTINUE_NEEDED;
257
258     gssEapSaveStatusInfo(*minor, "%s", e.what());
259
260     return GSS_S_FAILURE;
261 }
262
263 bool
264 gss_eap_saml_assertion_provider::getAttribute(const gss_buffer_t attr,
265                                               int *authenticated,
266                                               int *complete,
267                                               gss_buffer_t value,
268                                               gss_buffer_t display_value GSSEAP_UNUSED,
269                                               int *more) const
270 {
271     string str;
272
273     if (attr != GSS_C_NO_BUFFER && attr->length != 0)
274         return false;
275
276     if (m_assertion == NULL)
277         return false;
278
279     if (*more != -1)
280         return false;
281
282     if (authenticated != NULL)
283         *authenticated = m_authenticated;
284     if (complete != NULL)
285         *complete = true;
286
287     XMLHelper::serialize(m_assertion->marshall((DOMDocument *)NULL), str);
288
289     if (value != NULL)
290         duplicateBuffer(str, value);
291     if (display_value != NULL)
292         duplicateBuffer(str, display_value);
293
294     *more = 0;
295
296     return true;
297 }
298
299 gss_any_t
300 gss_eap_saml_assertion_provider::mapToAny(int authenticated,
301                                           gss_buffer_t type_id GSSEAP_UNUSED) const
302 {
303     if (authenticated && !m_authenticated)
304         return (gss_any_t)NULL;
305
306     return (gss_any_t)m_assertion;
307 }
308
309 void
310 gss_eap_saml_assertion_provider::releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UNUSED,
311                                                        gss_any_t input) const
312 {
313     delete ((saml2::Assertion *)input);
314 }
315
316 const char *
317 gss_eap_saml_assertion_provider::prefix(void) const
318 {
319     return "urn:ietf:params:gss-eap:saml-aaa-assertion";
320 }
321
322 bool
323 gss_eap_saml_assertion_provider::init(void)
324 {
325     gss_eap_attr_ctx::registerProvider(ATTR_TYPE_SAML_ASSERTION, createAttrContext);
326     return true;
327 }
328
329 void
330 gss_eap_saml_assertion_provider::finalize(void)
331 {
332     gss_eap_attr_ctx::unregisterProvider(ATTR_TYPE_SAML_ASSERTION);
333 }
334
335 gss_eap_attr_provider *
336 gss_eap_saml_assertion_provider::createAttrContext(void)
337 {
338     return new gss_eap_saml_assertion_provider;
339 }
340
341 saml2::Assertion *
342 gss_eap_saml_assertion_provider::initAssertion(void)
343 {
344     delete m_assertion;
345     m_assertion = saml2::AssertionBuilder::buildAssertion();
346     m_authenticated = false;
347
348     return m_assertion;
349 }
350
351 /*
352  * gss_eap_saml_attr_provider is for retrieving the underlying attributes.
353  */
354 bool
355 gss_eap_saml_attr_provider::getAssertion(int *authenticated,
356                                          saml2::Assertion **pAssertion,
357                                          bool createIfAbsent) const
358 {
359     gss_eap_saml_assertion_provider *saml;
360
361     if (authenticated != NULL)
362         *authenticated = false;
363     if (pAssertion != NULL)
364         *pAssertion = NULL;
365
366     saml = static_cast<const gss_eap_saml_assertion_provider *>
367         (m_manager->getProvider(ATTR_TYPE_SAML_ASSERTION));
368     if (saml == NULL)
369         return false;
370
371     if (authenticated != NULL)
372         *authenticated = saml->authenticated();
373     if (pAssertion != NULL)
374         *pAssertion = saml->getAssertion();
375
376     if (saml->getAssertion() == NULL) {
377         if (createIfAbsent) {
378             if (authenticated != NULL)
379                 *authenticated = false;
380             if (pAssertion != NULL)
381                 *pAssertion = saml->initAssertion();
382         } else
383             return false;
384     }
385
386     return true;
387 }
388
389 bool
390 gss_eap_saml_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute,
391                                               void *data) const
392 {
393     saml2::Assertion *assertion;
394     int authenticated;
395
396     if (!getAssertion(&authenticated, &assertion))
397         return true;
398
399     /*
400      * Note: the first prefix is added by the attribute provider manager
401      *
402      * From draft-hartman-gss-eap-naming-00:
403      *
404      *   Each attribute carried in the assertion SHOULD also be a GSS name
405      *   attribute.  The name of this attribute has three parts, all separated
406      *   by an ASCII space character.  The first part is
407      *   urn:ietf:params:gss-eap:saml-attr.  The second part is the URI for
408      *   the SAML attribute name format.  The final part is the name of the
409      *   SAML attribute.  If the mechanism performs an additional attribute
410      *   query, the retrieved attributes SHOULD be GSS-API name attributes
411      *   using the same name syntax.
412      */
413     /* For each attribute statement, look for an attribute match */
414     const vector <saml2::AttributeStatement *> &statements =
415         const_cast<const saml2::Assertion *>(assertion)->getAttributeStatements();
416
417     for (vector<saml2::AttributeStatement *>::const_iterator s = statements.begin();
418         s != statements.end();
419         ++s) {
420         const vector<saml2::Attribute*> &attrs =
421             const_cast<const saml2::AttributeStatement*>(*s)->getAttributes();
422
423         for (vector<saml2::Attribute*>::const_iterator a = attrs.begin(); a != attrs.end(); ++a) {
424             const XMLCh *attributeName, *attributeNameFormat;
425             XMLCh space[2] = { ' ', 0 };
426             gss_buffer_desc utf8;
427
428             attributeName = (*a)->getName();
429             attributeNameFormat = (*a)->getNameFormat();
430             if (attributeNameFormat == NULL || attributeNameFormat[0] == '\0')
431                 attributeNameFormat = saml2::Attribute::UNSPECIFIED;
432
433             XMLCh qualifiedName[XMLString::stringLen(attributeNameFormat) + 1 +
434                                 XMLString::stringLen(attributeName) + 1];
435             XMLString::copyString(qualifiedName, attributeNameFormat);
436             XMLString::catString(qualifiedName, space);
437             XMLString::catString(qualifiedName, attributeName);
438
439             utf8.value = (void *)toUTF8(qualifiedName);
440             utf8.length = strlen((char *)utf8.value);
441
442             if (!addAttribute(m_manager, this, &utf8, data))
443                 return false;
444         }
445     }
446
447     return true;
448 }
449
450 static BaseRefVectorOf<XMLCh> *
451 decomposeAttributeName(const gss_buffer_t attr)
452 {
453     BaseRefVectorOf<XMLCh> *components;
454     string str((const char *)attr->value, attr->length);
455     auto_ptr_XMLCh qualifiedAttr(str.c_str());
456
457     components = XMLString::tokenizeString(qualifiedAttr.get());
458
459     if (components->size() != 2) {
460         delete components;
461         components = NULL;
462     }
463
464     return components;
465 }
466
467 bool
468 gss_eap_saml_attr_provider::setAttribute(int complete GSSEAP_UNUSED,
469                                          const gss_buffer_t attr,
470                                          const gss_buffer_t value)
471 {
472     saml2::Assertion *assertion;
473     saml2::Attribute *attribute;
474     saml2::AttributeValue *attributeValue;
475     saml2::AttributeStatement *attributeStatement;
476
477     if (!getAssertion(NULL, &assertion, true))
478         return false;
479
480     if (assertion->getAttributeStatements().size() != 0) {
481         attributeStatement = assertion->getAttributeStatements().front();
482     } else {
483         attributeStatement = saml2::AttributeStatementBuilder::buildAttributeStatement();
484         assertion->getAttributeStatements().push_back(attributeStatement);
485     }
486
487     /* Check the attribute name consists of name format | whsp | name */
488     BaseRefVectorOf<XMLCh> *components = decomposeAttributeName(attr);
489     if (components == NULL)
490         return false;
491
492     attribute = saml2::AttributeBuilder::buildAttribute();
493     attribute->setNameFormat(components->elementAt(0));
494     attribute->setName(components->elementAt(1));
495
496     attributeValue = saml2::AttributeValueBuilder::buildAttributeValue();
497     auto_ptr_XMLCh unistr((char *)value->value, value->length);
498     attributeValue->setTextContent(unistr.get());
499
500     attribute->getAttributeValues().push_back(attributeValue);
501
502     assert(attributeStatement != NULL);
503     attributeStatement->getAttributes().push_back(attribute);
504
505     delete components;
506
507     return true;
508 }
509
510 bool
511 gss_eap_saml_attr_provider::deleteAttribute(const gss_buffer_t attr)
512 {
513     saml2::Assertion *assertion;
514     bool ret = false;
515
516     if (!getAssertion(NULL, &assertion) ||
517         assertion->getAttributeStatements().size() == 0)
518         return false;
519
520     /* Check the attribute name consists of name format | whsp | name */
521     BaseRefVectorOf<XMLCh> *components = decomposeAttributeName(attr);
522     if (components == NULL)
523         return false;
524
525     /* For each attribute statement, look for an attribute match */
526     const vector<saml2::AttributeStatement *> &statements =
527         const_cast<const saml2::Assertion *>(assertion)->getAttributeStatements();
528
529     for (vector<saml2::AttributeStatement *>::const_iterator s = statements.begin();
530         s != statements.end();
531         ++s) {
532         const vector<saml2::Attribute *> &attrs =
533             const_cast<const saml2::AttributeStatement *>(*s)->getAttributes();
534         ssize_t index = -1, i = 0;
535
536         /* There's got to be an easier way to do this */
537         for (vector<saml2::Attribute *>::const_iterator a = attrs.begin();
538              a != attrs.end();
539              ++a) {
540             if (XMLString::equals((*a)->getNameFormat(), components->elementAt(0)) &&
541                 XMLString::equals((*a)->getName(), components->elementAt(1))) {
542                 index = i;
543                 break;
544             }
545             ++i;
546         }
547         if (index != -1) {
548             (*s)->getAttributes().erase((*s)->getAttributes().begin() + index);
549             ret = true;
550         }
551     }
552
553     delete components;
554
555     return ret;
556 }
557
558 bool
559 gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr,
560                                          int *authenticated,
561                                          int *complete,
562                                          const saml2::Attribute **pAttribute) const
563 {
564     saml2::Assertion *assertion;
565
566     if (authenticated != NULL)
567         *authenticated = false;
568     if (complete != NULL)
569         *complete = true;
570     *pAttribute = NULL;
571
572     if (!getAssertion(authenticated, &assertion) ||
573         assertion->getAttributeStatements().size() == 0)
574         return false;
575
576     /* Check the attribute name consists of name format | whsp | name */
577     BaseRefVectorOf<XMLCh> *components = decomposeAttributeName(attr);
578     if (components == NULL)
579         return false;
580
581     /* For each attribute statement, look for an attribute match */
582     const vector <saml2::AttributeStatement *> &statements =
583         const_cast<const saml2::Assertion *>(assertion)->getAttributeStatements();
584     const saml2::Attribute *ret = NULL;
585
586     for (vector<saml2::AttributeStatement *>::const_iterator s = statements.begin();
587         s != statements.end();
588         ++s) {
589         const vector<saml2::Attribute *> &attrs =
590             const_cast<const saml2::AttributeStatement*>(*s)->getAttributes();
591
592         for (vector<saml2::Attribute *>::const_iterator a = attrs.begin(); a != attrs.end(); ++a) {
593             const XMLCh *attributeName, *attributeNameFormat;
594
595             attributeName = (*a)->getName();
596             attributeNameFormat = (*a)->getNameFormat();
597             if (attributeNameFormat == NULL || attributeNameFormat[0] == '\0')
598                 attributeNameFormat = saml2::Attribute::UNSPECIFIED;
599
600             if (XMLString::equals(attributeNameFormat, components->elementAt(0)) &&
601                 XMLString::equals(attributeName, components->elementAt(1))) {
602                 ret = *a;
603                 break;
604             }
605         }
606
607         if (ret != NULL)
608             break;
609     }
610
611     delete components;
612
613     *pAttribute = ret;
614
615     return (ret != NULL);
616 }
617
618 static bool
619 isBase64EncodedAttributeValueP(const saml2::AttributeValue *av)
620 {
621     const xmltooling::QName *type = av->getSchemaType();
622
623     if (type == NULL)
624         return false;
625
626     if (!type->hasNamespaceURI() ||
627         !XMLString::equals(type->getNamespaceURI(), xmlconstants::XSD_NS))
628         return false;
629
630     if (!type->hasLocalPart() ||
631         !XMLString::equals(type->getLocalPart(), base64Binary))
632         return false;
633
634     return true;
635 }
636
637 bool
638 gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr,
639                                          int *authenticated,
640                                          int *complete,
641                                          gss_buffer_t value,
642                                          gss_buffer_t display_value,
643                                          int *more) const
644 {
645     const saml2::Attribute *a;
646     const saml2::AttributeValue *av;
647     int nvalues, i = *more;
648
649     *more = 0;
650
651     if (!getAttribute(attr, authenticated, complete, &a))
652         return false;
653
654     nvalues = a->getAttributeValues().size();
655
656     if (i == -1)
657         i = 0;
658     if (i >= nvalues)
659         return false;
660 #ifdef __APPLE__
661     av = (const saml2::AttributeValue *)((void *)(a->getAttributeValues().at(i)));
662 #else
663     av = dynamic_cast<const saml2::AttributeValue *>(a->getAttributeValues().at(i));
664 #endif
665     if (av != NULL) {
666         bool base64Encoded = isBase64EncodedAttributeValueP(av);
667
668         if (value != NULL) {
669             char *stringValue = toUTF8(av->getTextContent(), true);
670             size_t stringValueLen = strlen(stringValue);
671
672             if (base64Encoded) {
673                 ssize_t octetLen;
674
675                 value->value = GSSEAP_MALLOC(stringValueLen);
676                 if (value->value == NULL) {
677                     GSSEAP_FREE(stringValue);
678                     throw new std::bad_alloc;
679                 }
680
681                 octetLen = base64Decode(stringValue, value->value);
682                 if (octetLen < 0) {
683                     GSSEAP_FREE(value->value);
684                     GSSEAP_FREE(stringValue);
685                     value->value = NULL;
686                     return false;
687                 }
688                 value->length = octetLen;
689                 GSSEAP_FREE(stringValue);
690             } else {
691                 value->value = stringValue;
692                 value->length = stringValueLen;
693             }
694         }
695         if (display_value != NULL && base64Encoded == false) {
696             display_value->value = toUTF8(av->getTextContent(), true);
697             display_value->length = strlen((char *)value->value);
698         }
699     }
700
701     if (nvalues > ++i)
702         *more = i;
703
704     return true;
705 }
706
707 gss_any_t
708 gss_eap_saml_attr_provider::mapToAny(int authenticated GSSEAP_UNUSED,
709                                      gss_buffer_t type_id GSSEAP_UNUSED) const
710 {
711     return (gss_any_t)NULL;
712 }
713
714 void
715 gss_eap_saml_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UNUSED,
716                                                   gss_any_t input GSSEAP_UNUSED) const
717 {
718 }
719
720 const char *
721 gss_eap_saml_attr_provider::prefix(void) const
722 {
723     return "urn:ietf:params:gss-eap:saml-attr";
724 }
725
726 bool
727 gss_eap_saml_attr_provider::init(void)
728 {
729     gss_eap_attr_ctx::registerProvider(ATTR_TYPE_SAML, createAttrContext);
730     return true;
731 }
732
733 void
734 gss_eap_saml_attr_provider::finalize(void)
735 {
736     gss_eap_attr_ctx::unregisterProvider(ATTR_TYPE_SAML);
737 }
738
739 gss_eap_attr_provider *
740 gss_eap_saml_attr_provider::createAttrContext(void)
741 {
742     return new gss_eap_saml_attr_provider;
743 }
744
745 OM_uint32
746 gssEapSamlAttrProvidersInit(OM_uint32 *minor)
747 {
748     if (!gss_eap_saml_assertion_provider::init() ||
749         !gss_eap_saml_attr_provider::init()) {
750         *minor = GSSEAP_SAML_INIT_FAILURE;
751         return GSS_S_FAILURE;
752     }
753
754     return GSS_S_COMPLETE;
755 }
756
757 OM_uint32
758 gssEapSamlAttrProvidersFinalize(OM_uint32 *minor)
759 {
760     gss_eap_saml_attr_provider::finalize();
761     gss_eap_saml_assertion_provider::finalize();
762
763     *minor = 0;
764     return GSS_S_COMPLETE;
765 }