automatically decode base64 encoded SAML values
[moonshot.git] / mech_eap / util_attr.h
index 6af4cf3..e3f3567 100644 (file)
@@ -41,6 +41,8 @@
 #include <string>
 #include <new>
 
+using namespace gss_eap_util;
+
 struct gss_eap_attr_provider;
 struct gss_eap_attr_ctx;
 
@@ -75,13 +77,13 @@ public:
         return true;
     }
 
-    virtual bool initFromExistingContext(const gss_eap_attr_ctx *manager,
+    virtual bool initWithExistingContext(const gss_eap_attr_ctx *manager,
                                          const gss_eap_attr_provider *ctx GSSEAP_UNUSED)
     {
         return initWithManager(manager);
     }
 
-    virtual bool initFromGssContext(const gss_eap_attr_ctx *manager,
+    virtual bool initWithGssContext(const gss_eap_attr_ctx *manager,
                                     const gss_cred_id_t cred GSSEAP_UNUSED,
                                     const gss_ctx_id_t ctx GSSEAP_UNUSED)
     {
@@ -121,26 +123,36 @@ public:
     {
         return NULL;
     }
+
     virtual void releaseAnyNameMapping(gss_buffer_t type_id GSSEAP_UNUSED,
                                        gss_any_t input GSSEAP_UNUSED) const
     {
     }
 
+    /* prefix to be prepended to attributes emitted by gss_get_name_attribute */
     virtual const char *prefix(void) const
     {
         return NULL;
     }
 
-    virtual void exportToBuffer(gss_buffer_t buffer GSSEAP_UNUSED) const
+    /* optional key for storing JSON dictionary */
+    virtual const char *name(void) const
     {
+        return NULL;
     }
 
-    virtual bool initFromBuffer(const gss_eap_attr_ctx *manager,
-                                const gss_buffer_t buffer GSSEAP_UNUSED)
+    virtual bool initWithJsonObject(const gss_eap_attr_ctx *manager,
+                                    JSONObject &object GSSEAP_UNUSED)
     {
         return initWithManager(manager);
     }
 
+
+    virtual JSONObject jsonRepresentation(void) const
+    {
+        return JSONObject::null();
+    }
+
     virtual time_t getExpiryTime(void) const { return 0; }
 
     virtual OM_uint32 mapException(OM_uint32 *minor GSSEAP_UNUSED,
@@ -175,8 +187,8 @@ public:
     gss_eap_attr_ctx(void);
     ~gss_eap_attr_ctx(void);
 
-    bool initFromExistingContext(const gss_eap_attr_ctx *manager);
-    bool initFromGssContext(const gss_cred_id_t cred,
+    bool initWithExistingContext(const gss_eap_attr_ctx *manager);
+    bool initWithGssContext(const gss_cred_id_t cred,
                             const gss_ctx_id_t ctx);
 
     bool getAttributeTypes(gss_eap_attr_enumeration_cb, void *data) const;
@@ -198,7 +210,7 @@ public:
                                gss_any_t input) const;
 
     void exportToBuffer(gss_buffer_t buffer) const;
-    bool initFromBuffer(const gss_buffer_t buffer);
+    bool initWithBuffer(const gss_buffer_t buffer);
 
     static std::string
     composeAttributeName(const gss_buffer_t prefix,
@@ -242,6 +254,9 @@ private:
     unsigned int attributePrefixToType(const gss_buffer_t prefix) const;
     gss_buffer_desc attributeTypeToPrefix(unsigned int type) const;
 
+    bool initWithJsonObject(JSONObject &object);
+    JSONObject jsonRepresentation(void) const;
+
     gss_eap_attr_provider *getPrimaryProvider(void) const;
 
     /* make non-copyable */
@@ -266,7 +281,7 @@ duplicateBuffer(gss_buffer_desc &src, gss_buffer_t dst)
     OM_uint32 minor;
 
     if (GSS_ERROR(duplicateBuffer(&minor, &src, dst)))
-        throw new std::bad_alloc();
+        throw std::bad_alloc();
 }
 
 static inline void