Security4Delphi ประกอบด้วยห้องสมุดที่ช่วยให้สามารถใช้แนวคิดความปลอดภัยในแอปพลิเคชัน Delphi ของคุณ
ความปลอดภัยเป็นข้อกังวลเกี่ยวกับความสำคัญอย่างยิ่งสำหรับแอปพลิเคชันส่วนใหญ่และจุดสนใจของการอภิปรายที่ไม่มีที่สิ้นสุดเกี่ยวกับทีมพัฒนา การดำเนินการตามบริบทความปลอดภัยได้รับการออกแบบอย่างง่ายและยืดหยุ่นโดยไม่คำนึงถึงการนำเสนอหรือเลเยอร์เทคโนโลยีทำให้คุณมีอิสระในการใช้โซลูชันของตนเองหรือใช้ส่วนขยายที่มีอยู่
กลไกการรับรองความถูกต้องมีจุดมุ่งหมายเพื่อตรวจสอบตัวตนของผู้ใช้ในระบบ
กลไกการอนุญาต IO นั้นมีหน้าที่รับผิดชอบในการตรวจสอบให้แน่ใจว่ามีเพียงผู้ใช้ที่ได้รับอนุญาตเท่านั้นที่ได้รับอนุญาตให้เข้าถึงคุณสมบัติบางอย่างของระบบ การอนุญาตอาจเกิดขึ้นได้สองวิธี: ฟังก์ชั่นการอนุญาตและเปิดใช้งานโดยบทบาท
เพื่อรับสำเนาท้องถิ่นและเรียกใช้ทำตามขั้นตอนง่าย ๆ เหล่านี้
ในการใช้ไลบรารีนี้จำเป็นต้องมีเวอร์ชันที่อัปเดตของ Delphi IDE (XE หรือสูงกว่า)
โคลน repo
git clone https://github.com/ezequieljuliano/Security4Delphi.git
เพิ่ม "เส้นทางการค้นหา" ของ IDE หรือโครงการของคุณไดเรกทอรีต่อไปนี้:
Security4Delphisrc
เพื่อจัดทำกระบวนทัศน์บริบทความปลอดภัยในโครงการของคุณด้วย Security4Delphi ที่คุณต้องการ:
เพื่อแสดงให้เห็นการใช้งานลองดูวิธีการจัดการบันทึกของแอปพลิเคชัน
สร้างการใช้งานอินเทอร์เฟซ iauthenticator ของคุณ:
TAuthenticator = class(TAbstractSecurityProvider, IAuthenticator)
private
fAuthenticated: Boolean;
fAuthenticatedUser: IUser;
protected
function GetAuthenticatedUser: IUser;
procedure Authenticate(user: IUser);
procedure Unauthenticate;
public
procedure AfterConstruction; override;
end;
สร้างการใช้งานอินเทอร์เฟซ iauthorizer ของคุณ:
TAuthorizer = class(TAbstractSecurityProvider, IAuthorizer)
private
{ private declarations }
protected
function HasRole(role: string): Boolean;
function HasAnyRole(roles: array of string): Boolean;
function HasAuthority(authority: string): Boolean;
function HasAnyAuthority(authorities: array of string): Boolean;
public
{ public declarations }
end;
ลงทะเบียนการใช้งานของคุณในบริบท:
function SecurityContext: ISecurityContext;
begin
if (SecurityContextInstance = nil) then
begin
SecurityContextInstance := TSecurityContext.Create;
SecurityContextInstance.RegisterAuthenticator(TAuthenticator.Create(SecurityContextInstance));
SecurityContextInstance.RegisterAuthorizer(TAuthorizer.Create(SecurityContextInstance));
end;
Result := SecurityContextInstance;
end;
ใช้บริบทและตรวจสอบการรับรองความถูกต้องและการอนุญาต:
function TPersonRepository.Delete(personId: Integer): Boolean;
begin
if not SecurityContext.HasAnyRole(['ROLE_ADMIN', 'ROLE_MANAGER']) then
raise EAuthorizationException.Create('You do not have role to access this feature.');
if not SecurityContext.HasAuthority('PERSON_DELETE') then
raise EAuthorizationException.Create('You do not have permission to access this feature.');
Result := True;
end;
การปกป้องระบบด้วย [จำเป็นต้องมี], [จำเป็นต้องมีการกำหนดการทางเพศ], [จำเป็นต้องมีการกำหนดเวลา] และ [จำเป็นต้องมีการกำหนดเวลา]: แง่มุม:
การใช้ Security4Delphi ร่วมกับ Apparment4Delphi เป็นไปได้ที่จะใช้ประโยชน์จากแนวคิดของการเขียนโปรแกรมเชิงภาพ (AOP)
TPersonRepository = class
private
{ private declarations }
protected
{ protected declarations }
public
constructor Create;
destructor Destroy; override;
[RequiredRole('ROLE_ADMIN')]
[RequiredAuthority('PERSON_INSERT')]
function Insert(person: TPerson): TPerson; virtual;
[RequiredAnyRole('ROLE_ADMIN,ROLE_MANAGER')]
[RequiredAuthority('PERSON_UPDATE')]
function Update(person: TPerson): TPerson; virtual;
[RequiredAnyRole('ROLE_ADMIN,ROLE_MANAGER')]
[RequiredAuthority('PERSON_DELETE')]
function Delete(personId: Integer): Boolean; virtual;
[RequiredAnyRole('ROLE_ADMIN,ROLE_MANAGER,ROLE_GUEST')]
[RequiredAuthority('PERSON_VIEW')]
function FindById(personId: Integer): TPerson; virtual;
end;
ดูปัญหาเปิดสำหรับรายการคุณสมบัติที่เสนอ (และปัญหาที่รู้จัก)
การมีส่วนร่วมคือสิ่งที่ทำให้ชุมชนโอเพ่นซอร์สเป็นสถานที่ที่น่าทึ่งในการเรียนรู้สร้างแรงบันดาลใจและสร้าง การมีส่วนร่วมใด ๆ ที่คุณทำ จะได้รับการชื่นชมอย่างมาก
git checkout -b feature/AmazingFeature )git commit -m 'Add some AmazingFeature' )git push origin feature/AmazingFeature ) แจกจ่ายภายใต้ใบอนุญาต Apache ดู LICENSE สำหรับข้อมูลเพิ่มเติม
หากต้องการติดต่อเราใช้ตัวเลือก:
https://github.com/ezequieljuliano/security4delphi