https://bugs.internet2.edu/jira/browse/SSPCPP-365 moonshot-old
authorscantor <scantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Mon, 23 May 2011 00:52:53 +0000 (00:52 +0000)
committerscantor <scantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Mon, 23 May 2011 00:52:53 +0000 (00:52 +0000)
git-svn-id: https://svn.shibboleth.net/cpp-sp/branches/REL_2@3432 cb58f699-b61c-0410-a6fe-9272a202ed29

plugins/GSSAPIAttributeExtractor.cpp
shibsp/Makefile.am
shibsp/attribute/Attribute.cpp
shibsp/attribute/BinaryAttribute.cpp [new file with mode: 0644]
shibsp/attribute/BinaryAttribute.h [new file with mode: 0644]
shibsp/shibsp-lite.vcxproj
shibsp/shibsp.vcxproj

index b17aed7..ec90a89 100644 (file)
@@ -27,6 +27,7 @@
 #include <shibsp/exceptions.h>
 #include <shibsp/Application.h>
 #include <shibsp/SPConfig.h>
+#include <shibsp/attribute/BinaryAttribute.h>
 #include <shibsp/attribute/ScopedAttribute.h>
 #include <shibsp/attribute/SimpleAttribute.h>
 #include <shibsp/attribute/resolver/AttributeExtractor.h>
@@ -273,22 +274,7 @@ void GSSAPIExtractorImpl::extractAttributes(
                 return;
             }
             if (buf.length) {
-                if (rule->second.binary) {
-                    // base64 encode the value
-                    xsecsize_t len=0;
-                    XMLByte* out=Base64::encode(reinterpret_cast<const XMLByte*>(buf.value), buf.length, &len);
-                    if (out) {
-                        values.push_back(string(reinterpret_cast<char*>(out), len));
-#ifdef SHIBSP_XERCESC_HAS_XMLBYTE_RELEASE
-                        XMLString::release(&out);
-#else
-                        XMLString::release((char**)&out);
-#endif
-                    }
-                }
-                else {
-                    values.push_back(string(reinterpret_cast<char*>(buf.value), buf.length));
-                }
+                values.push_back(string(reinterpret_cast<char*>(buf.value), buf.length));
             }
             gss_release_buffer(&minor, &buf);
         }
@@ -319,8 +305,12 @@ void GSSAPIExtractorImpl::extractAttributes(
         if (!scoped->getValues().empty())
             attributes.push_back(scoped.release());
     }
+    else if (rule->second.binary) {
+        auto_ptr<BinaryAttribute> binary(new BinaryAttribute(rule->second.ids));
+        binary->getValues() = values;
+        attributes.push_back(binary.release());
+    }
     else {
-        // If unscoped, just copy over the values.
         auto_ptr<SimpleAttribute> simple(new SimpleAttribute(rule->second.ids));
         simple->getValues() = values;
         attributes.push_back(simple.release());
index b70cd50..34ce43c 100644 (file)
@@ -45,6 +45,7 @@ libshibspinclude_HEADERS = \
 attrinclude_HEADERS = \
        attribute/Attribute.h \
        attribute/AttributeDecoder.h \
+       attribute/BinaryAttribute.h \
        attribute/ExtensibleAttribute.h \
        attribute/NameIDAttribute.h \
        attribute/ScopedAttribute.h \
@@ -112,6 +113,7 @@ common_sources = \
        SPConfig.cpp \
     version.cpp \
        attribute/Attribute.cpp \
+       attribute/BinaryAttribute.cpp \
        attribute/ExtensibleAttribute.cpp \
        attribute/NameIDAttribute.cpp \
        attribute/SimpleAttribute.cpp \
index 89f69bf..eba41df 100644 (file)
@@ -47,6 +47,7 @@ namespace shibsp {
     SHIBSP_DLLLOCAL Attribute* NameIDAttributeFactory(DDF& in);
     SHIBSP_DLLLOCAL Attribute* ExtensibleAttributeFactory(DDF& in);
     SHIBSP_DLLLOCAL Attribute* XMLAttributeFactory(DDF& in);
+    SHIBSP_DLLLOCAL Attribute* BinaryAttributeFactory(DDF& in);
 
 #ifndef SHIBSP_LITE
     SHIBSP_DLLLOCAL PluginManager<AttributeDecoder,xmltooling::QName,const DOMElement*>::Factory StringAttributeDecoderFactory;
@@ -142,6 +143,7 @@ void shibsp::registerAttributeFactories()
 {
     Attribute::registerFactory("", SimpleAttributeFactory);
     Attribute::registerFactory("Simple", SimpleAttributeFactory);
+    Attribute::registerFactory("Binary", BinaryAttributeFactory);
     Attribute::registerFactory("Scoped", ScopedAttributeFactory);
     Attribute::registerFactory("NameID", NameIDAttributeFactory);
     Attribute::registerFactory("Extensible", ExtensibleAttributeFactory);
diff --git a/shibsp/attribute/BinaryAttribute.cpp b/shibsp/attribute/BinaryAttribute.cpp
new file mode 100644 (file)
index 0000000..6851eac
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ *  Copyright 2009 Internet2
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * BinaryAttribute.cpp
+ *
+ * An Attribute whose values are binary data.
+ */
+
+#include "internal.h"
+#include "attribute/BinaryAttribute.h"
+
+#include <xercesc/util/Base64.hpp>
+
+using namespace shibsp;
+using namespace std;
+
+namespace shibsp {
+    SHIBSP_DLLLOCAL Attribute* BinaryAttributeFactory(DDF& in) {
+        return new BinaryAttribute(in);
+    }
+};
+
+BinaryAttribute::BinaryAttribute(const vector<string>& ids) : Attribute(ids)
+{
+}
+
+BinaryAttribute::BinaryAttribute(DDF& in) : Attribute(in)
+{
+    xsecsize_t x;
+    DDF val = in.first().first();
+    while (val.string()) {
+        m_serialized.push_back(val.string());
+        XMLByte* decoded=Base64::decode(reinterpret_cast<const XMLByte*>(val.string()), &x);
+        if (decoded) {
+            m_values.push_back(string(reinterpret_cast<char*>(decoded), x));
+#ifdef SHIBSP_XERCESC_HAS_XMLBYTE_RELEASE
+            XMLString::release(&decoded);
+#else
+            XMLString::release((char**)&decoded);
+#endif
+        }
+        val = in.first().next();
+    }
+}
+
+BinaryAttribute::~BinaryAttribute()
+{
+}
+
+vector<string>& BinaryAttribute::getValues()
+{
+    return m_values;
+}
+
+const vector<string>& BinaryAttribute::getValues() const
+{
+    return m_values;
+}
+
+size_t BinaryAttribute::valueCount() const
+{
+    return m_values.size();
+}
+
+void BinaryAttribute::clearSerializedValues()
+{
+    m_serialized.clear();
+}
+
+const char* BinaryAttribute::getString(size_t index) const
+{
+    return m_values[index].c_str();
+}
+
+void BinaryAttribute::removeValue(size_t index)
+{
+    Attribute::removeValue(index);
+    if (index < m_values.size())
+        m_values.erase(m_values.begin() + index);
+}
+
+const vector<string>& BinaryAttribute::getSerializedValues() const
+{
+    xsecsize_t len;
+    XMLByte *pos, *pos2;
+    if (m_serialized.empty()) {
+        for (vector<string>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
+            XMLByte* enc = Base64::encode(reinterpret_cast<const XMLByte*>(i->data()), i->size(), &len);
+            if (enc) {
+                for (pos=enc, pos2=enc; *pos2; pos2++)
+                    if (isgraph(*pos2))
+                        *pos++=*pos2;
+                *pos=0;
+                m_serialized.push_back(reinterpret_cast<char*>(enc));
+#ifdef SHIBSP_XERCESC_HAS_XMLBYTE_RELEASE
+                XMLString::release(&enc);
+#else
+                XMLString::release((char**)&enc);
+#endif
+            }
+        }
+    }
+    return Attribute::getSerializedValues();
+}
+
+DDF BinaryAttribute::marshall() const
+{
+    DDF ddf = Attribute::marshall();
+    ddf.name("Binary");
+    DDF vlist = ddf.first();
+    const vector<string>& encoded = getSerializedValues();
+    for (vector<string>::const_iterator i = encoded.begin(); i != encoded.end(); ++i) {
+        DDF val = DDF(nullptr).string(i->c_str());
+        vlist.add(val);
+    }
+    return ddf;
+}
diff --git a/shibsp/attribute/BinaryAttribute.h b/shibsp/attribute/BinaryAttribute.h
new file mode 100644 (file)
index 0000000..d837620
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ *  Copyright 2001-2009 Internet2
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file shibsp/attribute/BinaryAttribute.h
+ * 
+ * An Attribute whose values are binary data.
+ */
+
+#ifndef __shibsp_binattr_h__
+#define __shibsp_binattr_h__
+
+#include <shibsp/attribute/Attribute.h>
+
+namespace shibsp {
+
+#if defined (_MSC_VER)
+    #pragma warning( push )
+    #pragma warning( disable : 4251 )
+#endif
+
+    /**
+     * An Attribute whose values are binary data.
+     * 
+     * <p>Binary attributes use base64 encoding to serialize their values.
+     * The original binary values are accessible in the underlying value
+     * collection.
+     */
+    class SHIBSP_API BinaryAttribute : public Attribute
+    {
+    public:
+        /**
+         * Constructor.
+         * 
+         * @param ids   array with primary identifier in first position, followed by any aliases
+         */
+        BinaryAttribute(const std::vector<std::string>& ids);
+
+        /**
+         * Constructs based on a remoted BinaryAttribute.
+         * 
+         * @param in    input object containing marshalled BinaryAttribute
+         */
+        BinaryAttribute(DDF& in);
+        
+        virtual ~BinaryAttribute();
+
+        /**
+         * Returns the set of raw binary values.
+         * 
+         * @return  a mutable vector of the values
+         */
+        std::vector<std::string>& getValues();
+
+        /**
+         * Returns the set of raw binary values.
+         * 
+         * @return  an immutable vector of the values
+         */
+        const std::vector<std::string>& getValues() const;
+
+        // Virtual function overrides.
+        size_t valueCount() const;
+        void clearSerializedValues();
+        const char* getString(size_t index) const;
+        void removeValue(size_t index);
+        const std::vector<std::string>& getSerializedValues() const;
+        DDF marshall() const;
+    
+    private:
+        std::vector<std::string> m_values;
+    };
+
+#if defined (_MSC_VER)
+    #pragma warning( pop )
+#endif
+
+};
+
+#endif /* __shibsp_scopedattr_h__ */
index 2bbd998..9296ba0 100644 (file)
     <ClCompile Include="impl\XMLRequestMapper.cpp" />\r
     <ClCompile Include="impl\XMLServiceProvider.cpp" />\r
     <ClCompile Include="attribute\Attribute.cpp" />\r
+    <ClCompile Include="attribute\BinaryAttribute.cpp" />\r
     <ClCompile Include="attribute\ExtensibleAttribute.cpp" />\r
     <ClCompile Include="attribute\NameIDAttribute.cpp" />\r
     <ClCompile Include="attribute\ScopedAttribute.cpp" />\r
     <ClInclude Include="remoting\ddf.h" />\r
     <ClInclude Include="remoting\ListenerService.h" />\r
     <ClInclude Include="attribute\Attribute.h" />\r
+    <ClCompile Include="attribute\BinaryAttribute.h" />\r
     <ClInclude Include="attribute\ExtensibleAttribute.h" />\r
     <ClInclude Include="attribute\NameIDAttribute.h" />\r
     <ClInclude Include="attribute\ScopedAttribute.h" />\r
index 6f7e164..17dcd08 100644 (file)
     <ClCompile Include="impl\XMLRequestMapper.cpp" />\r
     <ClCompile Include="impl\XMLServiceProvider.cpp" />\r
     <ClCompile Include="attribute\Attribute.cpp" />\r
+    <ClCompile Include="attribute\BinaryAttribute.cpp" />\r
     <ClCompile Include="attribute\DOMAttributeDecoder.cpp" />\r
     <ClCompile Include="attribute\ExtensibleAttribute.cpp" />\r
     <ClCompile Include="attribute\KeyInfoAttributeDecoder.cpp" />\r
     <ClInclude Include="remoting\ddf.h" />\r
     <ClInclude Include="remoting\ListenerService.h" />\r
     <ClInclude Include="attribute\Attribute.h" />\r
+    <ClCompile Include="attribute\BinaryAttribute.h" />\r
     <ClInclude Include="attribute\AttributeDecoder.h" />\r
     <ClInclude Include="attribute\ExtensibleAttribute.h" />\r
     <ClInclude Include="attribute\NameIDAttribute.h" />\r