myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [2849] Added classes for the new security implementati


From: Giuseppe Scrivano
Subject: [myserver-commit] [2849] Added classes for the new security implementation.
Date: Sat, 27 Sep 2008 21:40:16 +0000

Revision: 2849
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2849
Author:   gscrivano
Date:     2008-09-27 21:40:15 +0000 (Sat, 27 Sep 2008)

Log Message:
-----------
Added classes for the new security implementation.  Work in progress.

Modified Paths:
--------------
    branches/myserver_sec_new/include/conf/security/Makefile.am
    branches/myserver_sec_new/include/conf/security/security_cache.h
    branches/myserver_sec_new/src/conf/security/Makefile.am
    branches/myserver_sec_new/src/conf/security/security_cache.cpp
    branches/myserver_sec_new/tests/Makefile.am

Added Paths:
-----------
    branches/myserver_sec_new/include/conf/security/auth_domain.h
    branches/myserver_sec_new/include/conf/security/security.h
    branches/myserver_sec_new/include/conf/security/security_domain.h
    branches/myserver_sec_new/include/conf/security/security_manager.h
    branches/myserver_sec_new/include/conf/security/validator.h
    branches/myserver_sec_new/include/conf/security/validator_factory.h
    branches/myserver_sec_new/src/conf/security/auth_domain.cpp
    branches/myserver_sec_new/src/conf/security/security_domain.cpp
    branches/myserver_sec_new/src/conf/security/security_manager.cpp
    branches/myserver_sec_new/src/conf/security/validator.cpp
    branches/myserver_sec_new/src/conf/security/validator_factory.cpp
    branches/myserver_sec_new/tests/test_auth_domain.cpp
    branches/myserver_sec_new/tests/test_security_cache.cpp
    branches/myserver_sec_new/tests/test_security_domain.cpp
    branches/myserver_sec_new/tests/test_security_manager.cpp
    branches/myserver_sec_new/tests/test_validator.cpp
    branches/myserver_sec_new/tests/test_validator_factory.cpp

Removed Paths:
-------------
    branches/myserver_sec_new/include/conf/security/security.h
    branches/myserver_sec_new/src/conf/security/security.cpp

Modified: branches/myserver_sec_new/include/conf/security/Makefile.am
===================================================================
--- branches/myserver_sec_new/include/conf/security/Makefile.am 2008-09-27 
20:08:53 UTC (rev 2848)
+++ branches/myserver_sec_new/include/conf/security/Makefile.am 2008-09-27 
21:40:15 UTC (rev 2849)
@@ -1,4 +1,4 @@
 securityincludedir=$(includedir)/myserver/include/conf/security
-securityinclude_HEADERS = security_cache.h security.h
+securityinclude_HEADERS = auth_domain.h  security_cache.h  security_domain.h  
security_manager.h  validator.h  validator_factory.h
 SUBDIRS =
 

Added: branches/myserver_sec_new/include/conf/security/auth_domain.h
===================================================================
--- branches/myserver_sec_new/include/conf/security/auth_domain.h               
                (rev 0)
+++ branches/myserver_sec_new/include/conf/security/auth_domain.h       
2008-09-27 21:40:15 UTC (rev 2849)
@@ -0,0 +1,42 @@
+/* -*- mode: c++ -*- */
+/*
+MyServer
+Copyright (C) 2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef AUTH_DOMAIN_H
+#define AUTH_DOMAIN_H
+
+#include "stdafx.h"
+#include <include/conf/security/security_domain.h>
+
+#include <string>
+
+using namespace std;
+
+struct SecurityToken;
+
+class AuthDomain : public SecurityDomain
+{
+public:
+  AuthDomain (SecurityToken*);
+  virtual ~AuthDomain ();
+  virtual string *getValue (string &name);
+protected:
+  string name;
+  SecurityToken *securityToken;
+};
+
+#endif

Deleted: branches/myserver_sec_new/include/conf/security/security.h
===================================================================
--- branches/myserver_sec_new/include/conf/security/security.h  2008-09-27 
20:08:53 UTC (rev 2848)
+++ branches/myserver_sec_new/include/conf/security/security.h  2008-09-27 
21:40:15 UTC (rev 2849)
@@ -1,121 +0,0 @@
-/* -*- mode: c++ -*- */
-/*
-MyServer
-Copyright (C) 2002, 2003, 2004, 2008 Free Software Foundation, Inc.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef SECURITY_H
-#define SECURITY_H
-
-#include "stdafx.h"
-#include <include/connection/connection.h>
-#include <include/base/xml/xml_parser.h>
-#include <include/base/hash_map/hash_map.h>
-#include <include/protocol/http/http_headers.h>
-
-#ifndef DO_NOT_USE_SSL
-#include<openssl/ssl.h>
-#include<openssl/crypto.h>
-#include<openssl/lhash.h>
-#include<openssl/err.h>
-#include<openssl/bn.h>
-#include<openssl/pem.h>
-#include<openssl/x509.h>
-#include<openssl/rand.h>
-#include<openssl/pem.h>
-#include<openssl/err.h>
-#include<openssl/rsa.h>
-#endif
-
-#include <string>
-
-using namespace std;
-
-/*!
- *Various permissions flags.
- */
-
-/*! Current user can read the file. */
-const u_long MYSERVER_PERMISSION_READ     =    (1<<0);
-
-/*! Current user can write to the file. */
-const u_long MYSERVER_PERMISSION_WRITE   = (1<<1);
-
-/*! Current user can execute the file. */
-const u_long MYSERVER_PERMISSION_EXECUTE  = (1<<2);
-
-/*! Current user can remove the file. */
-const u_long MYSERVER_PERMISSION_DELETE          = (1<<3);
-
-/*! Current user can browse the directory content. */
-const u_long MYSERVER_PERMISSION_BROWSE          = (1<<4);
-
-struct SecurityToken
-{
-  /*! User to check for. */
-  const char* user;
-
-  /*! Password provided by the user. */
-  const char* password;
-
-  /*! Directory that the user is in. */
-  const char* directory;
-
-  /*! System directory for the host. */
-  const char* sysdirectory;
-
-  /*! File that the user tried to access. */
-  const char* filename;
-
-  /*! 
-   *Password that the user should provide to have access. 
-   *This is used in authorization schemes like the HTTP digest,
-   *where the password is not sent in clear on the network.
-   */
-  char *requiredPassword;
-
-  /*! Permission mask that the user will have providing [neededPassword]. */
-  int *providedMask;
-
-  struct HttpThreadContext* td;
-
-  /*! Authorization scheme to use. */
-  char* authType;
-
-  /*! Length for the [authType] allocated string. */
-  int authTypeLen;
-
-  /*! Throttling rate to use with specified user. */
-  int throttlingRate;
-
-       HashMap<string,string*> *otherValues;
-
-  SecurityToken();
-  void reset();
-};
-
-class SecurityManager
-{
-public:
-  SecurityManager();
-  ~SecurityManager();
-  int getErrorFileName(const char *sysDir, int error, string& out, 
-                       XmlParser* parser = 0);
-  int getPermissionMask(SecurityToken* st, XmlParser* parser = 0);
-private:
-  XmlParser* getParser(const char *sysDir);
-  bool checkActions(HttpThreadContext* td,  xmlNode *root);
-};
-#endif

Added: branches/myserver_sec_new/include/conf/security/security.h
===================================================================
--- branches/myserver_sec_new/include/conf/security/security.h                  
        (rev 0)
+++ branches/myserver_sec_new/include/conf/security/security.h  2008-09-27 
21:40:15 UTC (rev 2849)
@@ -0,0 +1,2 @@
+//////KEEP THIS FILE TO DON'T BREAK OLD APIs
+#include <include/conf/security/security_manager.h>

Modified: branches/myserver_sec_new/include/conf/security/security_cache.h
===================================================================
--- branches/myserver_sec_new/include/conf/security/security_cache.h    
2008-09-27 20:08:53 UTC (rev 2848)
+++ branches/myserver_sec_new/include/conf/security/security_cache.h    
2008-09-27 21:40:15 UTC (rev 2849)
@@ -18,7 +18,7 @@
 #ifndef SECURITY_CACHE_H
 #define SECURITY_CACHE_H
 #include <include/base/hash_map/hash_map.h>
-#include <include/conf/security/security.h>
+#include <include/conf/security/security_manager.h>
 
 #include <string>
 
@@ -26,20 +26,24 @@
 
 class SecurityCache
 {
+
 public:
   SecurityCache();
   ~SecurityCache();
   void free();
   void setMaxNodes(int);
   int getMaxNodes();
-  XmlParser* getParser(const char* dir, const char* sys, bool useXpath = true);
-       int getSecurityFile(const char* file, const char* sys, string& out);
-  int getPermissionMask(SecurityToken* st);
+
+  XmlParser* getParser(const string &dir, const string &sys, bool useXpath = 
true);
+       int getSecurityFile(const string &file, const string &sys, string &out);
+
+  /////////OLD////////////////////////////////////
+  int getPermissionMask(SecurityToken* st){return 0;}
   int getErrorFileName(const char *root, int error, 
-                       const char* sysdirectory, string& out);
+                       const char* sysdirectory, string& out){return 0;}
+
 private:
-  /*! Object used to handle security on the server. */
-  SecurityManager sm;
+
   /*! Store a list of opened files using a hash dictionary. */
   HashMap<string, XmlParser*> dictionary;
   int limit;

Added: branches/myserver_sec_new/include/conf/security/security_domain.h
===================================================================
--- branches/myserver_sec_new/include/conf/security/security_domain.h           
                (rev 0)
+++ branches/myserver_sec_new/include/conf/security/security_domain.h   
2008-09-27 21:40:15 UTC (rev 2849)
@@ -0,0 +1,40 @@
+/* -*- mode: c++ -*- */
+/*
+MyServer
+Copyright (C) 2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef SECURITY_DOMAIN_H
+#define SECURITY_DOMAIN_H
+
+#include "stdafx.h"
+
+#include <string>
+
+using namespace std;
+
+class SecurityDomain
+{
+public:
+  SecurityDomain ();
+  SecurityDomain (string &name);
+  virtual ~SecurityDomain ();
+  virtual string *getValue (string &name);
+  const string& getName(){return name;}
+protected:
+  string name;
+};
+
+#endif

Added: branches/myserver_sec_new/include/conf/security/security_manager.h
===================================================================
--- branches/myserver_sec_new/include/conf/security/security_manager.h          
                (rev 0)
+++ branches/myserver_sec_new/include/conf/security/security_manager.h  
2008-09-27 21:40:15 UTC (rev 2849)
@@ -0,0 +1,134 @@
+/* -*- mode: c++ -*- */
+/*
+MyServer
+Copyright (C) 2002, 2003, 2004, 2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef SECURITY_MANAGER_H
+#define SECURITY_MANAGER_H
+
+#include "stdafx.h"
+#include <include/connection/connection.h>
+#include <include/base/xml/xml_parser.h>
+#include <include/protocol/http/http_headers.h>
+#include <include/base/hash_map/hash_map.h>
+
+#ifndef DO_NOT_USE_SSL
+#include<openssl/ssl.h>
+#include<openssl/crypto.h>
+#include<openssl/lhash.h>
+#include<openssl/err.h>
+#include<openssl/bn.h>
+#include<openssl/pem.h>
+#include<openssl/x509.h>
+#include<openssl/rand.h>
+#include<openssl/pem.h>
+#include<openssl/err.h>
+#include<openssl/rsa.h>
+#endif
+
+#include <string>
+
+using namespace std;
+
+class SecurityDomain;
+class ValidatorFactory;
+
+
+/*!
+ *Define permissions flags.
+ */
+enum PERMISSION_MASK
+{
+  /*! Current user can read the file. */
+  MYSERVER_PERMISSION_READ     =       (1<<0),
+
+  /*! Current user can write to the file. */
+  MYSERVER_PERMISSION_WRITE      = (1<<1),
+
+  /*! Current user can execute the file. */
+  MYSERVER_PERMISSION_EXECUTE  = (1<<2),
+
+  /*! Current user can remove the file. */
+  MYSERVER_PERMISSION_DELETE     = (1<<3),
+
+/*! Current user can browse the directory content. */
+  MYSERVER_PERMISSION_BROWSE     = (1<<4)
+};
+
+struct SecurityToken
+{
+  SecurityToken();
+  void reset();
+
+  /*! User to check for.  */
+  string user;
+
+  /*! Password provided by the user.  */
+  string password;
+
+  /*! Directory that the user is in.  */
+  string directory;
+
+  /*! System directory for the host.  */
+  string sysdirectory;
+
+  /*! Resource that the user tried to access.  */
+  string resource;
+
+  /*!
+   *Password that the user should provide to have access. 
+   *This is used in authorization schemes like the HTTP digest,
+   *where the password is not sent in clear on the network.
+   */
+  string neededPassword;
+
+  /*!
+   *Permission mask.  If [password] is NULL then only the
+   *user is considered.
+   */
+  int mask;
+
+       HashMap<string,string*> values;
+
+  /*! If it is true the security manager will use the cached values.  */
+  bool done;
+
+
+  ///////OLD NOT USED////////////
+  char* requiredPassword;
+  const char* filename;
+  int *providedMask;
+  struct HttpThreadContext* td;
+  char* authType;
+  int authTypeLen;
+  int throttlingRate;
+};
+
+class SecurityManager
+{
+public:
+  SecurityManager(ValidatorFactory*);
+  ~SecurityManager();
+
+  int getPermissionMask(SecurityToken* st, 
+                        list<SecurityDomain*> *domains, 
+                        string& validator);
+
+private:
+  ValidatorFactory *validatorFactory;
+};
+
+#endif

Added: branches/myserver_sec_new/include/conf/security/validator.h
===================================================================
--- branches/myserver_sec_new/include/conf/security/validator.h                 
        (rev 0)
+++ branches/myserver_sec_new/include/conf/security/validator.h 2008-09-27 
21:40:15 UTC (rev 2849)
@@ -0,0 +1,52 @@
+/* -*- mode: c++ -*- */
+/*
+MyServer
+Copyright (C) 2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef VALIDATOR_H
+#define VALIDATOR_H
+
+#include "stdafx.h"
+#include <include/base/hash_map/hash_map.h>
+
+#include <include/conf/security/security_domain.h>
+#include <include/conf/security/security_manager.h>
+
+#include <list>
+using namespace std;
+
+
+class Validator
+{
+public:
+  Validator ();
+  virtual ~Validator ();
+
+  int getPermissionMask (SecurityToken* st, 
+                         list<SecurityDomain*> *domains);
+
+  virtual int getPermissionMaskImpl (SecurityToken* st);
+
+
+  virtual string *getValue (string &name);
+protected:
+  int initializeDomains (SecurityToken* st, 
+                         list<SecurityDomain*> *domains);
+  void clearDomains ();
+  HashMap<string, SecurityDomain*> hashedDomains;
+};
+
+#endif

Added: branches/myserver_sec_new/include/conf/security/validator_factory.h
===================================================================
--- branches/myserver_sec_new/include/conf/security/validator_factory.h         
                (rev 0)
+++ branches/myserver_sec_new/include/conf/security/validator_factory.h 
2008-09-27 21:40:15 UTC (rev 2849)
@@ -0,0 +1,41 @@
+/*
+MyServer
+Copyright (C) 2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef VALIDATOR_FACTORY_H
+#define VALIDATOR_FACTORY_H
+
+#include "stdafx.h"
+#include <include/base/hash_map/hash_map.h>
+#include <string>
+
+using namespace std;
+
+class Validator;
+
+
+class ValidatorFactory
+{
+public:
+  ValidatorFactory ();
+  virtual ~ValidatorFactory ();
+  Validator* getValidator (string &name);
+  Validator* addValidator (string &name, Validator* validator);
+  bool isValidatorPresent (string &name);
+private:
+       HashMap<string, Validator*> validators;
+};
+#endif

Modified: branches/myserver_sec_new/src/conf/security/Makefile.am
===================================================================
--- branches/myserver_sec_new/src/conf/security/Makefile.am     2008-09-27 
20:08:53 UTC (rev 2848)
+++ branches/myserver_sec_new/src/conf/security/Makefile.am     2008-09-27 
21:40:15 UTC (rev 2849)
@@ -1,5 +1,4 @@
 lib_LIBRARIES = libsecurity.a
-libsecurity_a_SOURCES = security_cache.cpp security.cpp
+libsecurity_a_SOURCES = auth_domain.cpp  security_cache.cpp  
security_domain.cpp  security_manager.cpp  validator.cpp  validator_factory.cpp
 SUBDIRS =
 INCLUDES = $(all_includes)
-

Added: branches/myserver_sec_new/src/conf/security/auth_domain.cpp
===================================================================
--- branches/myserver_sec_new/src/conf/security/auth_domain.cpp                 
        (rev 0)
+++ branches/myserver_sec_new/src/conf/security/auth_domain.cpp 2008-09-27 
21:40:15 UTC (rev 2849)
@@ -0,0 +1,52 @@
+/*
+MyServer
+Copyright (C) 2002-2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <include/conf/security/auth_domain.h>
+#include <include/conf/security/security_manager.h>
+
+
+AuthDomain::AuthDomain (SecurityToken *st)
+{
+  this->name.assign("");
+  securityToken = st;
+}
+
+AuthDomain::~AuthDomain()
+{
+
+}
+
+/*!
+ *\see SecurityDomain::getValue.
+ */
+string *AuthDomain::getValue (string &name)
+{
+  if (!name.compare ("user"))
+    return &(securityToken->user);
+
+  if (!name.compare ("password"))
+    return &(securityToken->password);
+
+  if (!name.compare ("directory"))
+    return &(securityToken->directory);
+
+  if (!name.compare("sysdirectory"))
+    return &(securityToken->sysdirectory);
+
+  return NULL;
+}

Deleted: branches/myserver_sec_new/src/conf/security/security.cpp
===================================================================
--- branches/myserver_sec_new/src/conf/security/security.cpp    2008-09-27 
20:08:53 UTC (rev 2848)
+++ branches/myserver_sec_new/src/conf/security/security.cpp    2008-09-27 
21:40:15 UTC (rev 2849)
@@ -1,284 +0,0 @@
-/*
-MyServer
-Copyright (C) 2002-2008 Free Software Foundation, Inc.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-
-#include <include/conf/security/security.h>
-#include <include/base/utility.h>
-#include <include/base/xml/xml_parser.h>
-#include <include/connection/connection.h>
-#include <include/base/string/securestr.h>
-#include <include/base/regex/myserver_regex.h>
-#include <include/base/file/files_utility.h>
-#include <include/protocol/http/http_thread_context.h>
-
-#include <string>
-#include <sstream>
-#include <memory>
-
-using namespace std;
-
-/*!
- *Create the object.
- */
-SecurityToken::SecurityToken()
-{
-  reset();
-}
-
-/*!
- *Reset every structure member.
- */
-void SecurityToken::reset()
-{
-  user           = 0;
-  password       = 0;
-  directory      = 0;
-  filename       = 0;
-  requiredPassword = 0;
-  providedMask    = 0;
-  authType      = 0;
-  authTypeLen       = 0;
-  throttlingRate = (int)-1;
-}
-
-
-/*!
- *Get the error file for a page using the specified parser. 
- *Return 0 to use the default one.
- *Return -1 on errors.
- *Return other valus on success.
- */
-int SecurityManager::getErrorFileName(const char* sysDir, 
-                                      int error, 
-                                      string &out, 
-                                      XmlParser* parser)
-{
-  string evalString;
-  XmlXPathResult* xpathRes;
-  xmlNodeSetPtr nodes;
-  int ret;
-
-  out.assign("");
-
-  if(parser == NULL || !parser->isXpathEnabled())
-    return -1;
-
-  evalString = "/SECURITY/address@hidden'";
-  evalString += error;
-  evalString += "']/@FILE";
-
-  xpathRes = parser->evaluateXpath(evalString);
-  nodes = xpathRes->getNodeSet();
-
-  if(nodes && nodes->nodeNr)
-    out.assign((const char*)nodes->nodeTab[0]->children->content);
-
-  /* Return 1 if both it was found and well configured.  */
-  ret = nodes && nodes->nodeNr && out.length() ? 1 : 0;
-
-  delete xpathRes;
-  return ret;
-
-}
-
-
-/*!
- *Get the permissions mask for the file FILENAME using the XML parser PARSER.
- *The file DIRECTORY/security will be parsed.
- *PROVIDEDMASK is the permission mask that the USER will have providing the
- *REQUIREDPASSWORD password.
- *Returns -1 on errors.
- */
-int SecurityManager::getPermissionMask(SecurityToken *st, XmlParser* parser)
-{
-  xmlNodeSetPtr nodes;
-  xmlAttr* attr;
-  string evalString;
-  int permissions = 0;
-  const char* requiredPassword;
-  bool rightPassword = false;
-  auto_ptr<XmlXPathResult> itemRes;
-  auto_ptr<XmlXPathResult> userRes;
-
-  if(parser == NULL || !parser->isXpathEnabled())
-    return -1;
-
-
-  evalString = "/SECURITY/AUTH/@TYPE";
-
-  auto_ptr<XmlXPathResult>authRes(parser->evaluateXpath(evalString));
-  nodes = authRes.get()->getNodeSet();
-
-  if(nodes && nodes->nodeNr)
-    strncpy(st->authType,(const char*)nodes->nodeTab[0]->children->content, 
-            st->authTypeLen);
-
-  evalString = "/SECURITY/address@hidden'";
-  evalString += st->filename;
-  evalString += "\']/address@hidden'";
-  evalString += st->user;
-  evalString += "\']/.";
-
-  auto_ptr<XmlXPathResult> itemUserRes(parser->evaluateXpath(evalString));
-
-  nodes = itemUserRes.get()->getNodeSet();
-
-  if(!nodes || !nodes->nodeNr)
-  {
-    evalString = "/SECURITY/address@hidden'";
-    evalString += st->filename;
-    evalString += "\']/.";
-
-    itemRes.reset(parser->evaluateXpath(evalString));
-
-    nodes = itemRes.get()->getNodeSet();
-
-    if(!nodes || !nodes->nodeNr)
-    {
-      evalString = "/SECURITY/address@hidden'";
-      evalString += st->user;
-      evalString += "\']/.";
-
-      userRes.reset(parser->evaluateXpath(evalString));
-
-      nodes = userRes.get()->getNodeSet();
-    }
-
-  }
-
-  if(!nodes || !nodes->nodeNr)
-    return 0;
-
-  for(attr = nodes->nodeTab[0]->properties; attr; attr = attr->next)
-  {
-    if(!strcmpi((const char*)attr->name, "READ") && 
-       !strcmpi((const char*)attr->children->content, "TRUE"))
-      permissions |= MYSERVER_PERMISSION_READ;
-
-    if(!strcmpi((const char*)attr->name, "WRITE") && 
-       !strcmpi((const char*)attr->children->content, "TRUE"))
-      permissions |= MYSERVER_PERMISSION_WRITE;
-
-    if(!strcmpi((const char*)attr->name, "EXECUTE") && 
-       !strcmpi((const char*)attr->children->content, "TRUE"))
-      permissions |= MYSERVER_PERMISSION_EXECUTE;
-
-    if(!strcmpi((const char*)attr->name, "BROWSE") && 
-       !strcmpi((const char*)attr->children->content, "TRUE"))
-      permissions |= MYSERVER_PERMISSION_BROWSE;
-
-    if(!strcmpi((const char*)attr->name, "PASS"))
-    {
-      requiredPassword = (const char*)attr->children->content;
-      rightPassword = !strcmp(st->password, requiredPassword);
-    }
-  }
-
-  if(rightPassword)
-  {
-    for(attr = nodes->nodeTab[0]->properties; attr; attr = attr->next)
-    {
-      if(!strcmpi((const char*)attr->name, "THROTTLING_RATE"))
-        st->throttlingRate = atoi((const char*)attr->children->content);
-    }
-  }
-
-  if(st->requiredPassword)
-    myserver_strlcpy(st->requiredPassword, requiredPassword, 32);
-
-  if(st->providedMask)
-    *(st->providedMask) = permissions;
-
-  if(!SecurityManager::checkActions(st->td, nodes->nodeTab[0] ))
-    return 0;
-
-  
-  return rightPassword ? permissions : 0;
-}
-
-/*!
- *Check if the specified actions deny the access to the resource.
- *\param td The Thread Context.
- *\param root The root node with actions.
- *\return true if the action allows the access to the resource.
- *\return false if the action denies the access to the resource.
- */
-bool SecurityManager::checkActions(HttpThreadContext* td,  xmlNode *root)
-{
-  xmlNode* actionsNode = root;
-
-  for( ; td && actionsNode; actionsNode = actionsNode->next)
-  {
-    xmlAttr *attr = actionsNode->properties;
-    int deny = 0;
-    regmatch_t pm;
-    const char* name = 0;
-    Regex value;
-    string* headerVal = 0;
-
-    if(strcmpi((const char*)actionsNode->name, "ACTION"))
-      continue;
-
-    if(actionsNode->children && actionsNode->children->content 
-       && !strcmpi((const char*)actionsNode->children->content, "DENY"))
-         deny = 1;
-
-    if(!deny)
-      continue;
-
-    for( ; attr; attr = attr->next)
-    {
-      if(!strcmpi((const char*)attr->name, "NAME"))
-        name = (const char*) attr->children->content;
-      if(!strcmpi((const char*)attr->name, "VALUE"))
-        value.compile((const char*)attr->children->content, REG_EXTENDED);     
    
-    }
-
-    if(name)
-      headerVal = td->request.getValue(name, 0);
-
-    if(!headerVal)
-      continue;
-
-    /*
-     *If the regular expression matches the header value then deny the 
-     *access. 
-     */
-    if(value.isCompiled() && !value.exec(headerVal->c_str(), 1,&pm, 
-                                         REG_NOTEOL))
-      return false;
-  }
-
-  return true;
-
-}
-
-/*!
- *Create the object.
- */
-SecurityManager::SecurityManager()
-{
-
-}
-
-/*!
- *Destroy the SecurityManager object.
- */
-SecurityManager::~SecurityManager()
-{
-
-}

Modified: branches/myserver_sec_new/src/conf/security/security_cache.cpp
===================================================================
--- branches/myserver_sec_new/src/conf/security/security_cache.cpp      
2008-09-27 20:08:53 UTC (rev 2848)
+++ branches/myserver_sec_new/src/conf/security/security_cache.cpp      
2008-09-27 21:40:15 UTC (rev 2849)
@@ -16,7 +16,7 @@
 */
 
 #include <include/conf/security/security_cache.h>
-#include <include/conf/security/security.h>
+#include <include/conf/security/security_manager.h>
 #include <include/base/file/file.h>
 #include <include/base/file/files_utility.h>
 
@@ -82,18 +82,20 @@
  *\param sys The system directory.
  *\param out Output string where put the security file path. 
  */
-int SecurityCache::getSecurityFile(const char* dir, const char* sys, 
+int SecurityCache::getSecurityFile(const string& dir, 
+                                   const string& sys, 
                                    string& out)
 {
   int found = 0;
-  string file(dir);
   string secFile;
+  string file(dir);
+
   int i = file.length() - 1;
 
-  while(i && file[i] == '/')
+  while(i && dir[i] == '/')
     file.erase(i--, 1);
 
-  secFile.assign(file);
+  secFile.assign(dir);
   secFile.append("/security");
 
   /* The security file exists in the directory.  */
@@ -103,18 +105,11 @@
     return 0;
   }
 
-  if(file.length() == 0)
-  {
-    out.assign(sys);
-    out.append("/security");
-    return !FilesUtility::fileExists(out);
-  }
-
-  
+ 
   /* Go upper in the tree till we find a security file.  */
-  do
+  for(;;)
   {
-    if(!file.length())
+    if(found || !file.length())
       break;
 
     for(i = file.length() - 1; i; i--)
@@ -124,10 +119,9 @@
         break;
       }
 
-
     /* 
      *Top of the tree, check if the security file is present in the 
-     *system directory, returns an error if it is not.
+     *system directory.  Return an error if it is not.
      */
     if(i == 0)
     {
@@ -135,11 +129,12 @@
       out.append("/security");
       return !FilesUtility::fileExists(out);
     }
+
     secFile.assign(file);
     secFile.append("/security");
 
+    found = FilesUtility::fileExists(secFile);
   }
-  while(!(found = FilesUtility::fileExists(secFile)));
 
   out.assign(secFile);
   return 0;
@@ -160,7 +155,9 @@
  *\param sys The system directory.
  *\param useXpath Specify if XPath will be used on the file.
  */
-XmlParser* SecurityCache::getParser(const char* dir, const char* sys, bool 
useXpath)
+XmlParser* SecurityCache::getParser(const string &dir, 
+                                    const string &sys, 
+                                    bool useXpath)
 {
   XmlParser* parser;
   string file;
@@ -194,10 +191,11 @@
   else
   {
     /*! 
-     *Create the parser and append at the dictionary.
+     *Create the parser and add it to the dictionary.
      */
     XmlParser* old;
     parser = new XmlParser();
+
     if(parser == NULL)
     {  
       return NULL;
@@ -222,48 +220,3 @@
 
   return parser;
 }
-
-
-/*!
- *Get the permission mask for the specified file and user. If the security 
file to use
- *is not loaded it will be loaded and added to the cache dictionary for faster 
future 
- *accesses.
- */
-int SecurityCache::getPermissionMask(SecurityToken* st)
-{
-  XmlParser *parser;
-
-  if(st->directory == 0)
-    return -1;
-
-  if(st->filename == 0)
-    return -1;
-
-  parser = getParser(st->directory, st->sysdirectory);
-
-  if(parser == NULL)
-    return -1;
-
-  return sm.getPermissionMask(st, parser);
-}
-
-/*!
- *Get the error file name from the security file.
- */
-int SecurityCache::getErrorFileName(const char *directory, int error, 
-                                    const char* sysdirectory, string& out)
-{
-  XmlParser *parser;
-
-  out.assign("");
-
-  if(directory == 0)
-    return -1;
-
-  parser = getParser(directory, sysdirectory);
-
-  if(parser == NULL)
-    return -1;
- 
-  return sm.getErrorFileName(directory, error, out, parser);
-}

Added: branches/myserver_sec_new/src/conf/security/security_domain.cpp
===================================================================
--- branches/myserver_sec_new/src/conf/security/security_domain.cpp             
                (rev 0)
+++ branches/myserver_sec_new/src/conf/security/security_domain.cpp     
2008-09-27 21:40:15 UTC (rev 2849)
@@ -0,0 +1,44 @@
+/*
+MyServer
+Copyright (C) 2002-2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <include/conf/security/security_domain.h>
+
+
+SecurityDomain::SecurityDomain ()
+{
+  this->name.assign("");
+}
+
+SecurityDomain::SecurityDomain (string& name)
+{
+  this->name.assign(name);
+}
+
+
+SecurityDomain::~SecurityDomain()
+{
+
+}
+
+/*!
+ *Get the stored value for [name].
+ */
+string *SecurityDomain::getValue (string &name)
+{
+  return NULL;
+}

Added: branches/myserver_sec_new/src/conf/security/security_manager.cpp
===================================================================
--- branches/myserver_sec_new/src/conf/security/security_manager.cpp            
                (rev 0)
+++ branches/myserver_sec_new/src/conf/security/security_manager.cpp    
2008-09-27 21:40:15 UTC (rev 2849)
@@ -0,0 +1,70 @@
+/*
+MyServer
+Copyright (C) 2002-2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <include/conf/security/security_manager.h>
+#include <include/conf/security/validator.h>
+#include <include/conf/security/validator_factory.h>
+
+#include <string>
+#include <sstream>
+#include <memory>
+
+using namespace std;
+
+/*!
+ *Create the object.
+ */
+SecurityToken::SecurityToken ()
+{
+  reset ();
+}
+
+/*!
+ *Reset every structure member.
+ */
+void SecurityToken::reset ()
+{
+  mask = 0;
+  done = false;
+}
+
+
+SecurityManager::SecurityManager (ValidatorFactory* vf)
+{
+  validatorFactory = vf;
+}
+
+SecurityManager::~SecurityManager ()
+{
+
+}
+
+/*!
+ *Get the permission mask for the requested resource.
+ */
+int SecurityManager::getPermissionMask (SecurityToken* st, 
+                                        list<SecurityDomain*> *domains, 
+                                        string& validator)
+{
+  Validator* v = validatorFactory->getValidator(validator);
+
+  if (!v)
+    return 0;
+
+  return v->getPermissionMask (st, domains);
+}

Added: branches/myserver_sec_new/src/conf/security/validator.cpp
===================================================================
--- branches/myserver_sec_new/src/conf/security/validator.cpp                   
        (rev 0)
+++ branches/myserver_sec_new/src/conf/security/validator.cpp   2008-09-27 
21:40:15 UTC (rev 2849)
@@ -0,0 +1,127 @@
+/*
+MyServer
+Copyright (C) 2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <include/conf/security/validator.h>
+#include <include/conf/security/auth_domain.h>
+
+Validator::Validator ()
+{
+
+}
+
+Validator::~Validator ()
+{
+
+}
+
+/*!
+ *Get the permission mask for the requested resource.
+ *Decorate getPermissionMaskImpl.
+ */
+int Validator::getPermissionMask (SecurityToken* st, 
+                                 list<SecurityDomain*> *domains)
+{
+  int ret = initializeDomains (st, domains);
+
+  if(ret)
+    return ret;
+
+  ret = getPermissionMaskImpl (st);
+  
+  clearDomains ();
+
+  return ret;
+}
+
+
+/*!
+ *Get the permission mask for the requested resource.
+ */
+int Validator::getPermissionMaskImpl (SecurityToken* st)
+{
+  return 0;
+}
+
+
+
+/*!
+ *Initialize the domains.
+ */
+int Validator::initializeDomains (SecurityToken* st, 
+                                  list<SecurityDomain*> *domains)
+{
+  string authName("");
+  hashedDomains.put (authName, new AuthDomain(st));
+
+  if (domains)
+  {
+    for (list<SecurityDomain*>::iterator it = domains->begin (); it != 
domains->end (); it++)
+    {
+      SecurityDomain *domain = *it;
+      string name = domain->getName();
+      hashedDomains.put (name, domain);
+    }
+  }
+
+  return 0;
+}
+
+/*!
+ *Clear the resources used by the domains.
+ */
+void Validator::clearDomains ()
+{
+  HashMap<string, SecurityDomain*>::Iterator it = hashedDomains.begin();
+  
+  for (;it != hashedDomains.end(); it++)
+  {
+    delete *it;
+  }
+
+}
+
+/*!
+ *Get the value for [name] in the form domain.variable.
+ *\param name Variable name.
+ *\return The value of the requested variable.
+ */
+string *Validator::getValue (string &name)
+{
+  string domain;
+  string var;
+  size_t pos = name.find ('.');
+  SecurityDomain *securityDomain = NULL;
+
+  if (pos != string::npos)
+  {
+    domain = name.substr (0, pos);
+    var = name.substr (pos + 1, string::npos);
+  }
+  else
+  {
+    domain.assign("");
+    var = name;
+  }
+
+  securityDomain = hashedDomains.get (domain);
+
+  if (securityDomain)
+    return securityDomain->getValue(var);
+  
+  return NULL;
+}

Added: branches/myserver_sec_new/src/conf/security/validator_factory.cpp
===================================================================
--- branches/myserver_sec_new/src/conf/security/validator_factory.cpp           
                (rev 0)
+++ branches/myserver_sec_new/src/conf/security/validator_factory.cpp   
2008-09-27 21:40:15 UTC (rev 2849)
@@ -0,0 +1,67 @@
+/*
+MyServer
+Copyright (C) 2002-2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <include/conf/security/validator.h>
+#include <include/conf/security/validator_factory.h>
+
+ValidatorFactory::ValidatorFactory ()
+{
+  //  validators
+}
+
+ValidatorFactory::~ValidatorFactory ()
+{
+  HashMap<string, Validator*>::Iterator it = validators.begin ();
+  
+  for (;it != validators.end (); it++)
+  {
+    delete *it;
+  }
+
+  validators.clear ();
+}
+
+/*!
+ *Return a validator given its name.
+ */
+Validator* ValidatorFactory::getValidator(string &name)
+{
+  return validators.get (name);
+}
+
+/*!
+ *Add a new validator to the factory.
+ *\param name Validator name.
+ *\param validator The validator to add.
+ *\return The old validator registered with [name], in any.
+ */
+Validator* ValidatorFactory::addValidator(string &name, Validator* validator)
+{
+  return validators.put (name, validator);
+  
+}
+
+/*!
+ *Check if the specified validator is present in the factory.
+ *\param name The validator name.
+ *\return a bool value to indicate if it is present or not.
+ */
+bool ValidatorFactory::isValidatorPresent (string &name)
+{
+  return getValidator (name) != NULL;
+}

Modified: branches/myserver_sec_new/tests/Makefile.am
===================================================================
--- branches/myserver_sec_new/tests/Makefile.am 2008-09-27 20:08:53 UTC (rev 
2848)
+++ branches/myserver_sec_new/tests/Makefile.am 2008-09-27 21:40:15 UTC (rev 
2849)
@@ -2,5 +2,5 @@
 #
 
 bin_PROGRAMS = tests_suite
-tests_suite_SOURCES = main.cpp test_base64.cpp test_cached_file.cpp 
test_cached_file_buffer.cpp test_cached_file_factory.cpp test_connection.cpp 
test_connections_scheduler.cpp test_files_utility.cpp test_filter_chain.cpp 
test_ftp.cpp test_gzip.cpp test_hashmap.cpp test_homedir.cpp 
test_http_request.cpp test_http_response.cpp test_md5.cpp test_mem_buff.cpp 
test_mem_stream.cpp test_multicast.cpp test_mutex.cpp test_recursive_mutex.cpp 
test_regex.cpp test_pipe.cpp test_safetime.cpp test_semaphore.cpp 
test_thread.cpp test_utility.cpp test_log_manager.cpp 
test_log_stream_factory.cpp test_socket_stream_creator.cpp 
test_file_stream_creator.cpp test_file_stream.cpp
+tests_suite_SOURCES = main.cpp test_connection.cpp test_ftp.cpp 
test_log_manager.cpp test_mutex.cpp test_security_domain.cpp test_validator.cpp 
test_auth_domain.cpp test_connections_scheduler.cpp test_gzip.cpp 
test_log_stream_factory.cpp test_pipe.cpp test_security_manager.cpp 
test_validator_factory.cpp test_base64.cpp test_file_stream.cpp 
test_hashmap.cpp test_md5.cpp test_recursive_mutex.cpp test_semaphore.cpp 
test_xml.cpp test_cached_file_buffer.cpp test_file_stream_creator.cpp 
test_homedir.cpp test_mem_buff.cpp test_regex.cpp 
test_socket_stream_creator.cpp test_cached_file.cpp test_files_utility.cpp 
test_http_request.cpp test_mem_stream.cpp test_safetime.cpp test_thread.cpp 
test_cached_file_factory.cpp test_filter_chain.cpp test_http_response.cpp 
test_multicast.cpp test_security_cache.cpp test_utility.cpp 
 tests_suite_LDADD = ../src/libmyserver.a $(CPPUNIT_LDFLAGS) $(PTHREAD_LIB) 
$(IDN_LIB) $(XNET_LIB) $(EVENT_LIB) $(DL_LIB) $(OPENSSL_LIB) $(ZLIB_LIB) 
$(XML_LIBS) $(LDFLAGS)

Added: branches/myserver_sec_new/tests/test_auth_domain.cpp
===================================================================
--- branches/myserver_sec_new/tests/test_auth_domain.cpp                        
        (rev 0)
+++ branches/myserver_sec_new/tests/test_auth_domain.cpp        2008-09-27 
21:40:15 UTC (rev 2849)
@@ -0,0 +1,61 @@
+/*
+ MyServer
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ 
+ This program is distributed in the hope that it will be useful, 
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ctype.h>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <include/conf/security/security_manager.h>
+#include <include/conf/security/auth_domain.h>
+
+#include <string.h>
+
+#include <iostream>
+using namespace std;
+
+class TestAuthDomain : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE( TestAuthDomain );
+  CPPUNIT_TEST( testGetName );
+  CPPUNIT_TEST_SUITE_END();
+  
+  SecurityToken *secToken;
+  AuthDomain* authDomain;
+public:
+  void setUp()
+  {
+    secToken = new SecurityToken();
+    authDomain = new AuthDomain(secToken);
+  }
+
+  void tearDown()
+  {
+    delete authDomain;
+    delete secToken;
+  }
+
+  void testGetName()
+  {
+    CPPUNIT_ASSERT_EQUAL(authDomain->getName().compare(""), 0);
+  }
+
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION( TestAuthDomain );

Added: branches/myserver_sec_new/tests/test_security_cache.cpp
===================================================================
--- branches/myserver_sec_new/tests/test_security_cache.cpp                     
        (rev 0)
+++ branches/myserver_sec_new/tests/test_security_cache.cpp     2008-09-27 
21:40:15 UTC (rev 2849)
@@ -0,0 +1,84 @@
+/*
+ MyServer
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ 
+ This program is distributed in the hope that it will be useful, 
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ctype.h>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <include/conf/security/security_manager.h>
+#include <include/conf/security/security_cache.h>
+
+#include <string.h>
+
+#include <iostream>
+using namespace std;
+
+class TestSecurityCache : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE ( TestSecurityCache );
+  CPPUNIT_TEST ( testMaxNodes );
+  CPPUNIT_TEST ( testGetParser );
+  CPPUNIT_TEST ( testGetSecurityFile );
+  CPPUNIT_TEST_SUITE_END ();
+  
+  SecurityCache *secCache;
+public:
+  void setUp ()
+  {
+    secCache = new SecurityCache ();
+  }
+
+  void tearDown ()
+  {
+    delete secCache;
+  }
+
+  void testMaxNodes ()
+  {
+    secCache->setMaxNodes (0);
+    CPPUNIT_ASSERT_EQUAL (secCache->getMaxNodes (), 0);
+
+    secCache->setMaxNodes (10);
+    CPPUNIT_ASSERT_EQUAL (secCache->getMaxNodes (), 10);
+
+    secCache->setMaxNodes (100);
+    CPPUNIT_ASSERT_EQUAL (secCache->getMaxNodes (), 100);
+  }
+
+  void testGetSecurityFile ()
+  {
+    string file("foo/bar/not/exist/in/reality");
+    string out;
+
+    CPPUNIT_ASSERT(secCache->getSecurityFile (file, file, out));
+  }
+
+
+  void testGetParser ()
+  {
+    string dir("foo/bar/not/exist/in/reality");
+    string file("baz");
+    CPPUNIT_ASSERT_EQUAL(secCache->getParser (dir, dir, false), 
(XmlParser*)NULL);
+  }
+
+
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION ( TestSecurityCache );

Added: branches/myserver_sec_new/tests/test_security_domain.cpp
===================================================================
--- branches/myserver_sec_new/tests/test_security_domain.cpp                    
        (rev 0)
+++ branches/myserver_sec_new/tests/test_security_domain.cpp    2008-09-27 
21:40:15 UTC (rev 2849)
@@ -0,0 +1,67 @@
+/*
+ MyServer
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ 
+ This program is distributed in the hope that it will be useful, 
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ctype.h>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <include/conf/security/security_manager.h>
+#include <include/conf/security/security_domain.h>
+
+#include <string.h>
+
+#include <iostream>
+using namespace std;
+
+
+class TestSecurityDomain : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE( TestSecurityDomain );
+  CPPUNIT_TEST( testGetValue );
+  CPPUNIT_TEST( testGetName );
+  CPPUNIT_TEST_SUITE_END();
+  
+  SecurityDomain* securityDomain;
+public:
+  void setUp()
+  {
+    securityDomain = new SecurityDomain();
+  }
+
+  void tearDown()
+  {
+    delete securityDomain;
+  }
+
+  void testGetName()
+  {
+    string val("value");
+    CPPUNIT_ASSERT_EQUAL(securityDomain->getName().compare(""), 0);
+  }
+
+  void testGetValue()
+  {
+    string val("value");
+    CPPUNIT_ASSERT_EQUAL(securityDomain->getValue(val), (string*)NULL);
+  }
+
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION( TestSecurityDomain );

Added: branches/myserver_sec_new/tests/test_security_manager.cpp
===================================================================
--- branches/myserver_sec_new/tests/test_security_manager.cpp                   
        (rev 0)
+++ branches/myserver_sec_new/tests/test_security_manager.cpp   2008-09-27 
21:40:15 UTC (rev 2849)
@@ -0,0 +1,63 @@
+/*
+ MyServer
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ 
+ This program is distributed in the hope that it will be useful, 
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ctype.h>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <include/conf/security/security_manager.h>
+#include <include/conf/security/validator_factory.h>
+
+#include <string.h>
+
+#include <iostream>
+using namespace std;
+
+class TestSecurityManager : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE( TestSecurityManager );
+  CPPUNIT_TEST( testGetPermissionMask );
+  CPPUNIT_TEST_SUITE_END();
+  
+  ValidatorFactory validatorFactory;
+  SecurityManager* securityManager;
+public:
+  void setUp()
+  {
+    securityManager = new SecurityManager(&validatorFactory);
+  }
+
+  void tearDown()
+  {
+    delete securityManager;
+  }
+
+  void testGetPermissionMask()
+  {
+    string val("value");
+    SecurityToken secToken;
+    string validator("xml");
+    CPPUNIT_ASSERT_EQUAL(securityManager->getPermissionMask(&secToken, NULL, 
validator), 0);
+ 
+  }
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION( TestSecurityManager );

Added: branches/myserver_sec_new/tests/test_validator.cpp
===================================================================
--- branches/myserver_sec_new/tests/test_validator.cpp                          
(rev 0)
+++ branches/myserver_sec_new/tests/test_validator.cpp  2008-09-27 21:40:15 UTC 
(rev 2849)
@@ -0,0 +1,61 @@
+#include <ctype.h>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <include/conf/security/security_manager.h>
+#include <include/conf/security/validator.h>
+
+#include <string.h>
+
+#include <iostream>
+using namespace std;
+
+class TestValidator : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE( TestValidator );
+  CPPUNIT_TEST( testGetPermissionMask );
+  CPPUNIT_TEST( testGetPermissionMaskImpl );
+  CPPUNIT_TEST( testGetValue );
+  CPPUNIT_TEST_SUITE_END();
+  
+  Validator* validator;
+public:
+  void setUp()
+  {
+    validator = new Validator();
+  }
+
+  void tearDown()
+  {
+    delete validator;
+  }
+
+  void testGetValue()
+  {
+    string val("value");
+    CPPUNIT_ASSERT_EQUAL(validator->getValue(val), (string*)NULL);
+ 
+  }
+ 
+  void testGetPermissionMaskImpl()
+  {
+    string val("value");
+    SecurityToken secToken;
+    CPPUNIT_ASSERT_EQUAL(validator->getPermissionMaskImpl(&secToken), 0);
+ 
+  }
+
+  void testGetPermissionMask()
+  {
+    string val("value");
+    SecurityToken secToken;
+    CPPUNIT_ASSERT_EQUAL(validator->getPermissionMask(&secToken, NULL), 0);
+ 
+  }
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION( TestValidator );

Added: branches/myserver_sec_new/tests/test_validator_factory.cpp
===================================================================
--- branches/myserver_sec_new/tests/test_validator_factory.cpp                  
        (rev 0)
+++ branches/myserver_sec_new/tests/test_validator_factory.cpp  2008-09-27 
21:40:15 UTC (rev 2849)
@@ -0,0 +1,71 @@
+#include <ctype.h>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <include/conf/security/security_manager.h>
+#include <include/conf/security/validator_factory.h>
+#include <include/conf/security/validator.h>
+
+#include <string.h>
+
+#include <iostream>
+using namespace std;
+
+
+class TestValidatorFactory : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE( TestValidatorFactory );
+  CPPUNIT_TEST( testGetValidator );
+  CPPUNIT_TEST( testAddValidator );
+  CPPUNIT_TEST( testIsValidatorPresent );
+  CPPUNIT_TEST_SUITE_END();
+  
+  ValidatorFactory* factory;
+public:
+  void setUp()
+  {
+    factory = new ValidatorFactory();
+  }
+
+  void tearDown()
+  {
+    delete factory;
+  }
+
+  void testGetValidator()
+  {
+    string val("foo");
+    CPPUNIT_ASSERT_EQUAL(factory->getValidator(val), (Validator*)NULL);
+ 
+  }
+ 
+  void testAddValidator()
+  {
+    string val("bar");
+    Validator *validator = new Validator;
+   
+    Validator* old = factory->addValidator(val, validator);
+
+    CPPUNIT_ASSERT_EQUAL(old, (Validator*)NULL);
+    CPPUNIT_ASSERT(factory->getValidator(val));
+  }
+
+  void testIsValidatorPresent()
+  {
+    string val("bar");
+    Validator *validator = new Validator;
+
+ 
+    CPPUNIT_ASSERT_EQUAL(factory->isValidatorPresent(val), false);
+   
+    factory->addValidator(val, validator);
+ 
+    CPPUNIT_ASSERT_EQUAL(factory->isValidatorPresent(val), true);
+  }
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION( TestValidatorFactory );






reply via email to

[Prev in Thread] Current Thread [Next in Thread]