Fixes for Heimdal (macOS) builds from Stefan.
[mech_eap.git] / 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/SAMLConfig.h>
50 #include <saml/saml1/core/Assertions.h>
51 #include <saml/saml2/core/Assertions.h>
52 #include <saml/saml2/metadata/Metadata.h>
53 #include <saml/saml2/metadata/MetadataProvider.h>
54
55 using namespace xmltooling;
56 using namespace opensaml::saml2md;
57 using namespace opensaml;
58 using namespace xercesc;
59 using namespace std;
60
61 static const XMLCh
62 base64Binary[] = {'b','a','s','e','6','4','B','i','n','a','r','y',0};
63
64 /*
65  * gss_eap_saml_assertion_provider is for retrieving the underlying
66  * assertion.
67  */
68 gss_eap_saml_assertion_provider::gss_eap_saml_assertion_provider(void)
69 {
70     m_assertion = NULL;
71     m_authenticated = false;
72 }
73
74 gss_eap_saml_assertion_provider::~gss_eap_saml_assertion_provider(void)
75 {
76     delete m_assertion;
77 }
78
79 bool
80 gss_eap_saml_assertion_provider::initWithExistingContext(const gss_eap_attr_ctx *manager,
81                                                          const gss_eap_attr_provider *ctx)
82 {
83     /* Then we may be creating from an existing attribute context */
84     const gss_eap_saml_assertion_provider *saml;
85
86     GSSEAP_ASSERT(m_assertion == NULL);
87
88     if (!gss_eap_attr_provider::initWithExistingContext(manager, ctx))
89         return false;
90
91     saml = static_cast<const gss_eap_saml_assertion_provider *>(ctx);
92     setAssertion(saml->getAssertion(), saml->authenticated());
93
94     return true;
95 }
96
97 bool
98 gss_eap_saml_assertion_provider::initWithGssContext(const gss_eap_attr_ctx *manager,
99                                                     const gss_cred_id_t gssCred,
100                                                     const gss_ctx_id_t gssCtx)
101 {
102     const gss_eap_radius_attr_provider *radius;
103     gss_buffer_desc value = GSS_C_EMPTY_BUFFER;
104     int authenticated, complete;
105     OM_uint32 minor;
106     gss_eap_attrid attrid(VENDORPEC_UKERNA, PW_SAML_AAA_ASSERTION);
107
108     GSSEAP_ASSERT(m_assertion == NULL);
109
110     if (!gss_eap_attr_provider::initWithGssContext(manager, gssCred, gssCtx))
111         return false;
112
113     /*
114      * XXX TODO we need to support draft-howlett-radius-saml-attr-00
115      */
116     radius = static_cast<const gss_eap_radius_attr_provider *>
117         (m_manager->getProvider(ATTR_TYPE_RADIUS));
118     if (radius != NULL &&
119         radius->getFragmentedAttribute(attrid, &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:federated-saml-assertion";
320 }
321
322 bool
323 gss_eap_saml_assertion_provider::init(void)
324 {
325     bool ret = false;
326
327     try {
328         ret = SAMLConfig::getConfig().init();
329     } catch (exception &e) {
330     }
331
332     if (ret)
333         gss_eap_attr_ctx::registerProvider(ATTR_TYPE_SAML_ASSERTION, createAttrContext);
334
335     return ret;
336 }
337
338 void
339 gss_eap_saml_assertion_provider::finalize(void)
340 {
341     gss_eap_attr_ctx::unregisterProvider(ATTR_TYPE_SAML_ASSERTION);
342 }
343
344 gss_eap_attr_provider *
345 gss_eap_saml_assertion_provider::createAttrContext(void)
346 {
347     return new gss_eap_saml_assertion_provider;
348 }
349
350 saml2::Assertion *
351 gss_eap_saml_assertion_provider::initAssertion(void)
352 {
353     delete m_assertion;
354     m_assertion = saml2::AssertionBuilder::buildAssertion();
355     m_authenticated = false;
356
357     return m_assertion;
358 }
359
360 /*
361  * gss_eap_saml_attr_provider is for retrieving the underlying attributes.
362  */
363 bool
364 gss_eap_saml_attr_provider::getAssertion(int *authenticated,
365                                          saml2::Assertion **pAssertion,
366                                          bool createIfAbsent) const
367 {
368     gss_eap_saml_assertion_provider *saml;
369
370     if (authenticated != NULL)
371         *authenticated = false;
372     if (pAssertion != NULL)
373         *pAssertion = NULL;
374
375     saml = static_cast<gss_eap_saml_assertion_provider *>
376         (m_manager->getProvider(ATTR_TYPE_SAML_ASSERTION));
377     if (saml == NULL)
378         return false;
379
380     if (authenticated != NULL)
381         *authenticated = saml->authenticated();
382     if (pAssertion != NULL)
383         *pAssertion = saml->getAssertion();
384
385     if (saml->getAssertion() == NULL) {
386         if (createIfAbsent) {
387             if (authenticated != NULL)
388                 *authenticated = false;
389             if (pAssertion != NULL)
390                 *pAssertion = saml->initAssertion();
391         } else
392             return false;
393     }
394
395     return true;
396 }
397
398 bool
399 gss_eap_saml_attr_provider::getAttributeTypes(gss_eap_attr_enumeration_cb addAttribute,
400                                               void *data) const
401 {
402     saml2::Assertion *assertion;
403     int authenticated;
404
405     if (!getAssertion(&authenticated, &assertion))
406         return true;
407
408     /*
409      * Note: the first prefix is added by the attribute provider manager
410      *
411      * From draft-hartman-gss-eap-naming-00:
412      *
413      *   Each attribute carried in the assertion SHOULD also be a GSS name
414      *   attribute.  The name of this attribute has three parts, all separated
415      *   by an ASCII space character.  The first part is
416      *   urn:ietf:params:gss:federated-saml-attribute.  The second part is the URI for
417      *   the SAML attribute name format.  The final part is the name of the
418      *   SAML attribute.  If the mechanism performs an additional attribute
419      *   query, the retrieved attributes SHOULD be GSS-API name attributes
420      *   using the same name syntax.
421      */
422     /* For each attribute statement, look for an attribute match */
423     const vector <saml2::AttributeStatement *> &statements =
424         const_cast<const saml2::Assertion *>(assertion)->getAttributeStatements();
425
426     for (vector<saml2::AttributeStatement *>::const_iterator s = statements.begin();
427         s != statements.end();
428         ++s) {
429         const vector<saml2::Attribute*> &attrs =
430             const_cast<const saml2::AttributeStatement*>(*s)->getAttributes();
431
432         for (vector<saml2::Attribute*>::const_iterator a = attrs.begin(); a != attrs.end(); ++a) {
433             const XMLCh *attributeName, *attributeNameFormat;
434             XMLCh space[2] = { ' ', 0 };
435             gss_buffer_desc utf8;
436
437             attributeName = (*a)->getName();
438             attributeNameFormat = (*a)->getNameFormat();
439             if (attributeNameFormat == NULL || attributeNameFormat[0] == '\0')
440                 attributeNameFormat = saml2::Attribute::UNSPECIFIED;
441
442             XMLCh qualifiedName[XMLString::stringLen(attributeNameFormat) + 1 +
443                                 XMLString::stringLen(attributeName) + 1];
444             XMLString::copyString(qualifiedName, attributeNameFormat);
445             XMLString::catString(qualifiedName, space);
446             XMLString::catString(qualifiedName, attributeName);
447
448             utf8.value = (void *)toUTF8(qualifiedName);
449             utf8.length = strlen((char *)utf8.value);
450
451             if (!addAttribute(m_manager, this, &utf8, data))
452                 return false;
453         }
454     }
455
456     return true;
457 }
458
459 static BaseRefVectorOf<XMLCh> *
460 decomposeAttributeName(const gss_buffer_t attr)
461 {
462     BaseRefVectorOf<XMLCh> *components;
463     string str((const char *)attr->value, attr->length);
464     auto_ptr_XMLCh qualifiedAttr(str.c_str());
465
466     components = XMLString::tokenizeString(qualifiedAttr.get());
467
468     if (components->size() != 2) {
469         delete components;
470         components = NULL;
471     }
472
473     return components;
474 }
475
476 bool
477 gss_eap_saml_attr_provider::setAttribute(int complete GSSEAP_UNUSED,
478                                          const gss_buffer_t attr,
479                                          const gss_buffer_t value)
480 {
481     saml2::Assertion *assertion;
482     saml2::Attribute *attribute;
483     saml2::AttributeValue *attributeValue;
484     saml2::AttributeStatement *attributeStatement;
485
486     if (!getAssertion(NULL, &assertion, true))
487         return false;
488
489     if (assertion->getAttributeStatements().size() != 0) {
490         attributeStatement = assertion->getAttributeStatements().front();
491     } else {
492         attributeStatement = saml2::AttributeStatementBuilder::buildAttributeStatement();
493         assertion->getAttributeStatements().push_back(attributeStatement);
494     }
495
496     /* Check the attribute name consists of name format | whsp | name */
497     BaseRefVectorOf<XMLCh> *components = decomposeAttributeName(attr);
498     if (components == NULL)
499         return false;
500
501     attribute = saml2::AttributeBuilder::buildAttribute();
502     attribute->setNameFormat(components->elementAt(0));
503     attribute->setName(components->elementAt(1));
504
505     attributeValue = saml2::AttributeValueBuilder::buildAttributeValue();
506     auto_ptr_XMLCh unistr((char *)value->value, value->length);
507     attributeValue->setTextContent(unistr.get());
508
509     attribute->getAttributeValues().push_back(attributeValue);
510
511     GSSEAP_ASSERT(attributeStatement != NULL);
512     attributeStatement->getAttributes().push_back(attribute);
513
514     delete components;
515
516     return true;
517 }
518
519 bool
520 gss_eap_saml_attr_provider::deleteAttribute(const gss_buffer_t attr)
521 {
522     saml2::Assertion *assertion;
523     bool ret = false;
524
525     if (!getAssertion(NULL, &assertion) ||
526         assertion->getAttributeStatements().size() == 0)
527         return false;
528
529     /* Check the attribute name consists of name format | whsp | name */
530     BaseRefVectorOf<XMLCh> *components = decomposeAttributeName(attr);
531     if (components == NULL)
532         return false;
533
534     /* For each attribute statement, look for an attribute match */
535     const vector<saml2::AttributeStatement *> &statements =
536         const_cast<const saml2::Assertion *>(assertion)->getAttributeStatements();
537
538     for (vector<saml2::AttributeStatement *>::const_iterator s = statements.begin();
539         s != statements.end();
540         ++s) {
541         const vector<saml2::Attribute *> &attrs =
542             const_cast<const saml2::AttributeStatement *>(*s)->getAttributes();
543         ssize_t index = -1, i = 0;
544
545         /* There's got to be an easier way to do this */
546         for (vector<saml2::Attribute *>::const_iterator a = attrs.begin();
547              a != attrs.end();
548              ++a) {
549             if (XMLString::equals((*a)->getNameFormat(), components->elementAt(0)) &&
550                 XMLString::equals((*a)->getName(), components->elementAt(1))) {
551                 index = i;
552                 break;
553             }
554             ++i;
555         }
556         if (index != -1) {
557             (*s)->getAttributes().erase((*s)->getAttributes().begin() + index);
558             ret = true;
559         }
560     }
561
562     delete components;
563
564     return ret;
565 }
566
567 bool
568 gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr,
569                                          int *authenticated,
570                                          int *complete,
571                                          const saml2::Attribute **pAttribute) const
572 {
573     saml2::Assertion *assertion;
574
575     if (authenticated != NULL)
576         *authenticated = false;
577     if (complete != NULL)
578         *complete = true;
579     *pAttribute = NULL;
580
581     if (!getAssertion(authenticated, &assertion) ||
582         assertion->getAttributeStatements().size() == 0)
583         return false;
584
585     /* Check the attribute name consists of name format | whsp | name */
586     BaseRefVectorOf<XMLCh> *components = decomposeAttributeName(attr);
587     if (components == NULL)
588         return false;
589
590     /* For each attribute statement, look for an attribute match */
591     const vector <saml2::AttributeStatement *> &statements =
592         const_cast<const saml2::Assertion *>(assertion)->getAttributeStatements();
593     const saml2::Attribute *ret = NULL;
594
595     for (vector<saml2::AttributeStatement *>::const_iterator s = statements.begin();
596         s != statements.end();
597         ++s) {
598         const vector<saml2::Attribute *> &attrs =
599             const_cast<const saml2::AttributeStatement*>(*s)->getAttributes();
600
601         for (vector<saml2::Attribute *>::const_iterator a = attrs.begin(); a != attrs.end(); ++a) {
602             const XMLCh *attributeName, *attributeNameFormat;
603
604             attributeName = (*a)->getName();
605             attributeNameFormat = (*a)->getNameFormat();
606             if (attributeNameFormat == NULL || attributeNameFormat[0] == '\0')
607                 attributeNameFormat = saml2::Attribute::UNSPECIFIED;
608
609             if (XMLString::equals(attributeNameFormat, components->elementAt(0)) &&
610                 XMLString::equals(attributeName, components->elementAt(1))) {
611                 ret = *a;
612                 break;
613             }
614         }
615
616         if (ret != NULL)
617             break;
618     }
619
620     delete components;
621
622     *pAttribute = ret;
623
624     return (ret != NULL);
625 }
626
627 static bool
628 isBase64EncodedAttributeValueP(const saml2::AttributeValue *av)
629 {
630     const xmltooling::QName *type = av->getSchemaType();
631
632     if (type == NULL)
633         return false;
634
635     if (!type->hasNamespaceURI() ||
636         !XMLString::equals(type->getNamespaceURI(), xmlconstants::XSD_NS))
637         return false;
638
639     if (!type->hasLocalPart() ||
640         !XMLString::equals(type->getLocalPart(), base64Binary))
641         return false;
642
643     return true;
644 }
645
646 bool
647 gss_eap_saml_attr_provider::getAttribute(const gss_buffer_t attr,
648                                          int *authenticated,
649                                          int *complete,
650                                          gss_buffer_t value,
651                                          gss_buffer_t display_value,
652                                          int *more) const
653 {
654     const saml2::Attribute *a;
655     const saml2::AttributeValue *av;
656     int nvalues, i = *more;
657
658     *more = 0;
659
660     if (!getAttribute(attr, authenticated, complete, &a))
661         return false;
662
663     nvalues = a->getAttributeValues().size();
664
665     if (i == -1)
666         i = 0;
667     if (i >= nvalues)
668         return false;
669 #ifdef __APPLE__
670     av = (const saml2::AttributeValue *)((void *)(a->getAttributeValues().at(i)));
671 #else
672     av = dynamic_cast<const saml2::AttributeValue *>(a->getAttributeValues().at(i));
673 #endif
674     if (av != NULL) {
675         bool base64Encoded = isBase64EncodedAttributeValueP(av);
676
677         if (value != NULL) {
678             char *stringValue = toUTF8(av->getTextContent(), true);
679             size_t stringValueLen = strlen(stringValue);
680
681             if (base64Encoded) {
682                 ssize_t octetLen;
683
684                 value->value = GSSEAP_MALLOC(stringValueLen);
685                 if (value->value == NULL) {
686                     GSSEAP_FREE(stringValue);
687                     throw new std::bad_alloc;
688                 }
689
690                 octetLen = base64Decode(stringValue, value->value);
691                 if (octetLen < 0) {
692                     GSSEAP_FREE(value->value);
693                     GSSEAP_FREE(stringValue);
694                     value->value = NULL;
695                     return false;
696                 }
697                 value->length = octetLen;
698                 GSSEAP_FREE(stringValue);
699             } else {
700                 value->value = stringValue;
701                 value->length = stringValueLen;
702             }
703         }
704         if (display_value != NULL && base64Encoded == false) {
705             display_value->value = toUTF8(av->getTextContent(), true);
706             display_value->length = strlen((char *)display_value->value);
707         }
708     }
709
710     if (nvalues > ++i)
711         *more = i;
712
713     return true;
714 }
715
716 gss_any_t
717 gss_eap_saml_attr_provider::mapToAny(int authenticated GSSEAP_UNUSED,
718                                      gss_buffer_t type_id GSSEAP_UNUSED) const
719 {
720     return (gss_any_t)NULL;
721 }
722
723 void
724 gss_eap_saml_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UNUSED,
725                                                   gss_any_t input GSSEAP_UNUSED) const
726 {
727 }
728
729 const char *
730 gss_eap_saml_attr_provider::prefix(void) const
731 {
732     return "urn:ietf:params:gss:federated-saml-attribute";
733 }
734
735 bool
736 gss_eap_saml_attr_provider::init(void)
737 {
738     gss_eap_attr_ctx::registerProvider(ATTR_TYPE_SAML, createAttrContext);
739     return true;
740 }
741
742 void
743 gss_eap_saml_attr_provider::finalize(void)
744 {
745     gss_eap_attr_ctx::unregisterProvider(ATTR_TYPE_SAML);
746 }
747
748 gss_eap_attr_provider *
749 gss_eap_saml_attr_provider::createAttrContext(void)
750 {
751     return new gss_eap_saml_attr_provider;
752 }
753
754 OM_uint32
755 gssEapSamlAttrProvidersInit(OM_uint32 *minor)
756 {
757     if (!gss_eap_saml_assertion_provider::init() ||
758         !gss_eap_saml_attr_provider::init()) {
759         *minor = GSSEAP_SAML_INIT_FAILURE;
760         return GSS_S_FAILURE;
761     }
762
763     return GSS_S_COMPLETE;
764 }
765
766 OM_uint32
767 gssEapSamlAttrProvidersFinalize(OM_uint32 *minor)
768 {
769     gss_eap_saml_attr_provider::finalize();
770     gss_eap_saml_assertion_provider::finalize();
771
772     *minor = 0;
773     return GSS_S_COMPLETE;
774 }