cleanup unused parameter warnings
[mech_eap.git] / util_shib.cpp
index 33280d5..04ef90f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, JANET(UK)
+ * Copyright (c) 2011, JANET(UK)
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * limitations under the License.
  */
 
+/*
+ * Local attribute provider implementation.
+ */
+
+#include <xmltooling/XMLObject.h>
+
+#include <saml/saml2/core/Assertions.h>
+
 #include <shibsp/exceptions.h>
 #include <shibsp/attribute/SimpleAttribute.h>
-#include <shibsp/handler/AssertionConsumerService.h>
-
 #include <shibresolver/resolver.h>
 
+#include <sstream>
+
 #include "gssapiP_eap.h"
 
 using namespace shibsp;
 using namespace shibresolver;
 using namespace opensaml::saml2md;
 using namespace opensaml;
-using namespace xmltooling::logging;
 using namespace xmltooling;
-using namespace xercesc;
 using namespace std;
 
 gss_eap_shib_attr_provider::gss_eap_shib_attr_provider(void)
@@ -158,15 +164,17 @@ gss_eap_shib_attr_provider::initFromGssContext(const gss_eap_attr_ctx *manager,
         return false;
 
     saml = static_cast<const gss_eap_saml_assertion_provider *>
-        (manager->getProvider(ATTR_TYPE_SAML_ASSERTION));
+        (m_manager->getProvider(ATTR_TYPE_SAML_ASSERTION));
     radius = static_cast<const gss_eap_radius_attr_provider *>
-        (manager->getProvider(ATTR_TYPE_RADIUS));
+        (m_manager->getProvider(ATTR_TYPE_RADIUS));
 
     resolver = ShibbolethResolver::create();
 
     if (gssCred != GSS_C_NO_CREDENTIAL &&
-        gss_display_name(&minor, gssCred->name, &nameBuf, NULL) == GSS_S_COMPLETE)
+        gssEapDisplayName(&minor, gssCred->name, &nameBuf, NULL) == GSS_S_COMPLETE) {
         resolver->setApplicationID((const char *)nameBuf.value);
+        gss_release_buffer(&minor, &nameBuf);
+    }
 
     m_authenticated = false;
 
@@ -181,27 +189,22 @@ gss_eap_shib_attr_provider::initFromGssContext(const gss_eap_attr_ctx *manager,
             m_authenticated = saml->authenticated();
     }
 
-    resolver->resolve();
-
-    m_attributes = resolver->getResolvedAttributes();
-    resolver->getResolvedAttributes().clear();
-
-    gss_release_buffer(&minor, &nameBuf);
+    try {
+        resolver->resolve();
+        m_attributes = resolver->getResolvedAttributes();
+        resolver->getResolvedAttributes().clear();
+    } catch (exception &e) {
+#if 0
+        delete resolver;
+        throw e;
+#endif
+    }
 
     delete resolver;
-
-#ifdef GSSEAP_DEBUG
-    gss_buffer_desc testattr = {
-        sizeof("urn:greet:greeting") - 1, (void *)"urn:greet:greeting" };
-    gss_buffer_desc testval =
-        { sizeof("Hello, GSS EAP.") - 1, (void *)"Hello, GSS EAP." };
-    setAttribute(true, &testattr, &testval);
-#endif /* GSSEAP_DEBUG */
-
     return true;
 }
 
-int
+ssize_t
 gss_eap_shib_attr_provider::getAttributeIndex(const gss_buffer_t attr) const
 {
     int i = 0;
@@ -223,8 +226,8 @@ gss_eap_shib_attr_provider::getAttributeIndex(const gss_buffer_t attr) const
     return -1;
 }
 
-void
-gss_eap_shib_attr_provider::setAttribute(int complete,
+bool
+gss_eap_shib_attr_provider::setAttribute(int complete GSSEAP_UNUSED,
                                          const gss_buffer_t attr,
                                          const gss_buffer_t value)
 {
@@ -240,9 +243,11 @@ gss_eap_shib_attr_provider::setAttribute(int complete,
 
     m_attributes.push_back(a);
     m_authenticated = false;
+
+    return true;
 }
 
-void
+bool
 gss_eap_shib_attr_provider::deleteAttribute(const gss_buffer_t attr)
 {
     int i;
@@ -252,6 +257,8 @@ gss_eap_shib_attr_provider::deleteAttribute(const gss_buffer_t attr)
         m_attributes.erase(m_attributes.begin() + i);
 
     m_authenticated = false;
+
+    return true;
 }
 
 bool
@@ -348,10 +355,13 @@ gss_eap_shib_attr_provider::getAttribute(const gss_buffer_t attr,
 
 gss_any_t
 gss_eap_shib_attr_provider::mapToAny(int authenticated,
-                                     gss_buffer_t type_id) const
+                                     gss_buffer_t type_id GSSEAP_UNUSED) const
 {
     gss_any_t output;
 
+    if (authenticated && !m_authenticated)
+        return (gss_any_t)NULL;
+
     vector <Attribute *>v = duplicateAttributes(m_attributes);
 
     output = (gss_any_t)new vector <Attribute *>(v);
@@ -360,7 +370,7 @@ gss_eap_shib_attr_provider::mapToAny(int authenticated,
 }
 
 void
-gss_eap_shib_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id,
+gss_eap_shib_attr_provider::releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UNUSED,
                                                   gss_any_t input) const
 {
     vector <Attribute *> *v = ((vector <Attribute *> *)input);
@@ -438,9 +448,7 @@ gss_eap_shib_attr_provider::init(void)
     if (!ShibbolethResolver::init())
         return false;
 
-    gss_eap_attr_ctx::registerProvider(ATTR_TYPE_LOCAL,
-                                       NULL,
-                                       gss_eap_shib_attr_provider::createAttrContext);
+    gss_eap_attr_ctx::registerProvider(ATTR_TYPE_LOCAL, NULL, createAttrContext);
 
     return true;
 }
@@ -452,6 +460,28 @@ gss_eap_shib_attr_provider::finalize(void)
     ShibbolethResolver::term();
 }
 
+OM_uint32
+gss_eap_shib_attr_provider::mapException(OM_uint32 *minor,
+                                         std::exception &e) const
+{
+    if (typeid(e) == typeid(AttributeException))
+        *minor = GSSEAP_SHIB_ATTR_FAILURE;
+    else if (typeid(e) == typeid(AttributeExtractionException))
+        *minor = GSSEAP_SHIB_ATTR_EXTRACT_FAILURE;
+    else if (typeid(e) == typeid(AttributeFilteringException))
+        *minor = GSSEAP_SHIB_ATTR_FILTER_FAILURE;
+    else if (typeid(e) == typeid(AttributeResolutionException))
+        *minor = GSSEAP_SHIB_ATTR_RESOLVE_FAILURE;
+    else if (typeid(e) == typeid(ConfigurationException))
+        *minor = GSSEAP_SHIB_CONFIG_FAILURE;
+    else if (typeid(e) == typeid(ListenerException))
+        *minor = GSSEAP_SHIB_LISTENER_FAILURE;
+    else
+        return GSS_S_CONTINUE_NEEDED;
+
+    return GSS_S_FAILURE;
+}
+
 gss_eap_attr_provider *
 gss_eap_shib_attr_provider::createAttrContext(void)
 {
@@ -484,13 +514,18 @@ gss_eap_shib_attr_provider::duplicateAttributes(const vector <Attribute *>src)
 OM_uint32
 gssEapLocalAttrProviderInit(OM_uint32 *minor)
 {
-    return gss_eap_shib_attr_provider::init()
-        ? GSS_S_COMPLETE : GSS_S_FAILURE;
+    if (!gss_eap_shib_attr_provider::init()) {
+        *minor = GSSEAP_SHIB_INIT_FAILURE;
+        return GSS_S_FAILURE;
+    }
+    return GSS_S_COMPLETE;
 }
 
 OM_uint32
 gssEapLocalAttrProviderFinalize(OM_uint32 *minor)
 {
     gss_eap_shib_attr_provider::finalize();
+
+    *minor = 0;
     return GSS_S_COMPLETE;
 }