Security4Delphi
1.0.1
Security4Delphi由一个库组成,该库可以在您的Delphi应用程序中使用安全概念。
安全对于大多数应用程序以及关于开发团队的无休止讨论的重点是一个非常重要的关注点。无论演示文稿或技术层如何,安全环境的实现都是以一种简单而灵活的方式设计的,使您可以自由实施自己的解决方案或使用现有的扩展。
身份验证机制旨在验证用户对系统的身份。
IO授权机制已经负责确保仅授予授权用户访问系统的某些功能。授权可能以两种方式进行:权限功能并逐个角色启用。
要启动并运行本地副本,请遵循以下简单步骤。
要使用此库,需要更新版本的Delphi IDE(XE或更高)。
克隆仓库
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;
使用[必需的],[必需的anyrole],[quertauthority]和[quertanyauthority]方面保护系统:
可以使用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