Better error reporting through com_err
[mech_eap.git] / util_shib.cpp
index 94441c8..a37329f 100644 (file)
  * limitations under the License.
  */
 
-#include "gssapiP_eap.h"
-
-#include <shibsp/Application.h>
 #include <shibsp/exceptions.h>
-#include <shibsp/SPConfig.h>
-#include <shibsp/ServiceProvider.h>
-#include <shibsp/attribute/Attribute.h>
 #include <shibsp/attribute/SimpleAttribute.h>
-#include <shibsp/attribute/resolver/ResolutionContext.h>
-#include <shibsp/handler/AssertionConsumerService.h>
-#include <shibsp/metadata/MetadataProviderCriteria.h>
-#include <shibsp/util/SPConstants.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)
@@ -165,14 +157,14 @@ 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);
 
     m_authenticated = false;
@@ -197,14 +189,6 @@ gss_eap_shib_attr_provider::initFromGssContext(const gss_eap_attr_ctx *manager,
 
     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;
 }
 
@@ -359,6 +343,9 @@ gss_eap_shib_attr_provider::mapToAny(int authenticated,
 {
     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);
@@ -442,25 +429,8 @@ gss_eap_shib_attr_provider::initFromBuffer(const gss_eap_attr_ctx *ctx,
 bool
 gss_eap_shib_attr_provider::init(void)
 {
-#if 1
-    SPConfig& conf=SPConfig::getConfig();
-    conf.setFeatures(
-        SPConfig::Metadata |
-        SPConfig::Trust |
-        SPConfig::AttributeResolution |
-        SPConfig::Credentials |
-        SPConfig::OutOfProcess
-        );
-    if (!conf.init())
-        return false;
-    if (!conf.instantiate()) {
-        conf.term();
-        return false;
-    }
-#else
     if (!ShibbolethResolver::init())
         return false;
-#endif
 
     gss_eap_attr_ctx::registerProvider(ATTR_TYPE_LOCAL,
                                        NULL,
@@ -473,7 +443,7 @@ void
 gss_eap_shib_attr_provider::finalize(void)
 {
     gss_eap_attr_ctx::unregisterProvider(ATTR_TYPE_LOCAL);
-//    ShibbolethResolver::term();
+    ShibbolethResolver::term();
 }
 
 gss_eap_attr_provider *
@@ -508,8 +478,11 @@ 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