You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ra...@apache.org on 2010/04/09 00:12:03 UTC

svn commit: r932148 - in /qpid/trunk/qpid/cpp/src: CMakeLists.txt acl.mk qpid/acl/Acl.cpp qpid/acl/AclValidator.cpp qpid/acl/AclValidator.h

Author: rajith
Date: Thu Apr  8 22:12:03 2010
New Revision: 932148

URL: http://svn.apache.org/viewvc?rev=932148&view=rev
Log:
Committing the patch attached to QPID-2488

Added:
    qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.cpp
    qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.h
Modified:
    qpid/trunk/qpid/cpp/src/CMakeLists.txt
    qpid/trunk/qpid/cpp/src/acl.mk
    qpid/trunk/qpid/cpp/src/qpid/acl/Acl.cpp

Modified: qpid/trunk/qpid/cpp/src/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/CMakeLists.txt?rev=932148&r1=932147&r2=932148&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/CMakeLists.txt (original)
+++ qpid/trunk/qpid/cpp/src/CMakeLists.txt Thu Apr  8 22:12:03 2010
@@ -412,6 +412,8 @@ if (BUILD_ACL)
        qpid/acl/AclPlugin.cpp
        qpid/acl/AclReader.cpp
        qpid/acl/AclReader.h
+       qpid/acl/AclValidator.cpp
+       qpid/acl/AclValidator.h
       )
   # Windows builds the ACL code into the qpidbroker library; see QPID-1842
   # for history and rationale. If this is changed, remove the acl_SOURCES from

Modified: qpid/trunk/qpid/cpp/src/acl.mk
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/acl.mk?rev=932148&r1=932147&r2=932148&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/acl.mk (original)
+++ qpid/trunk/qpid/cpp/src/acl.mk Thu Apr  8 22:12:03 2010
@@ -28,7 +28,9 @@ acl_la_SOURCES = \
   qpid/acl/AclData.h \
   qpid/acl/AclPlugin.cpp \
   qpid/acl/AclReader.cpp \
-  qpid/acl/AclReader.h
+  qpid/acl/AclReader.h \
+  qpid/acl/AclValidator.cpp \
+  qpid/acl/AclValidator.h
 
 acl_la_LIBADD = libqpidbroker.la
 if SUNOS

Modified: qpid/trunk/qpid/cpp/src/qpid/acl/Acl.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/acl/Acl.cpp?rev=932148&r1=932147&r2=932148&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/acl/Acl.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/acl/Acl.cpp Thu Apr  8 22:12:03 2010
@@ -18,6 +18,7 @@
 
 #include "qpid/acl/Acl.h"
 #include "qpid/acl/AclData.h"
+#include "qpid/acl/AclValidator.h"
 
 #include "qpid/broker/Broker.h"
 #include "qpid/Plugin.h"
@@ -129,6 +130,9 @@ Acl::Acl (AclValues& av, Broker& b): acl
           return false;
       }
 
+      AclValidator validator;
+      validator.validate(d);
+
       data = d;
 	  transferAcl = data->transferAcl; // any transfer ACL
       data->aclSource = aclFile; 

Added: qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.cpp?rev=932148&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.cpp Thu Apr  8 22:12:03 2010
@@ -0,0 +1,141 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/acl/AclValidator.h"
+#include "qpid/acl/AclData.h"
+#include "qpid/Exception.h"
+#include "qpid/log/Statement.h"
+#include "qpid/sys/IntegerTypes.h"
+#include <boost/lexical_cast.hpp>
+#include <numeric>
+#include <sstream>
+
+namespace qpid {
+namespace acl {
+
+AclValidator::AclIntProperty::AclIntProperty(int64_t i,int64_t j) : min(i), max(j){    
+}
+
+bool AclValidator::AclIntProperty::validate(const std::string& val) {
+  int64_t v;
+  try
+  {
+    v = boost::lexical_cast<int64_t>(val);
+  }catch(const boost::bad_lexical_cast& e){
+    return 0;
+  }
+
+  if (v < min || v >= max){
+    return 0;
+  }else{
+    return 1;
+  }
+}
+
+std::string AclValidator::AclIntProperty::allowedValues() {
+   return "values should be between " + 
+          boost::lexical_cast<std::string>(min) + " and " +
+          boost::lexical_cast<std::string>(max);
+}
+
+AclValidator::AclEnumProperty::AclEnumProperty(std::vector<std::string>& allowed): values(allowed){      
+}
+
+bool AclValidator::AclEnumProperty::validate(const std::string& val) {
+  for (std::vector<std::string>::iterator itr = values.begin(); itr != values.end(); ++itr ){
+     if (val.compare(*itr) == 0){
+        return 1;
+     }
+  }
+
+  return 0;
+}
+
+std::string AclValidator::AclEnumProperty::allowedValues() {
+   std::ostringstream oss;
+   oss << "possible values are one of { ";
+   for (std::vector<std::string>::iterator itr = values.begin(); itr != values.end(); itr++ ){
+        oss << "'" << *itr << "' ";
+   }
+   oss << "}";
+   return oss.str();
+}
+
+AclValidator::AclValidator(){
+  validators.insert(Validator(acl::PROP_MAXQUEUESIZE,
+                              boost::shared_ptr<AclProperty>(
+                                new AclIntProperty(0,std::numeric_limits<int64_t>::max()))
+                             )
+                   );
+
+  validators.insert(Validator(acl::PROP_MAXQUEUECOUNT,
+                              boost::shared_ptr<AclProperty>(
+                                new AclIntProperty(0,std::numeric_limits<int64_t>::max()))
+                             )
+                   );
+
+  std::string policyTypes[] = {"ring", "ring_strict", "flow_to_disk", "reject"};
+  std::vector<std::string> v(policyTypes, policyTypes + sizeof(policyTypes) / sizeof(std::string));
+  validators.insert(Validator(acl::PROP_POLICYTYPE,
+                              boost::shared_ptr<AclProperty>(new AclEnumProperty(v))
+                             )
+                   );
+  
+}
+
+AclValidator::~AclValidator(){
+}
+
+/* Iterate through the data model and validate the parameters. */
+void AclValidator::validate(boost::shared_ptr<AclData> d) {
+  
+    for (unsigned int cnt=0; cnt< qpid::acl::ACTIONSIZE; cnt++){
+
+        if (d->actionList[cnt]){
+
+	        for (unsigned int cnt1=0; cnt1< qpid::acl::OBJECTSIZE; cnt1++){
+
+		        if (d->actionList[cnt][cnt1]){
+
+                    for (AclData::actObjItr actionMapItr = d->actionList[cnt][cnt1]->begin(); 
+                      actionMapItr != d->actionList[cnt][cnt1]->end(); actionMapItr++) {
+
+                        for (AclData::ruleSetItr i = actionMapItr->second.begin(); i < actionMapItr->second.end(); i++) {
+                            
+                            for (AclData::propertyMapItr pMItr = i->props.begin(); pMItr != i->props.end(); pMItr++) {
+
+                               ValidatorItr itr = validators.find(pMItr->first);
+                               if (itr != validators.end()){
+                                 QPID_LOG(debug,"Found validator for property " << itr->second->allowedValues());
+
+                                 if (!itr->second->validate(pMItr->second)){
+                                    throw Exception( pMItr->second + " is not a valid value for '" + 
+                                                     AclHelper::getPropertyStr(pMItr->first) + "', " +
+                                                     itr->second->allowedValues());
+                                 }//if
+                               }//if
+                            }//for
+                        }//for 
+                    }//for
+                }//if 
+            }//for
+	    }//if
+	}//for
+}
+
+}}

Added: qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.h?rev=932148&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.h (added)
+++ qpid/trunk/qpid/cpp/src/qpid/acl/AclValidator.h Thu Apr  8 22:12:03 2010
@@ -0,0 +1,82 @@
+#ifndef QPID_ACL_ACLVALIDATOR_H
+#define QPID_ACL_ACLVALIDATOR_H
+
+
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * 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.
+ *
+ */
+
+#include "qpid/broker/AclModule.h"
+#include "qpid/acl/AclData.h"
+#include "qpid/sys/IntegerTypes.h"
+#include <boost/shared_ptr.hpp>
+#include <vector>
+#include <sstream>
+
+namespace qpid {
+namespace acl {
+
+class AclValidator {
+
+    /* Base Property */
+   class AclProperty{        
+        public:
+            enum PropertyType { INT, STRING, ENUM };
+
+        public:
+            virtual int getType()=0;
+            virtual bool validate(const std::string& val)=0;
+            virtual std::string allowedValues()=0;
+   };
+
+   class AclIntProperty : public AclProperty{        
+            int64_t min;
+            int64_t max;
+        
+        public:
+            AclIntProperty(int64_t min,int64_t max);
+            int getType(){ return AclProperty::INT; }
+            virtual bool validate(const std::string& val);
+            virtual std::string allowedValues();
+   };
+
+   class AclEnumProperty : public AclProperty{
+            std::vector<std::string> values;               
+
+        public:
+            AclEnumProperty(std::vector<std::string>& allowed);
+            int getType(){ return AclProperty::ENUM; }
+            virtual bool validate(const std::string& val);
+            virtual std::string allowedValues();
+   };
+   
+   typedef std::pair<acl::Property,boost::shared_ptr<AclProperty> > Validator;
+   typedef std::map<acl::Property,boost::shared_ptr<AclProperty> > ValidatorMap;
+   typedef ValidatorMap::iterator ValidatorItr;
+ 
+   ValidatorMap validators;
+
+public:
+     
+   void validate(boost::shared_ptr<AclData> d);
+   AclValidator();
+   ~AclValidator();
+};
+    
+}} // namespace qpid::acl
+
+#endif // QPID_ACL_ACLVALIDATOR_H



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org