#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>
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);
}
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());
attrinclude_HEADERS = \
attribute/Attribute.h \
attribute/AttributeDecoder.h \
+ attribute/BinaryAttribute.h \
attribute/ExtensibleAttribute.h \
attribute/NameIDAttribute.h \
attribute/ScopedAttribute.h \
SPConfig.cpp \
version.cpp \
attribute/Attribute.cpp \
+ attribute/BinaryAttribute.cpp \
attribute/ExtensibleAttribute.cpp \
attribute/NameIDAttribute.cpp \
attribute/SimpleAttribute.cpp \
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;
{
Attribute::registerFactory("", SimpleAttributeFactory);
Attribute::registerFactory("Simple", SimpleAttributeFactory);
+ Attribute::registerFactory("Binary", BinaryAttributeFactory);
Attribute::registerFactory("Scoped", ScopedAttributeFactory);
Attribute::registerFactory("NameID", NameIDAttributeFactory);
Attribute::registerFactory("Extensible", ExtensibleAttributeFactory);
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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__ */
<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
<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