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