Some draft attribute classes.
authorScott Cantor <cantor.2@osu.edu>
Fri, 19 Jan 2007 19:32:06 +0000 (19:32 +0000)
committerScott Cantor <cantor.2@osu.edu>
Fri, 19 Jan 2007 19:32:06 +0000 (19:32 +0000)
shibsp/Makefile.am
shibsp/SPConfig.cpp
shibsp/SPConfig.h
shibsp/attribute/Attribute.h [new file with mode: 0644]
shibsp/attribute/NameIDAttribute.h [new file with mode: 0644]
shibsp/attribute/ScopedAttribute.h [new file with mode: 0644]
shibsp/attribute/SimpleAttribute.h [new file with mode: 0644]
shibsp/shibsp.vcproj

index b30255b..6975ad6 100644 (file)
@@ -7,6 +7,8 @@ lib_LTLIBRARIES = libshibsp.la
 
 libshibspincludedir = $(includedir)/shibsp
 
+attrincludedir = $(includedir)/shibsp/attribute
+
 mdincludedir = $(includedir)/shibsp/metadata
 
 remincludedir = $(includedir)/shibsp/remoting
@@ -31,6 +33,12 @@ libshibspinclude_HEADERS = \
        SPRequest.h \
        version.h
 
+attrinclude_HEADERS = \
+       attribute/Attribute.h \
+       attribute/NameIDAttribute.h \
+       attribute/ScopedAttribute.h \
+       attribute/SimpleAttribute.h
+
 mdinclude_HEADERS = \
        metadata/MetadataExt.h
 
index f789410..a239229 100644 (file)
 #include "remoting/ListenerService.h"
 #include "security/PKIXTrustEngine.h"
 
+#include "attribute/SimpleAttribute.h"
+#include "attribute/ScopedAttribute.h"
+#include "attribute/NameIDAttribute.h"
+
 #include <log4cpp/Category.hh>
 #include <saml/SAMLConfig.h>
 #include <xmltooling/util/NDC.h>
index 431b753..72a51cb 100644 (file)
@@ -133,6 +133,9 @@ namespace shibsp {
             return m_serviceProvider;
         }
 
+        /** Separator for serialized values of multi-valued attributes. */
+        char attribute_value_delimeter;
+        
         /**
          * Manages factories for AccessControl plugins.
          */
@@ -184,7 +187,7 @@ namespace shibsp {
         xmltooling::PluginManager<Handler,const xercesc::DOMElement*> SingleLogoutServiceManager;
 
     protected:
-        SPConfig() : m_serviceProvider(NULL) {}
+        SPConfig() : attribute_value_delimeter(';'), m_serviceProvider(NULL), m_features(0) {}
         
         /** Global ServiceProvider instance. */
         ServiceProvider* m_serviceProvider;
diff --git a/shibsp/attribute/Attribute.h b/shibsp/attribute/Attribute.h
new file mode 100644 (file)
index 0000000..70328de
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ *  Copyright 2001-2006 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/Attribute.h
+ * 
+ * A resolved attribute.
+ */
+
+#ifndef __shibsp_attribute_h__
+#define __shibsp_attribute_h__
+
+#include <shibsp/base.h>
+
+#include <string>
+#include <vector>
+
+namespace shibsp {
+
+    /**
+     * A resolved attribute.
+     * 
+     * <p>Resolved attributes are a neutral construct that represent both simple and
+     * complex attribute data structures that might be found in SAML assertions
+     * or obtained from other sources.
+     * 
+     * <p>Attributes consist of an id/name that is locally unique (that is, unique to a
+     * configuration at any given point in time) and zero or more values. Values can
+     * be of any type or structure, but will generally be made available to applications
+     * only if a serialized string form exists. More complex values can be used with
+     * access control plugins that understand them, however. 
+     */
+    class SHIBSP_API Attribute
+    {
+        MAKE_NONCOPYABLE(Attribute);
+    protected:
+        /**
+         * Constructor
+         * 
+         * @param id    Attribute identifier 
+         */
+        Attribute(const char* id) : m_id(id) {}
+
+        /**
+         * Maintains a copy of serialized attribute values, when possible.
+         * 
+         * <p>Implementations should maintain the array when values are added or removed.
+         */
+        mutable std::vector<std::string> m_serialized;
+
+    public:
+        virtual ~Attribute() {}
+        
+        /**
+         * Returns the Attribute identifier.
+         * 
+         * @return Attribute identifier
+         */
+        const char* getId() const {
+            return m_id.c_str();
+        }
+        
+        /**
+         * Returns serialized attribute values encoded as UTF-8 strings.
+         * 
+         * @return  an immutable vector of values
+         */
+        virtual const std::vector<std::string>& getSerializedValues() const {
+            return m_serialized;
+        }
+        
+        /**
+         * Informs the attribute that values have changed and any serializations
+         * must be reset. 
+         */
+        virtual void clearSerializedValues()=0;
+        
+    private:
+        std::string m_id;
+    };
+
+};
+
+#endif /* __shibsp_attribute_h__ */
diff --git a/shibsp/attribute/NameIDAttribute.h b/shibsp/attribute/NameIDAttribute.h
new file mode 100644 (file)
index 0000000..e72a332
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ *  Copyright 2001-2006 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/NameIDAttribute.h
+ * 
+ * An Attribute whose values are relations of a value and a scope.
+ */
+
+#ifndef __shibsp_nameidattr_h__
+#define __shibsp_nameidattr_h__
+
+#include <shibsp/attribute/Attribute.h>
+#include <xmltooling/exceptions.h>
+
+namespace shibsp {
+
+    /** Default serialization format for NameIDs */
+    #define DEFAULT_NAMEID_FORMATTER    "$Name!!$NameQualifier!!$SPNameQualifier"
+
+    /**
+     * An Attribute whose values are derived from or mappable to a SAML NameID.
+     */
+    class SHIBSP_API NameIDAttribute : public Attribute
+    {
+    public:
+        /**
+         * Constructor
+         * 
+         * @param id    Attribute identifier
+         */
+        NameIDAttribute(const char* id, const char* formatter=DEFAULT_NAMEID_FORMATTER)
+            : Attribute(id), m_formatter(formatter) {
+        }
+        
+        virtual ~NameIDAttribute() {}
+        
+        /**
+         * Holds all the fields associated with a NameID.
+         */
+        struct SHIBSP_API Value
+        {
+            std::string m_Name;
+            std::string m_Format;
+            std::string m_NameQualifier;
+            std::string m_SPNameQualifier;
+            std::string m_SPProvidedID;
+        };
+        
+        /**
+         * Returns the set of values encoded as UTF-8 strings.
+         * 
+         * <p>Each compound value is a pair containing the simple value and the scope. 
+         * 
+         * @return  a mutable vector of the values
+         */
+        std::vector<Value>& getValues() {
+            return m_values;
+        }
+        
+        void clearSerializedValues() {
+            m_serialized.clear();
+        }
+        
+        const std::vector<std::string>& getSerializedValues() const {
+            if (m_serialized.empty()) {
+                for (std::vector<Value>::const_iterator i=m_values.begin(); i!=m_values.end(); ++i) {
+                    // This is kind of a hack, but it's a good way to reuse some code.
+                    xmltooling::XMLToolingException e(
+                        m_formatter,
+                        xmltooling::namedparams(
+                            5,
+                            "Name", i->m_Name,
+                            "Format", i->m_Format,
+                            "NameQualifier", i->m_NameQualifier,
+                            "SPNameQualifier", i->m_SPNameQualifier,
+                            "SPProvidedID", i->m_SPProvidedID
+                            )
+                        );
+                    m_serialized.push_back(e.what());
+                }
+            }
+            return Attribute::getSerializedValues();
+        }
+    
+    private:
+        std::vector<Value> m_values;
+        std::string m_formatter;
+    };
+
+};
+
+#endif /* __shibsp_nameidattr_h__ */
diff --git a/shibsp/attribute/ScopedAttribute.h b/shibsp/attribute/ScopedAttribute.h
new file mode 100644 (file)
index 0000000..9ee1d34
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ *  Copyright 2001-2006 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/ScopedAttribute.h
+ * 
+ * An Attribute whose values are relations of a value and a scope.
+ */
+
+#ifndef __shibsp_scopedattr_h__
+#define __shibsp_scopedattr_h__
+
+#include <shibsp/attribute/Attribute.h>
+
+namespace shibsp {
+
+    /**
+     * An Attribute whose values are relations of a value and a scope.
+     * 
+     * <p>In practice, scoped attributes are simple pairs of strings instead
+     * of a single string. They can be expressed as a string easily using a delimeter,
+     * typically an '@' symbol. The scope concept allows certain kinds of filtering to
+     * be performed more intelligently and efficiently, although not all scoped
+     * attributes can be effectively filtered (e.g. if the set of scope values is
+     * unconstrained).
+     */
+    class SHIBSP_API ScopedAttribute : public Attribute
+    {
+    public:
+        /**
+         * Constructor
+         * 
+         * @param id    Attribute identifier
+         */
+        ScopedAttribute(const char* id) : Attribute(id) {}
+        
+        virtual ~ScopedAttribute() {}
+        
+        /**
+         * Returns the set of values encoded as UTF-8 strings.
+         * 
+         * <p>Each compound value is a pair containing the simple value and the scope. 
+         * 
+         * @return  a mutable vector of the values
+         */
+        std::vector< std::pair<std::string,std::string> >& getValues() {
+            return m_values;
+        }
+        
+        void clearSerializedValues() {
+            m_serialized.clear();
+        }
+        
+        const std::vector<std::string>& getSerializedValues() const {
+            if (m_serialized.empty()) {
+                for (std::vector< std::pair<std::string,std::string> >::const_iterator i=m_values.begin(); i!=m_values.end(); ++i)
+                    m_serialized.push_back(i->first + '@' + i->second);
+            }
+            return Attribute::getSerializedValues();
+        }
+    
+    private:
+        std::vector< std::pair<std::string,std::string> > m_values;
+    };
+
+};
+
+#endif /* __shibsp_scopedattr_h__ */
diff --git a/shibsp/attribute/SimpleAttribute.h b/shibsp/attribute/SimpleAttribute.h
new file mode 100644 (file)
index 0000000..fd88c05
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ *  Copyright 2001-2006 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/SimpleAttribute.h
+ * 
+ * An Attribute whose values are simple strings.
+ */
+
+#ifndef __shibsp_simpattr_h__
+#define __shibsp_simpattr_h__
+
+#include <shibsp/attribute/Attribute.h>
+
+namespace shibsp {
+
+    /**
+     * An Attribute whose values are simple strings.
+     */
+    class SHIBSP_API SimpleAttribute : public Attribute
+    {
+    public:
+        /**
+         * Constructor
+         * 
+         * @param id    Attribute identifier
+         */
+        SimpleAttribute(const char* id) : Attribute(id) {}
+        
+        virtual ~SimpleAttribute() {}
+        
+        /**
+         * Returns the set of values encoded as UTF-8 strings.
+         * 
+         * <p>For simple values, the serialized form is just the actual string,
+         * so the value array can be directly manipulated. 
+         * 
+         * @return  a mutable vector of the values
+         */
+        std::vector<std::string>& getValues() {
+            return m_serialized;
+        }
+        
+        void clearSerializedValues() const {
+            // Do nothing, since our values are already serialized.
+        }
+    };
+
+};
+
+#endif /* __shibsp_simpattr_h__ */
index 64bbd8f..6fd0b62 100644 (file)
                                        >\r
                                </File>\r
                        </Filter>\r
+                       <Filter\r
+                               Name="attribute"\r
+                               >\r
+                       </Filter>\r
                </Filter>\r
                <Filter\r
                        Name="Header Files"\r
                                        >\r
                                </File>\r
                        </Filter>\r
+                       <Filter\r
+                               Name="attribute"\r
+                               >\r
+                               <File\r
+                                       RelativePath=".\attribute\Attribute.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\attribute\NameIDAttribute.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\attribute\ScopedAttribute.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\attribute\SimpleAttribute.h"\r
+                                       >\r
+                               </File>\r
+                       </Filter>\r
                </Filter>\r
                <Filter\r
                        Name="Resource Files"\r