Security4Delphiは、Delphiアプリケーションでセキュリティの概念を使用できるライブラリで構成されています。
セキュリティは、ほとんどのアプリケーションにとって非常に重要であり、開発チームに関する無限の議論の焦点です。セキュリティコンテキストの実装は、プレゼンテーションやテクノロジーレイヤーに関係なく、シンプルで柔軟な方法で設計されているため、独自のソリューションを自由に実装するか、既存の拡張機能を使用できます。
認証メカニズムは、ユーザーのシステムのアイデンティティを検証することを目的としています。
すでにIO認証メカニズムは、システムの特定の機能へのアクセスが許可されたユーザーのみが許可されていることを保証する責任があります。許可は、許可機能と役割による有効性の2つの方法で行われる場合があります。
地元のコピーを稼働させるには、これらの簡単な手順に従ってください。
このライブラリを使用するには、Delphi IDE(XE以上)の更新バージョンが必要です。
レポをクローンします
git clone https://github.com/ezequieljuliano/Security4Delphi.git
IDEの「検索パス」またはプロジェクトを次のディレクトリに追加します。
Security4Delphisrc
セキュリティコンテキストのパラダイムをセキュリティ4delphiで提供するには、次のことが必要です。
使用法を説明するために、アプリケーションのログを管理するためのソリューションを見てみましょう。
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;
[rebulicrole]、[rebynectianyrole]、[rebynectauthority]、[rebynectanyauthority]の側面でシステムを保護します。
Security4delphiをAspect4delphiと一緒に使用することは、アスペクト指向プログラミング(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