From 0cdc35a31b606056984c77332c05cb6e3f3ae776 Mon Sep 17 00:00:00 2001 From: sarit <151683854+sarit-r@users.noreply.github.com> Date: Tue, 3 Sep 2024 15:59:07 +0300 Subject: [PATCH] Revert "fixed conflict in auth" --- DB/configuration/event_config.json | 45 ++++++++++++++ .../Controllers/AuthenticationController.py | 21 ++++--- .../DataAccess/UserDAL.py | 14 ++--- .../__pycache__/UserDAL.cpython-311.pyc | Bin 5570 -> 0 bytes .../__pycache__/userModel.cpython-311.pyc | Bin 1188 -> 0 bytes .../Models/userModel.py | 57 ++++++++---------- .../Services/AuthenticationService.py | 43 ++++++------- .../AuthenticationService.cpython-311.pyc | Bin 3692 -> 3530 bytes 8 files changed, 108 insertions(+), 72 deletions(-) create mode 100644 DB/configuration/event_config.json delete mode 100644 Storage_UserAdministration/DataAccess/__pycache__/UserDAL.cpython-311.pyc delete mode 100644 Storage_UserAdministration/Models/__pycache__/userModel.cpython-311.pyc diff --git a/DB/configuration/event_config.json b/DB/configuration/event_config.json new file mode 100644 index 00000000..a2a3342e --- /dev/null +++ b/DB/configuration/event_config.json @@ -0,0 +1,45 @@ +{ + "funcs": { + "create_db_instance": { + "category": "creation", + "resource_type": "DBInstance", + "message": "db instance created" + }, + "delete_db_instance": { + "category": "deletion", + "resource_type": "DBInstance", + "message": "db instance deleted" + }, + "stop_db_instance": { + "category": "deletion", + "resource_type": "DBInstance", + "message": "DB instance shutdown" + }, + "start_db_instance": { + "category": "deletion", + "resource_type": "DBInstance", + "message": "DB instance restarted" + }, + + "create_db_snapshot":{ + "category": "creation", + "resource_type": "DBSnapshot", + "message": "db snapshot created" + }, + "delete_db_snapshot":{ + "category": "creation", + "resource_type": "DBSnapshot", + "message": "db snapshot deleted" + + }, + "restore_db_instance_from_snapshot":{ + "category": "restoring", + "resource_type": "DBSnapshot", + "message": "db instance restored from snapshot" + + } + }, + "errs": { + + } +} \ No newline at end of file diff --git a/Storage_UserAdministration/Controllers/AuthenticationController.py b/Storage_UserAdministration/Controllers/AuthenticationController.py index 0c3bfd27..e980e770 100644 --- a/Storage_UserAdministration/Controllers/AuthenticationController.py +++ b/Storage_UserAdministration/Controllers/AuthenticationController.py @@ -7,8 +7,8 @@ from Services.AuthenticationService import AuthenticationService class AuthenticationController: - def __init__(self): - self.auth_service = AuthenticationService() + def __init__(self, data_file_path): + self.auth_service = AuthenticationService(data_file_path) def login(self, username, password): session_id = self.auth_service.login(username, password) @@ -41,12 +41,13 @@ def register(self, username, password): # Example usage if __name__ == "__main__": - controller = AuthenticationController() - # # Register a user - controller.register('user', 'password123') - # # Login a user - session_id = controller.login('user', 'password123') + controller = AuthenticationController('users.json') + # Register a user + controller.register('user1', 'password123') + # Login a user + session_id = controller.login('user1', 'password123') # Check if the user is authenticated - controller.check_authentication('user') - # Logout the user - controller.logout('user') + if session_id: + controller.check_authentication(session_id) + # Logout the user + controller.logout(session_id) diff --git a/Storage_UserAdministration/DataAccess/UserDAL.py b/Storage_UserAdministration/DataAccess/UserDAL.py index c44ad970..c2e0389f 100644 --- a/Storage_UserAdministration/DataAccess/UserDAL.py +++ b/Storage_UserAdministration/DataAccess/UserDAL.py @@ -1,14 +1,14 @@ import json import os -# from Models.UserModel import User -# from Models.PermissionModel import Permission -# from Models.PolicyModel import Policy -# from Models.GroupModel import Group -# from Models.QuotaModel import Quota -# from Models.RoleModel import Role +from Models.UserModel import User +from Models.PermissionModel import Permission +from Models.PolicyModel import Policy +from Models.GroupModel import Group +from Models.QuotaModel import Quota +from Models.RoleModel import Role class UserDAL: - FILE_PATH = 'users.json' + FILE_PATH = "users_data.json" def __init__(self): self.users = self.load_users_from_file() diff --git a/Storage_UserAdministration/DataAccess/__pycache__/UserDAL.cpython-311.pyc b/Storage_UserAdministration/DataAccess/__pycache__/UserDAL.cpython-311.pyc deleted file mode 100644 index 77d026fd095bf1812e610dc80e0b900488524c64..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5570 zcmcIoO>7(25q`T|N=tI-l|(9vBgI-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i_*ms^tklP zM?StO_?Q5}93{9 zaI&!wx{Nx@X7Yrckj>k%n`)Q{*0vpd9?FqTxpPDAEQE^kv66gjT|D;V>iYUHrApS{5V^r4hPU2BWN>Hjon!-lrqmF;pa@oM2;pn|j$>#v7|DraNt?pC2 z-#nKF%{rUMz989Z9CXy!)$}&1@d9+Qfq=t$CS@3Kp~9nlzf*h`FGitbW10yt{B|~LCX~r6D6mf`*aMP) z0f`2ip(br|SRcF~xhw9JO{bFAp3{|r%w^aN`4*2GG2Xdnko+6yvtRVBrorAc9`Ybw zKU$j_!%^>p$yfotn+;Y{X2EHzeb&pF>|-}SxGQb8WB9)Kj>0vr4;EkTDY8k_zsaNZT#;om2t|*!KdK8R`nYb|XQ3Eg#&ZbPUisW;!|xfp}=^ z?;;sS@;;I?NIpb@`s(=oj)`J_jzElbBtiH$4g-XX?yua`v3Pb%;QRw{*K|mO;BVO? zE|GXY+*n;Aa(?(i;S%T^#m*HXaen;v;1Fo-D4fLhj-5mj{J}e8$c1FWOJK$0xMGEf zZjJGN%-2SgdpEJIhc<)k9lsms_{D}9affxEil=RShxDIA7u+Al7!bJUb6lB(7TK>% Y0*mao)pVZYV9EOQ5#vAJqm>EuKWfdWh5!Hn diff --git a/Storage_UserAdministration/Models/__pycache__/userModel.cpython-311.pyc b/Storage_UserAdministration/Models/__pycache__/userModel.cpython-311.pyc deleted file mode 100644 index de0da74eff078a97e7b6f95ce0fd6856635cc5d0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1188 zcmaJ<&1(};5TE@@HZf_`*tE2^L?qB$da+O}r4SW8r~zp`7#1E&-lp9)$<}>|(vm|C zJ@nu`2o-v&l>P($8MYKHdn$PHwi5MFFV1YTD~dXg{msYwy_tFQ_H8|`tW^>-0^(2`IMrA6_ftVazWVB{za!vXS-qB9*}(V32fUR0?gqZeKXItqHRFbOAS zJn{g?A(!tLbx#p3*HhbVn|m7JoEN9tFq^xS%B2jRW;IN^?j`EZ>Z-+=-7Kn}Dy(|# z7spK@QBW^=l#3_T1%rko46$Z5P2-*=Hd@Z6A#NEDSJ>UU)8@u<%W=(BixIEH8+Oyi zUd)#5G>yj&x9Y;6P6BgwbIa2i7PecAZKvtPZ0IJa@NI-He9OW3Z{b*cpg>yEH@pf(Fs(^v$5-_Ms{)a@i0`Q>7x_9*b+KD=)gKr0_nhh^cG=^ zbVvIAoi>7e%Wx=_i?Wvve+;%}iZw4y$ii4rc1JKnFl#}_@_9Fd%FDd4T)Vav5x1`e zH~%Ag6RBbvp$q4k>}lr4{>sO~{7GT{oqk*>ofb+bnbLc`2 zYdE}JCp*R1^R`(Z?6^AdFB9Yt4q=dh8gpqr0T4&j5W3OwlaR^!iHtVo1H$>$QC}k` z2HBh+55vLU0On-vjsg#J~PyH>ma#;z$F_ diff --git a/Storage_UserAdministration/Models/userModel.py b/Storage_UserAdministration/Models/userModel.py index 372a31fc..dc3787dc 100644 --- a/Storage_UserAdministration/Models/userModel.py +++ b/Storage_UserAdministration/Models/userModel.py @@ -1,51 +1,46 @@ -# from Models.PermissionModel import Permission -# from Models.PolicyModel import Policy -# from Models.GroupModel import Group -# from Models.QuotaModel import Quota -# from Models.RoleModel import Role -import uuid - +from Models.PermissionModel import Permission +from Models.PolicyModel import Policy +from Models.GroupModel import Group +from Models.QuotaModel import Quota +from Models.RoleModel import Role class User: def __init__( self, username: str, password: str, - email=None, - - # role: Optional[Role] = None, - # policies: Optional[List[Policy]] = None, - # quota: Optional[Quota] = None, - # groups: Optional[List[Group]] = None + email: str, + role: Optional[Role] = None, + policies: Optional[List[Policy]] = None, + quota: Optional[Quota] = None, + groups: Optional[List[Group]] = None ): self.user_id = str(uuid.uuid4()) # Unique identifier self.username = username - self.password=password + self.password_hash = hashlib.sha256(password.encode()).hexdigest() self.email = email - self.logged_in=False - self.token=None - # self.role = role - # self.policies = policies - # self.quota =quota - # self.groups = groups + self.role = role + self.policies = policies + self.quota =quota + self.groups = groups - # def hash_password(self, password): - # # Implement password hashing - # return hashlib.sha256(password.encode()).hexdigest() + def hash_password(self, password): + # Implement password hashing + return hashlib.sha256(password.encode()).hexdigest() def verify_password(self, password:str): # Verify password against the hashed password return self.password_hash == self.hash_password(password) - # def can(self, action, resource): - # return any( - # policy.evaluate(policy_name, permissions) for policy in self.policies - # ) or self.role.has_permission(permissions) + def can(self, action, resource): + return any( + policy.evaluate(policy_name, permissions) for policy in self.policies + ) or self.role.has_permission(permissions) - # def update_quota(self, quota: Quota): - # self.quota = quota + def update_quota(self, quota: Quota): + self.quota = quota - # def check_quota(self): - # return self.quota.check_exceeded() + def check_quota(self): + return self.quota.check_exceeded() diff --git a/Storage_UserAdministration/Services/AuthenticationService.py b/Storage_UserAdministration/Services/AuthenticationService.py index 06e4e51e..c91530ca 100644 --- a/Storage_UserAdministration/Services/AuthenticationService.py +++ b/Storage_UserAdministration/Services/AuthenticationService.py @@ -1,3 +1,4 @@ +# service.py import hashlib import uuid import sys @@ -5,49 +6,43 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -from DataAccess.UserDAL import UserDAL -from Models.userModel import User +from DataAccess.userManager import UserNanager + class AuthenticationService: - def __init__(self): - self.data_access =UserDAL() + def __init__(self,data_file_path): + self.data_access =UserNanager(data_file_path) + self.logged_in_users = {} def hash_password(self, password): return hashlib.sha256(password.encode()).hexdigest() def login(self, username, password): - users = self.data_access.users + users = self.data_access.load_users() user_data = users.get(username) if user_data and user_data.get('password') == self.hash_password(password): session_id = self.generate_session_id() - user_data['logged_in']=True - user_data['token']=session_id - self.data_access.save_users_to_file() + self.logged_in_users[session_id] = username return session_id else: return None - def logout(self, username): - users = self.data_access.users - user_data = users.get(username) - user_data['logged_in']=False - user_data['token']=None - self.data_access.save_users_to_file() - + def logout(self, session_id): + if session_id in self.logged_in_users: + self.logged_in_users.pop(session_id) def generate_session_id(self): return str(uuid.uuid4()) - def is_authenticated(self, username): - users = self.data_access.users - user_data = users.get(username) - return user_data['logged_in']==True + def is_authenticated(self, session_id): + return session_id in self.logged_in_users def register(self, username, password): - users = self.data_access.users + users = self.data_access.load_users() if username in users: + print(f"User {username} already exists.") return False hashed_password = self.hash_password(password) - new_user =User(username=username,password=password) - users[username] = {'password': hashed_password,'logged_in':False,'token':None} - self.data_access.save_users_to_file() - return new_user + users[username] = {'password': hashed_password} + self.data_access.save_users(users) + print(f"User {username} registered successfully.") + return True diff --git a/Storage_UserAdministration/Services/__pycache__/AuthenticationService.cpython-311.pyc b/Storage_UserAdministration/Services/__pycache__/AuthenticationService.cpython-311.pyc index 8c10488e78ada251a26225982fe340b872d66e06..92f324ab0e4cf64228e207d56f9bc1541dce6425 100644 GIT binary patch delta 1635 zcmZ`(-)kd99G}_UNw>+SS#5gPY=5}zrFWNJnrn~ddR9+4IK7kFsPqImgs^nCX(Xm) zHaWerwSDj*f)73Cp#>3x$erZ`(LY0c*p!uqg~Gjw;6sk;gCOE}Hf>N^XJNq4!S{QzX+en`tZuj$D@ns%q*?8XyynPY`&KhKHs26_Q4!|aA zs&P-%_ti^#>ZOJ{;i(gBGSrU=do6TLxja+5=_z_$Yba^98#;gfO&9|)adOaVmwSi~ z{@V_sOr~+bmGh-t;FuBuZoas>vbrl!PLK`(1PNzfbzQlZ1q=8@`gY=8V#1B^+Ei3n ze_u)NDarcXhBE0XlkRbCiAc$~5tft})4>v=FWMFAOVw)8gm3|;Q#e@4=91AV-%^@j z-^&?1!k);JAl0_a4tYLL26oIH2i)lhIJNnH*?r@7l3OYOkd7sG?s!8}Zfwexr)Up! zE^-YX7rv3)KKu*d|1^fOc&t zSx?EjO19bCzm;uj!~0r#PfLIEPD8uuX;*8p=D=8e!_{VLq_+G?tSKvS!1v{Id-A#Z zD-C(vlgHf=dHg_*x;@WtEd#V`L!R~ISy!HI#(HZNrYbWV!$6RZa!7Ev$YBCt7X^}N z%a6xIIYi*K*8w&=PfHNUXbW{f#^ibnbs!{@{ub&$Tp&~2`3U6On2d1mBM4z~g_}nZ z>L&3PItguRoKPxCxt!@3>xo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