Add option to make attributes internal only.
[shibboleth/cpp-sp.git] / shibsp / attribute / StringAttributeDecoder.cpp
index 4e0bcfb..f2a9d6f 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
- *  Copyright 2001-2007 Internet2\r
- * \r
+ *  Copyright 2001-2009 Internet2\r
+ *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
@@ -16,7 +16,7 @@
 \r
 /**\r
  * StringAttributeDecoder.cpp\r
- * \r
+ *\r
  * Decodes SAML into SimpleAttributes\r
  */\r
 \r
@@ -24,7 +24,6 @@
 #include "attribute/AttributeDecoder.h"\r
 #include "attribute/SimpleAttribute.h"\r
 \r
-#include <log4cpp/Category.hh>\r
 #include <saml/saml1/core/Assertions.h>\r
 #include <saml/saml2/core/Assertions.h>\r
 \r
@@ -32,7 +31,6 @@ using namespace shibsp;
 using namespace opensaml::saml1;\r
 using namespace opensaml::saml2;\r
 using namespace xmltooling;\r
-using namespace log4cpp;\r
 using namespace std;\r
 \r
 namespace shibsp {\r
@@ -43,7 +41,7 @@ namespace shibsp {
         ~StringAttributeDecoder() {}\r
 \r
         shibsp::Attribute* decode(\r
-            const char* id, const XMLObject* xmlObject, const char* assertingParty=NULL, const char* relyingParty=NULL\r
+            const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty=NULL, const char* relyingParty=NULL\r
             ) const;\r
     };\r
 \r
@@ -54,16 +52,15 @@ namespace shibsp {
 };\r
 \r
 shibsp::Attribute* StringAttributeDecoder::decode(\r
-    const char* id, const XMLObject* xmlObject, const char* assertingParty, const char* relyingParty\r
+    const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty, const char* relyingParty\r
     ) const\r
 {\r
     char* val;\r
-    auto_ptr<SimpleAttribute> simple(new SimpleAttribute(id));\r
-    simple->setCaseSensitive(m_caseSensitive);\r
+    auto_ptr<SimpleAttribute> simple(new SimpleAttribute(ids));\r
     vector<string>& dest = simple->getValues();\r
     vector<XMLObject*>::const_iterator v,stop;\r
 \r
-    Category& log = Category::getInstance(SHIBSP_LOGCAT".AttributeDecoder");\r
+    Category& log = Category::getInstance(SHIBSP_LOGCAT".AttributeDecoder.String");\r
 \r
     if (xmlObject && XMLString::equals(opensaml::saml1::Attribute::LOCAL_NAME,xmlObject->getElementQName().getLocalPart())) {\r
         const opensaml::saml2::Attribute* saml2attr = dynamic_cast<const opensaml::saml2::Attribute*>(xmlObject);\r
@@ -73,7 +70,10 @@ shibsp::Attribute* StringAttributeDecoder::decode(
             stop = values.end();\r
             if (log.isDebugEnabled()) {\r
                 auto_ptr_char n(saml2attr->getName());\r
-                log.debug("decoding SimpleAttribute (%s) from SAML 2 Attribute (%s) with %lu value(s)", id, n.get() ? n.get() : "unnamed", values.size());\r
+                log.debug(\r
+                    "decoding SimpleAttribute (%s) from SAML 2 Attribute (%s) with %lu value(s)",\r
+                    ids.front().c_str(), n.get() ? n.get() : "unnamed", values.size()\r
+                    );\r
             }\r
         }\r
         else {\r
@@ -84,7 +84,10 @@ shibsp::Attribute* StringAttributeDecoder::decode(
                 stop = values.end();\r
                 if (log.isDebugEnabled()) {\r
                     auto_ptr_char n(saml1attr->getAttributeName());\r
-                    log.debug("decoding SimpleAttribute (%s) from SAML 1 Attribute (%s) with %lu value(s)", id, n.get() ? n.get() : "unnamed", values.size());\r
+                log.debug(\r
+                    "decoding SimpleAttribute (%s) from SAML 1 Attribute (%s) with %lu value(s)",\r
+                    ids.front().c_str(), n.get() ? n.get() : "unnamed", values.size()\r
+                    );\r
                 }\r
             }\r
             else {\r
@@ -107,14 +110,14 @@ shibsp::Attribute* StringAttributeDecoder::decode(
             }\r
         }\r
 \r
-        return dest.empty() ? NULL : simple.release();\r
+        return dest.empty() ? NULL : _decode(simple.release());\r
     }\r
 \r
     const NameID* saml2name = dynamic_cast<const NameID*>(xmlObject);\r
     if (saml2name) {\r
         if (log.isDebugEnabled()) {\r
             auto_ptr_char f(saml2name->getFormat());\r
-            log.debug("decoding SimpleAttribute (%s) from SAML 2 NameID with Format (%s)", id, f.get() ? f.get() : "unspecified");\r
+            log.debug("decoding SimpleAttribute (%s) from SAML 2 NameID with Format (%s)", ids.front().c_str(), f.get() ? f.get() : "unspecified");\r
         }\r
         val = toUTF8(saml2name->getName());\r
     }\r
@@ -123,7 +126,10 @@ shibsp::Attribute* StringAttributeDecoder::decode(
         if (saml1name) {\r
             if (log.isDebugEnabled()) {\r
                 auto_ptr_char f(saml1name->getFormat());\r
-                log.debug("decoding SimpleAttribute (%s) from SAML 1 NameIdentifier with Format (%s)", id, f.get() ? f.get() : "unspecified");\r
+                log.debug(\r
+                    "decoding SimpleAttribute (%s) from SAML 1 NameIdentifier with Format (%s)",\r
+                    ids.front().c_str(), f.get() ? f.get() : "unspecified"\r
+                    );\r
             }\r
             val = toUTF8(saml1name->getName());\r
         }\r
@@ -138,5 +144,5 @@ shibsp::Attribute* StringAttributeDecoder::decode(
     else\r
         log.warn("ignoring empty NameID");\r
     delete[] val;\r
-    return dest.empty() ? NULL : simple.release();\r
+    return dest.empty() ? NULL : _decode(simple.release());\r
 }\r