defaultsecuritymanager.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #pragma warning( disable : 4786 )
  14. #include "defaultsecuritymanager.hpp"
  15. #include "authmap.ipp"
  16. //#ifdef _WIN32
  17. CDefaultSecurityManager::CDefaultSecurityManager(const char *serviceName, const char *config) : CBaseSecurityManager(serviceName,config)
  18. {
  19. }
  20. CDefaultSecurityManager::CDefaultSecurityManager(const char *serviceName, IPropertyTree *config) : CBaseSecurityManager(serviceName,config)
  21. {
  22. }
  23. //========Local Secuirty Manager==========
  24. CLocalSecurityManager::CLocalSecurityManager(const char *serviceName, const char *config) : CDefaultSecurityManager(serviceName, config)
  25. {
  26. }
  27. CLocalSecurityManager::CLocalSecurityManager(const char *serviceName, IPropertyTree *config) : CDefaultSecurityManager(serviceName, config)
  28. {
  29. }
  30. CLocalSecurityManager::~CLocalSecurityManager()
  31. {
  32. }
  33. bool CLocalSecurityManager::IsPasswordValid(ISecUser& sec_user)
  34. {
  35. IAuthenticatedUser* au = createAuthenticatedUser();
  36. StringBuffer userbuf;
  37. #ifdef _WIN32
  38. const char* realm = sec_user.getRealm();
  39. if(realm&&*realm)
  40. userbuf.append(realm).append("\\");
  41. #endif
  42. userbuf.append(sec_user.getName());
  43. return au->login(userbuf.str(), sec_user.credentials().getPassword());
  44. }
  45. IAuthMap * CLocalSecurityManager::createAuthMap(IPropertyTree * authconfig)
  46. {
  47. CAuthMap* authmap = new CAuthMap(this);
  48. IPropertyTreeIterator *loc_iter = NULL;
  49. loc_iter = authconfig->getElements(".//Location");
  50. if (loc_iter != NULL)
  51. {
  52. IPropertyTree *location = NULL;
  53. loc_iter->first();
  54. while(loc_iter->isValid())
  55. {
  56. location = &loc_iter->query();
  57. if (location)
  58. {
  59. StringBuffer pathstr, rstr, required, description;
  60. location->getProp("@path", pathstr);
  61. location->getProp("@resource", rstr);
  62. location->getProp("@required", required);
  63. location->getProp("@description", description);
  64. if(pathstr.length() == 0)
  65. throw MakeStringException(-1, "path empty in Authenticate/Location");
  66. if(rstr.length() == 0)
  67. throw MakeStringException(-1, "resource empty in Authenticate/Location");
  68. ISecResourceList* rlist = authmap->queryResourceList(pathstr.str());
  69. if(rlist == NULL)
  70. {
  71. rlist = createResourceList("localsecurity");
  72. authmap->add(pathstr.str(), rlist);
  73. }
  74. ISecResource* rs = rlist->addResource(rstr.str());
  75. unsigned requiredaccess = str2perm(required.str());
  76. rs->setRequiredAccessFlags(requiredaccess);
  77. rs->setDescription(description.str());
  78. }
  79. loc_iter->next();
  80. }
  81. loc_iter->Release();
  82. loc_iter = NULL;
  83. }
  84. return authmap;
  85. }