diff --git a/README.md b/README.md
index ac5e74d..237c522 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,22 @@
-# safety4d
-Application Rules Management Framework inspired by the RBAC concept
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+# Router4Delphi
+Framework para Controle de Regras de Acesso do Usuários inspirado no conceito RBAC.
+
+## Instalação
+
+Basta registrar no Library Path do seu Delphi o caminho da pasta SRC da Biblioteca
\ No newline at end of file
diff --git a/RbacProjectGroup.groupproj b/RbacProjectGroup.groupproj
new file mode 100644
index 0000000..bc04a61
--- /dev/null
+++ b/RbacProjectGroup.groupproj
@@ -0,0 +1,48 @@
+
+
+ {828C2011-D2F0-4E90-9828-5C6F0E3E803D}
+
+
+
+
+
+
+
+
+
+
+ Default.Personality.12
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Safety4Delphi.dpk b/Safety4Delphi.dpk
new file mode 100644
index 0000000..e19f28d
--- /dev/null
+++ b/Safety4Delphi.dpk
@@ -0,0 +1,37 @@
+package Safety4Delphi;
+
+{$R *.res}
+{$IFDEF IMPLICITBUILDING This IFDEF should not be used by users}
+{$ALIGN 8}
+{$ASSERTIONS ON}
+{$BOOLEVAL OFF}
+{$DEBUGINFO OFF}
+{$EXTENDEDSYNTAX ON}
+{$IMPORTEDDATA ON}
+{$IOCHECKS ON}
+{$LOCALSYMBOLS ON}
+{$LONGSTRINGS ON}
+{$OPENSTRINGS ON}
+{$OPTIMIZATION OFF}
+{$OVERFLOWCHECKS OFF}
+{$RANGECHECKS OFF}
+{$REFERENCEINFO ON}
+{$SAFEDIVIDE OFF}
+{$STACKFRAMES ON}
+{$TYPEDADDRESS OFF}
+{$VARSTRINGCHECKS ON}
+{$WRITEABLECONST OFF}
+{$MINENUMSIZE 1}
+{$IMAGEBASE $400000}
+{$DEFINE DEBUG}
+{$ENDIF IMPLICITBUILDING}
+{$IMPLICITBUILD ON}
+
+requires
+ rtl;
+
+contains
+ Rbac4D in 'src\Rbac4D.pas',
+ Rbac4D.Interfaces in 'src\Rbac4D.Interfaces.pas';
+
+end.
diff --git a/Safety4Delphi.dproj b/Safety4Delphi.dproj
new file mode 100644
index 0000000..1c49582
--- /dev/null
+++ b/Safety4Delphi.dproj
@@ -0,0 +1,846 @@
+
+
+ {76E3723F-A2C6-4C46-B750-A446551153AE}
+ Safety4Delphi.dpk
+ 19.2
+ None
+ True
+ Debug
+ Win32
+ 1
+ Package
+
+
+ true
+
+
+ true
+ Base
+ true
+
+
+ true
+ Base
+ true
+
+
+ true
+ Base
+ true
+
+
+ true
+ Base
+ true
+
+
+ true
+ Cfg_1
+ true
+ true
+
+
+ true
+ Base
+ true
+
+
+ .\$(Platform)\$(Config)
+ .\$(Platform)\$(Config)
+ false
+ false
+ false
+ false
+ false
+ true
+ true
+ System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)
+ All
+ Safety4Delphi
+
+
+ None
+
+
+ None
+
+
+ Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)
+ Debug
+ true
+ CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=
+ 1033
+
+
+ DEBUG;$(DCC_Define)
+ true
+ false
+ true
+ true
+ true
+
+
+ false
+
+
+ false
+ RELEASE;$(DCC_Define)
+ 0
+ 0
+
+
+
+ MainSource
+
+
+
+
+
+ Cfg_2
+ Base
+
+
+ Base
+
+
+ Cfg_1
+ Base
+
+
+
+ Delphi.Personality.12
+ Package
+
+
+
+ Safety4Delphi.dpk
+
+
+
+
+
+ true
+
+
+
+
+ true
+
+
+
+
+ true
+
+
+
+
+ Safety4Delphi.bpl
+ true
+
+
+
+
+ 1
+
+
+ 0
+
+
+
+
+ classes
+ 1
+
+
+ classes
+ 1
+
+
+
+
+ res\xml
+ 1
+
+
+ res\xml
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+
+
+ library\lib\armeabi
+ 1
+
+
+ library\lib\armeabi
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+
+
+ library\lib\mips
+ 1
+
+
+ library\lib\mips
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+ library\lib\arm64-v8a
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+
+
+ res\drawable
+ 1
+
+
+ res\drawable
+ 1
+
+
+
+
+ res\values
+ 1
+
+
+ res\values
+ 1
+
+
+
+
+ res\values-v21
+ 1
+
+
+ res\values-v21
+ 1
+
+
+
+
+ res\values
+ 1
+
+
+ res\values
+ 1
+
+
+
+
+ res\drawable
+ 1
+
+
+ res\drawable
+ 1
+
+
+
+
+ res\drawable-xxhdpi
+ 1
+
+
+ res\drawable-xxhdpi
+ 1
+
+
+
+
+ res\drawable-xxxhdpi
+ 1
+
+
+ res\drawable-xxxhdpi
+ 1
+
+
+
+
+ res\drawable-ldpi
+ 1
+
+
+ res\drawable-ldpi
+ 1
+
+
+
+
+ res\drawable-mdpi
+ 1
+
+
+ res\drawable-mdpi
+ 1
+
+
+
+
+ res\drawable-hdpi
+ 1
+
+
+ res\drawable-hdpi
+ 1
+
+
+
+
+ res\drawable-xhdpi
+ 1
+
+
+ res\drawable-xhdpi
+ 1
+
+
+
+
+ res\drawable-mdpi
+ 1
+
+
+ res\drawable-mdpi
+ 1
+
+
+
+
+ res\drawable-hdpi
+ 1
+
+
+ res\drawable-hdpi
+ 1
+
+
+
+
+ res\drawable-xhdpi
+ 1
+
+
+ res\drawable-xhdpi
+ 1
+
+
+
+
+ res\drawable-xxhdpi
+ 1
+
+
+ res\drawable-xxhdpi
+ 1
+
+
+
+
+ res\drawable-xxxhdpi
+ 1
+
+
+ res\drawable-xxxhdpi
+ 1
+
+
+
+
+ res\drawable-small
+ 1
+
+
+ res\drawable-small
+ 1
+
+
+
+
+ res\drawable-normal
+ 1
+
+
+ res\drawable-normal
+ 1
+
+
+
+
+ res\drawable-large
+ 1
+
+
+ res\drawable-large
+ 1
+
+
+
+
+ res\drawable-xlarge
+ 1
+
+
+ res\drawable-xlarge
+ 1
+
+
+
+
+ res\values
+ 1
+
+
+ res\values
+ 1
+
+
+
+
+ 1
+
+
+ 1
+
+
+ 0
+
+
+
+
+ 1
+ .framework
+
+
+ 1
+ .framework
+
+
+ 0
+
+
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ 0
+ .dll;.bpl
+
+
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ 0
+ .bpl
+
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ 1
+
+
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF
+ 1
+
+
+ ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF
+ 1
+
+
+
+
+
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+
+
+
+
+
+ Contents\Resources
+ 1
+
+
+ Contents\Resources
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+ library\lib\arm64-v8a
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 0
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+
+
+ 1
+
+
+ 1
+
+
+
+
+ Assets
+ 1
+
+
+ Assets
+ 1
+
+
+
+
+ Assets
+ 1
+
+
+ Assets
+ 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ False
+ False
+ True
+ False
+
+
+ 12
+
+
+
+
+
diff --git a/Safety4Delphi.res b/Safety4Delphi.res
new file mode 100644
index 0000000..172924e
Binary files /dev/null and b/Safety4Delphi.res differ
diff --git a/assets/logo.fw.png b/assets/logo.fw.png
new file mode 100644
index 0000000..2f26e01
Binary files /dev/null and b/assets/logo.fw.png differ
diff --git a/samples/RbacSample.dpr b/samples/RbacSample.dpr
new file mode 100644
index 0000000..fee4f66
--- /dev/null
+++ b/samples/RbacSample.dpr
@@ -0,0 +1,15 @@
+program RbacSample;
+
+uses
+ Vcl.Forms,
+ Unit1 in 'Unit1.pas' {Form1};
+
+{$R *.res}
+
+begin
+ Application.Initialize;
+ ReportMemoryLeaksOnShutdown := True;
+ Application.MainFormOnTaskbar := True;
+ Application.CreateForm(TForm1, Form1);
+ Application.Run;
+end.
diff --git a/samples/RbacSample.dproj b/samples/RbacSample.dproj
new file mode 100644
index 0000000..05fc52a
--- /dev/null
+++ b/samples/RbacSample.dproj
@@ -0,0 +1,922 @@
+
+
+ {94E1E924-4B2D-49BF-9361-D6402259FADC}
+ 19.2
+ VCL
+ True
+ Debug
+ Win32
+ 1
+ Application
+ RbacSample.dpr
+
+
+ true
+
+
+ true
+ Base
+ true
+
+
+ true
+ Base
+ true
+
+
+ true
+ Base
+ true
+
+
+ true
+ Cfg_1
+ true
+ true
+
+
+ true
+ Base
+ true
+
+
+ true
+ Cfg_2
+ true
+ true
+
+
+ .\$(Platform)\$(Config)
+ .\$(Platform)\$(Config)
+ false
+ false
+ false
+ false
+ false
+ System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace)
+ $(BDS)\bin\delphi_PROJECTICON.ico
+ $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png
+ $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png
+ RbacSample
+
+
+ DBXSqliteDriver;RESTComponents;fmxase;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;bindcompvclsmp;emsclientfiredac;tethering;svnui;DataSnapFireDAC;FireDACADSDriver;DBXMSSQLDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;vcldb;bindcompfmx;svn;DBXOracleDriver;inetdb;CEF4Delphi;emsedge;fmx;FireDACIBDriver;fmxdae;vcledge;FireDACDBXDriver;dbexpress;IndyCore;vclx;dsnap;emsclient;DataSnapCommon;FireDACCommon;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;vclie;bindengine;DBXMySQLDriver;CloudService;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;FireDACCommonODBC;FireDACCommonDriver;DataSnapClient;inet;IndyIPCommon;bindcompdbx;vcl;IndyIPServer;DBXSybaseASEDriver;TBGWebCharts;IndySystem;FireDACDb2Driver;bindcompvclwinx;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;FireDAC;emshosting;FireDACSqliteDriver;FireDACPgDriver;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;soaprtl;DbxCommonDriver;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;emsserverresource;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;DataSnapServerMidas;$(DCC_UsePackage)
+ Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)
+ Debug
+ true
+ CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=
+ 1033
+ $(BDS)\bin\default_app.manifest
+
+
+ DBXSqliteDriver;RESTComponents;fmxase;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;bindcompvclsmp;emsclientfiredac;tethering;DataSnapFireDAC;FireDACADSDriver;DBXMSSQLDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;vcldb;bindcompfmx;DBXOracleDriver;inetdb;CEF4Delphi;emsedge;fmx;FireDACIBDriver;fmxdae;vcledge;FireDACDBXDriver;dbexpress;IndyCore;vclx;dsnap;emsclient;DataSnapCommon;FireDACCommon;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;vclie;bindengine;DBXMySQLDriver;CloudService;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;FireDACCommonODBC;FireDACCommonDriver;DataSnapClient;inet;IndyIPCommon;bindcompdbx;vcl;IndyIPServer;DBXSybaseASEDriver;IndySystem;FireDACDb2Driver;bindcompvclwinx;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;FireDAC;emshosting;FireDACSqliteDriver;FireDACPgDriver;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;soaprtl;DbxCommonDriver;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;emsserverresource;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;DataSnapServerMidas;$(DCC_UsePackage)
+
+
+ DEBUG;$(DCC_Define)
+ true
+ false
+ true
+ true
+ true
+
+
+ false
+ true
+ PerMonitorV2
+ D:\Projetos\Componentes\RBAC4D\src;$(DCC_UnitSearchPath)
+ true
+ 1033
+
+
+ false
+ RELEASE;$(DCC_Define)
+ 0
+ 0
+
+
+ true
+ PerMonitorV2
+
+
+
+ MainSource
+
+
+
+ dfm
+
+
+ Cfg_2
+ Base
+
+
+ Base
+
+
+ Cfg_1
+ Base
+
+
+
+ Delphi.Personality.12
+ Application
+
+
+
+ RbacSample.dpr
+
+
+ Microsoft Office 2000 Sample Automation Server Wrapper Components
+ Microsoft Office XP Sample Automation Server Wrapper Components
+ CEF4Delphi
+
+
+
+
+
+ RbacSample.exe
+ true
+
+
+
+
+ 1
+
+
+ Contents\MacOS
+ 1
+
+
+ 0
+
+
+
+
+ classes
+ 1
+
+
+ classes
+ 1
+
+
+
+
+ res\xml
+ 1
+
+
+ res\xml
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+
+
+ library\lib\armeabi
+ 1
+
+
+ library\lib\armeabi
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+
+
+ library\lib\mips
+ 1
+
+
+ library\lib\mips
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+ library\lib\arm64-v8a
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+
+
+ res\drawable
+ 1
+
+
+ res\drawable
+ 1
+
+
+
+
+ res\values
+ 1
+
+
+ res\values
+ 1
+
+
+
+
+ res\values-v21
+ 1
+
+
+ res\values-v21
+ 1
+
+
+
+
+ res\values
+ 1
+
+
+ res\values
+ 1
+
+
+
+
+ res\drawable
+ 1
+
+
+ res\drawable
+ 1
+
+
+
+
+ res\drawable-xxhdpi
+ 1
+
+
+ res\drawable-xxhdpi
+ 1
+
+
+
+
+ res\drawable-xxxhdpi
+ 1
+
+
+ res\drawable-xxxhdpi
+ 1
+
+
+
+
+ res\drawable-ldpi
+ 1
+
+
+ res\drawable-ldpi
+ 1
+
+
+
+
+ res\drawable-mdpi
+ 1
+
+
+ res\drawable-mdpi
+ 1
+
+
+
+
+ res\drawable-hdpi
+ 1
+
+
+ res\drawable-hdpi
+ 1
+
+
+
+
+ res\drawable-xhdpi
+ 1
+
+
+ res\drawable-xhdpi
+ 1
+
+
+
+
+ res\drawable-mdpi
+ 1
+
+
+ res\drawable-mdpi
+ 1
+
+
+
+
+ res\drawable-hdpi
+ 1
+
+
+ res\drawable-hdpi
+ 1
+
+
+
+
+ res\drawable-xhdpi
+ 1
+
+
+ res\drawable-xhdpi
+ 1
+
+
+
+
+ res\drawable-xxhdpi
+ 1
+
+
+ res\drawable-xxhdpi
+ 1
+
+
+
+
+ res\drawable-xxxhdpi
+ 1
+
+
+ res\drawable-xxxhdpi
+ 1
+
+
+
+
+ res\drawable-small
+ 1
+
+
+ res\drawable-small
+ 1
+
+
+
+
+ res\drawable-normal
+ 1
+
+
+ res\drawable-normal
+ 1
+
+
+
+
+ res\drawable-large
+ 1
+
+
+ res\drawable-large
+ 1
+
+
+
+
+ res\drawable-xlarge
+ 1
+
+
+ res\drawable-xlarge
+ 1
+
+
+
+
+ res\values
+ 1
+
+
+ res\values
+ 1
+
+
+
+
+ 1
+
+
+ Contents\MacOS
+ 1
+
+
+ 0
+
+
+
+
+ Contents\MacOS
+ 1
+ .framework
+
+
+ Contents\MacOS
+ 1
+ .framework
+
+
+ 0
+
+
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ Contents\MacOS
+ 1
+ .dylib
+
+
+ Contents\MacOS
+ 1
+ .dylib
+
+
+ 0
+ .dll;.bpl
+
+
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ 1
+ .dylib
+
+
+ Contents\MacOS
+ 1
+ .dylib
+
+
+ Contents\MacOS
+ 1
+ .dylib
+
+
+ 0
+ .bpl
+
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ Contents\Resources\StartUp\
+ 0
+
+
+ Contents\Resources\StartUp\
+ 0
+
+
+ 0
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+ ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset
+ 1
+
+
+
+
+ 1
+
+
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF
+ 1
+
+
+ ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF
+ 1
+
+
+
+
+ ..\
+ 1
+
+
+ ..\
+ 1
+
+
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).launchscreen
+ 64
+
+
+ ..\$(PROJECTNAME).launchscreen
+ 64
+
+
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+
+
+ ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF
+ 1
+
+
+
+
+ ..\
+ 1
+
+
+ ..\
+ 1
+
+
+
+
+ Contents
+ 1
+
+
+ Contents
+ 1
+
+
+
+
+ Contents\Resources
+ 1
+
+
+ Contents\Resources
+ 1
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+ library\lib\arm64-v8a
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ 1
+
+
+ Contents\MacOS
+ 1
+
+
+ Contents\MacOS
+ 1
+
+
+ 0
+
+
+
+
+ library\lib\armeabi-v7a
+ 1
+
+
+
+
+ 1
+
+
+ 1
+
+
+
+
+ Assets
+ 1
+
+
+ Assets
+ 1
+
+
+
+
+ Assets
+ 1
+
+
+ Assets
+ 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ True
+ False
+
+
+ 12
+
+
+
+
+
diff --git a/samples/RbacSample.res b/samples/RbacSample.res
new file mode 100644
index 0000000..3eafdff
Binary files /dev/null and b/samples/RbacSample.res differ
diff --git a/samples/Unit1.dfm b/samples/Unit1.dfm
new file mode 100644
index 0000000..e5fd1b5
--- /dev/null
+++ b/samples/Unit1.dfm
@@ -0,0 +1,120 @@
+object Form1: TForm1
+ Left = 0
+ Top = 0
+ Caption = 'Form1'
+ ClientHeight = 574
+ ClientWidth = 843
+ Color = clBtnFace
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -11
+ Font.Name = 'Tahoma'
+ Font.Style = []
+ OldCreateOrder = False
+ DesignSize = (
+ 843
+ 574)
+ PixelsPerInch = 96
+ TextHeight = 13
+ object GetResources: TButton
+ Left = 8
+ Top = 49
+ Width = 161
+ Height = 35
+ Caption = 'GetResources'
+ TabOrder = 0
+ OnClick = GetResourcesClick
+ end
+ object Memo1: TMemo
+ Left = 320
+ Top = 8
+ Width = 515
+ Height = 558
+ Anchors = [akLeft, akTop, akRight, akBottom]
+ Lines.Strings = (
+ 'Memo1')
+ TabOrder = 1
+ ExplicitWidth = 451
+ ExplicitHeight = 438
+ end
+ object Button1: TButton
+ Left = 8
+ Top = 90
+ Width = 161
+ Height = 35
+ Caption = 'CreateGroupPermission'
+ TabOrder = 2
+ OnClick = Button1Click
+ end
+ object Button2: TButton
+ Left = 8
+ Top = 174
+ Width = 161
+ Height = 35
+ Caption = 'RegisterUserKeys'
+ TabOrder = 3
+ OnClick = Button2Click
+ end
+ object Button3: TButton
+ Left = 8
+ Top = 231
+ Width = 161
+ Height = 35
+ Caption = 'GetSafety4DConfig'
+ TabOrder = 4
+ OnClick = Button3Click
+ end
+ object Button4: TButton
+ Left = 8
+ Top = 8
+ Width = 161
+ Height = 35
+ Caption = 'RegisterResource'
+ TabOrder = 5
+ OnClick = Button4Click
+ end
+ object Button5: TButton
+ Left = 8
+ Top = 295
+ Width = 161
+ Height = 35
+ Caption = 'SaveSafety4DConfig'
+ TabOrder = 6
+ OnClick = Button5Click
+ end
+ object Button6: TButton
+ Left = 8
+ Top = 359
+ Width = 161
+ Height = 35
+ Caption = 'LoadSafety4DConfig'
+ TabOrder = 7
+ OnClick = Button6Click
+ end
+ object Button7: TButton
+ Left = 8
+ Top = 131
+ Width = 161
+ Height = 35
+ Caption = 'GetGroupsPermissions'
+ TabOrder = 8
+ OnClick = Button7Click
+ end
+ object Button8: TButton
+ Left = 48
+ Top = 464
+ Width = 121
+ Height = 25
+ Caption = 'Button8'
+ TabOrder = 9
+ OnClick = Button8Click
+ end
+ object Edit1: TEdit
+ Left = 48
+ Top = 437
+ Width = 121
+ Height = 21
+ TabOrder = 10
+ Text = 'delete'
+ end
+end
diff --git a/samples/Unit1.pas b/samples/Unit1.pas
new file mode 100644
index 0000000..9fcaaa8
--- /dev/null
+++ b/samples/Unit1.pas
@@ -0,0 +1,317 @@
+unit Unit1;
+
+interface
+
+uses
+ Winapi.Windows,
+ Winapi.Messages,
+ System.SysUtils,
+ System.Variants,
+ System.Classes,
+ Vcl.Graphics,
+ Vcl.Controls,
+ Vcl.Forms,
+ Vcl.Dialogs,
+ Vcl.StdCtrls;
+
+type
+ TForm1 = class(TForm)
+ GetResources: TButton;
+ Memo1: TMemo;
+ Button1: TButton;
+ Button2: TButton;
+ Button3: TButton;
+ Button4: TButton;
+ Button5: TButton;
+ Button6: TButton;
+ Button7: TButton;
+ Button8: TButton;
+ Edit1: TEdit;
+ procedure GetResourcesClick(Sender: TObject);
+ procedure Button1Click(Sender: TObject);
+ procedure Button2Click(Sender: TObject);
+ procedure Button3Click(Sender: TObject);
+ procedure Button4Click(Sender: TObject);
+ procedure Button5Click(Sender: TObject);
+ procedure Button6Click(Sender: TObject);
+ procedure Button7Click(Sender: TObject);
+ procedure Button8Click(Sender: TObject);
+ private
+ { Private declarations }
+ procedure RegisterResources;
+ procedure _GetResources;
+ procedure _GetGroupsPermissions;
+ procedure _GetUserKeys;
+ public
+ { Public declarations }
+ end;
+
+var
+ Form1: TForm1;
+
+implementation
+
+{$R *.dfm}
+
+uses
+ Safety4D,
+ System.JSON,
+ Rest.Json,
+ System.IOUtils;
+
+procedure TForm1._GetGroupsPermissions;
+var
+ aJsonSafety4D : TJsonObject;
+begin
+ aJsonSafety4D := TJSONObject.Create;
+ try
+ TSafety4D
+ .New
+ .groupPermission
+ .getGroups(aJsonSafety4D);
+
+ Memo1.Lines.Clear;
+ Memo1.Lines.Add(TJson.Format(aJsonSafety4D));
+ finally
+ aJsonSafety4D.Free;
+ end;
+
+end;
+
+procedure TForm1._GetResources;
+var
+ aJsonSafety4D : TJsonObject;
+begin
+ aJsonSafety4D := TJSONObject.Create;
+ try
+ TSafety4D
+ .New
+ .resources
+ .getResource(aJsonSafety4D);
+
+ Memo1.Lines.Clear;
+ Memo1.Lines.Add(TJson.Format(aJsonSafety4D));
+ finally
+ aJsonSafety4D.Free;
+ end;
+end;
+
+procedure TForm1._GetUserKeys;
+var
+ aJsonSafety4D : TJsonObject;
+begin
+ aJsonSafety4D := TJSONObject.Create;
+ try
+ TSafety4D
+ .New
+ .userKey
+ .getUserKey(aJsonSafety4D);
+
+ Memo1.Lines.Clear;
+ Memo1.Lines.Add(TJson.Format(aJsonSafety4D));
+ finally
+ aJsonSafety4D.Free;
+ end;
+end;
+
+procedure TForm1.GetResourcesClick(Sender: TObject);
+begin
+ _GetResources;
+
+ {*
+ TRbac4D
+ .New
+
+ //Como registrar os recursos
+ //Default Resource [view, read, write, delete, action]
+
+ //>>;
+
+
+
+
+ //Buscar grupo de permissões
+ TRbac4D
+ .New
+ .getFunctionDefinitions; //TArray
+
+
+ //Busar Resources
+ TRbac4D
+ .New
+ .getResourcesGroup('GroupName'); //TArray
+
+
+ //Como validar o acesso a um recurso
+ TRbac4D
+ .New
+ .validateAccess
+ .roleName('operador')
+ .group('housex')
+ .provider('user')
+ .resource('Actions.getSaldo')
+ .Execute; //Boolean
+
+
+ //Atribuir as Roles na instancia global
+ TRbac4D
+ .New
+ .roleName('operador|marketing|gerente');
+
+
+ TRbac4D
+ .New
+ .loadConfiguration(aJsonString);
+
+ TRbac4D
+ .New
+ .saveConfiguration; //Retorna JsonString;
+
+ *}
+end;
+
+procedure TForm1.Button1Click(Sender: TObject);
+begin
+ TSafety4D
+ .New
+ .groupPermission
+ .groupRegister
+ .add('Gerente')
+ .description('Permissões completa de gestão do Sistema')
+ .actions
+ .add('*')
+ .&end
+ .notActions
+ .add('users.delete')
+ .add('users.write')
+ .&end
+ .&end
+
+ .groupRegister
+ .add('Comercial')
+ .description('Permissões de Recursos Comerciais')
+ .actions
+ .add('*')
+ .&end
+ .notActions
+ .add('users.delete')
+ .add('users.write')
+ .&end
+ .&end
+ .&end;
+end;
+
+procedure TForm1.Button2Click(Sender: TObject);
+begin
+ TSafety4D
+ .New
+ .userKey
+ .registerUserKey
+ .Add('Fulano de Tal')
+ .addPermission('Gerente')
+ .&end
+ .Add('Beltrano')
+ .addPermission('Comercial')
+ .&end
+ .&end
+ .&end;
+
+ _GetUserKeys;
+end;
+
+procedure TForm1.Button3Click(Sender: TObject);
+var
+ aJsonSafety4D : TJsonObject;
+begin
+ aJsonSafety4D := TJSONObject.Create;
+ try
+ TSafety4D.New.getConfig(aJsonSafety4D);
+
+ Memo1.Lines.Clear;
+ Memo1.Lines.Add(TJson.Format(aJsonSafety4D));
+ finally
+ aJsonSafety4D.Free;
+ end;
+
+end;
+
+procedure TForm1.Button4Click(Sender: TObject);
+begin
+ RegisterResources;
+end;
+
+procedure TForm1.Button5Click(Sender: TObject);
+begin
+ TSafety4D.New.SaveToStorage();
+end;
+
+procedure TForm1.Button6Click(Sender: TObject);
+var
+ JSONValue : TJsonValue;
+ LFileName: string;
+begin
+ LFileName := ChangeFileExt(ParamStr(0), '.s4d');
+ JSONValue := TJSONObject.ParseJSONValue(TFile.ReadAllText(LFileName));
+ try
+ TSafety4D.New.LoadConfig(JSONValue as TJSONObject);
+ finally
+ JSONValue.Free;
+ end;
+end;
+
+procedure TForm1.Button7Click(Sender: TObject);
+begin
+ _GetGroupsPermissions;
+end;
+
+procedure TForm1.Button8Click(Sender: TObject);
+begin
+ try
+ TSafety4D.New
+ .Validation
+ .userKey('{34C940ED-50E7-4CE3-B701-03CF1E15F28B}')
+ .application('delphitohero')
+ .resource('users')
+ .action(edit1.Text)
+ .validate;
+ ShowMessage('Usuario Autorizado');
+ except on e : Exception do
+ raise Exception.Create(e.Message);
+ end;
+end;
+
+procedure TForm1.RegisterResources;
+begin
+ TSafety4D
+ .New
+ .resources
+ .registerResources
+ .resourcesGroupName
+ .add('delphitohero')
+ .providerName
+ .add('users')
+ .actions
+ .add('read')
+ .description('read-only')
+ .errormsg('not permit')
+ .&end
+ .add('write')
+ .description('read-write')
+ .errormsg('not write data')
+ .&end
+ .add('delete')
+ .description('delete-data')
+ .errormsg('not delete data')
+ .&end
+ .add('view')
+ .description('view data')
+ .errormsg('not view data')
+ .&end
+ .&end
+ .&end
+ .&end
+ .&end
+ .&end;
+end;
+
+end.
diff --git a/src/Safety4D.Groups.Actions.pas b/src/Safety4D.Groups.Actions.pas
new file mode 100644
index 0000000..72046e6
--- /dev/null
+++ b/src/Safety4D.Groups.Actions.pas
@@ -0,0 +1,61 @@
+unit Safety4D.Groups.Actions;
+
+interface
+
+uses
+ System.Generics.Collections,
+ Safety4D.Interfaces;
+
+type
+ TSafety4DGroupActions = class(TInterfacedObject, iSafety4DGroupActions)
+ private
+ [weak]
+ FParent : iSafety4DGroupRegister;
+ FList : TList;
+ public
+ constructor Create(aParent : iSafety4DGroupRegister);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4DGroupRegister) : iSafety4DGroupActions;
+ function add ( aValue : String ) : iSafety4DGroupActions;
+ function getActions : TList;
+ function &End : iSafety4DGroupRegister;
+ end;
+
+implementation
+
+{ TSafety4DGroupActions }
+
+function TSafety4DGroupActions.&end : iSafety4DGroupRegister;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DGroupActions.add(aValue: String): iSafety4DGroupActions;
+begin
+ Result := Self;
+ FList.Add(aValue);
+end;
+
+function TSafety4DGroupActions.getActions: TList;
+begin
+ Result := FList;
+end;
+
+constructor TSafety4DGroupActions.Create(aParent : iSafety4DGroupRegister);
+begin
+ FParent := aParent;
+ FList := TList.Create;
+end;
+
+destructor TSafety4DGroupActions.Destroy;
+begin
+ FList.DisposeOf;
+ inherited;
+end;
+
+class function TSafety4DGroupActions.New(aParent : iSafety4DGroupRegister): iSafety4DGroupActions;
+begin
+ Result := Self.Create(aParent);
+end;
+
+end.
diff --git a/src/Safety4D.Groups.ListActions.pas b/src/Safety4D.Groups.ListActions.pas
new file mode 100644
index 0000000..a296ad7
--- /dev/null
+++ b/src/Safety4D.Groups.ListActions.pas
@@ -0,0 +1,98 @@
+unit Safety4D.Groups.ListActions;
+
+interface
+
+uses
+ Safety4D.Interfaces;
+
+type
+ TSafety4DGroupsListActions = class(TInterfacedObject, iSafety4DGroupListActions)
+ private
+ [weak]
+ FParent : iSafety4DGroupRegister;
+ FActions : iSafety4DGroupActions;
+ FNotActions : iSafety4DGroupNotActions;
+ FDescription : String;
+ FKey : String;
+ public
+ constructor Create(aParent : iSafety4DGroupRegister);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4DGroupRegister) : iSafety4DGroupListActions;
+ function actions : iSafety4DGroupActions;
+ function notActions : iSafety4DGroupNotActions;
+ function description ( aValue : String ) : iSafety4DGroupListActions; overload;
+ function description : String; overload;
+ function key ( aValue : String ) : iSafety4DGroupListActions; overload;
+ function key : string; overload;
+ function &End : iSafety4DGroupRegister;
+ end;
+
+implementation
+
+uses
+ Safety4D.Groups.Actions, Safety4D.Groups.NotActions;
+
+{ TSafety4DGroupsListActions }
+
+function TSafety4DGroupsListActions.&end : iSafety4DGroupRegister;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DGroupsListActions.key: string;
+begin
+ Result := FKey;
+end;
+
+function TSafety4DGroupsListActions.key(
+ aValue: String): iSafety4DGroupListActions;
+begin
+ Result := Self;
+ FKey := aValue;
+end;
+
+function TSafety4DGroupsListActions.actions: iSafety4DGroupActions;
+begin
+ if not Assigned(FActions) then
+ FActions := TSafety4DGroupActions.New(FParent);
+
+ Result := FActions;
+end;
+
+constructor TSafety4DGroupsListActions.Create(aParent : iSafety4DGroupRegister);
+begin
+ FParent := aParent;
+end;
+
+function TSafety4DGroupsListActions.description: String;
+begin
+ Result := FDescription;
+end;
+
+function TSafety4DGroupsListActions.description(
+ aValue: String): iSafety4DGroupListActions;
+begin
+ Result := Self;
+ FDescription := aValue;
+end;
+
+destructor TSafety4DGroupsListActions.Destroy;
+begin
+
+ inherited;
+end;
+
+class function TSafety4DGroupsListActions.New(aParent : iSafety4DGroupRegister): iSafety4DGroupListActions;
+begin
+ Result := Self.Create(aParent);
+end;
+
+function TSafety4DGroupsListActions.notActions: iSafety4DGroupNotActions;
+begin
+ if not Assigned(FNotActions) then
+ FNotActions := TSafety4DGroupNotActions.New(FParent);
+
+ Result := FNotActions;
+end;
+
+end.
diff --git a/src/Safety4D.Groups.NotActions.pas b/src/Safety4D.Groups.NotActions.pas
new file mode 100644
index 0000000..92f7228
--- /dev/null
+++ b/src/Safety4D.Groups.NotActions.pas
@@ -0,0 +1,61 @@
+unit Safety4D.Groups.NotActions;
+
+interface
+
+uses
+ System.Generics.Collections,
+ Safety4D.Interfaces;
+
+type
+ TSafety4DGroupNotActions = class(TInterfacedObject, iSafety4DGroupNotActions)
+ private
+ [weak]
+ FParent : iSafety4DGroupRegister;
+ FList : TList;
+ public
+ constructor Create(aParent : iSafety4DGroupRegister);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4DGroupRegister) : iSafety4DGroupNotActions;
+ function add ( aValue : String ) : iSafety4DGroupNotActions;
+ function getNotActions : TList;
+ function &End : iSafety4DGroupRegister;
+ end;
+
+implementation
+
+{ TSafety4DGroupNotActions }
+
+function TSafety4DGroupNotActions.&end : iSafety4DGroupRegister;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DGroupNotActions.add(aValue: String): iSafety4DGroupNotActions;
+begin
+ Result := Self;
+ FList.Add(aValue);
+end;
+
+function TSafety4DGroupNotActions.getNotActions: TList;
+begin
+ Result := FList;
+end;
+
+constructor TSafety4DGroupNotActions.Create(aParent : iSafety4DGroupRegister);
+begin
+ FParent := aParent;
+ FList := TList.Create;
+end;
+
+destructor TSafety4DGroupNotActions.Destroy;
+begin
+ FList.DisposeOf;
+ inherited;
+end;
+
+class function TSafety4DGroupNotActions.New(aParent : iSafety4DGroupRegister): iSafety4DGroupNotActions;
+begin
+ Result := Self.Create(aParent);
+end;
+
+end.
diff --git a/src/Safety4D.Groups.Register.pas b/src/Safety4D.Groups.Register.pas
new file mode 100644
index 0000000..1b408bf
--- /dev/null
+++ b/src/Safety4D.Groups.Register.pas
@@ -0,0 +1,116 @@
+unit Safety4D.Groups.Register;
+
+interface
+
+uses
+ System.Generics.Collections,
+ Safety4D.Interfaces,
+ System.JSON;
+
+type
+ TSafety4DGroupRegister = class(TInterfacedObject, iSafety4DGroupRegister)
+ private
+ [weak]
+ FParent : iSafety4DGroup;
+ FActions : iSafety4DGroupListActions;
+ FList : TDictionary;
+ public
+ constructor Create(aParent : iSafety4DGroup);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4DGroup) : iSafety4DGroupRegister;
+ function add ( aRoleName : String ) : iSafety4DGroupRegister;
+ function description (aValue : String ) : iSafety4DGroupRegister; overload;
+ function description : String; overload;
+ function key ( aValue : String ) : iSafety4DGroupRegister; overload;
+ function key : String; overload;
+ function actions : iSafety4DGroupActions;
+ function notActions : iSafety4DGroupNotActions;
+ function getGroupsRegisters : TDictionary;
+ function &end : iSafety4DGroup;
+ end;
+
+implementation
+
+uses
+ Safety4D.Groups.Actions,
+ Safety4D.Groups.NotActions,
+ Safety4D.Groups.ListActions,
+ System.SysUtils,
+ System.StrUtils;
+
+{ TSafety4DGroups }
+
+function TSafety4DGroupRegister.&end: iSafety4DGroup;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DGroupRegister.getGroupsRegisters: TDictionary;
+begin
+ Result := FList;
+end;
+
+function TSafety4DGroupRegister.key: String;
+begin
+ Result := FActions.key;
+end;
+
+function TSafety4DGroupRegister.key(aValue: String): iSafety4DGroupRegister;
+begin
+ Result := Self;
+ FActions.key(aValue);
+end;
+
+function TSafety4DGroupRegister.actions: iSafety4DGroupActions;
+begin
+ Result := FActions.actions;
+end;
+
+function TSafety4DGroupRegister.add(aRoleName: String): iSafety4DGroupRegister;
+var
+ aGuid : String;
+begin
+ aGuid := TGuid.NewGuid.ToString;
+ if ContainsText(aRoleName, '{') and ContainsText(aRoleName, '}') then
+ aGuid := aRoleName;
+
+ Result := Self;
+ FList.Add(aGuid, TSafety4DGroupsListActions.New(Self));
+ FActions := FList.Items[aGuid];
+ FActions.key(aRoleName);
+end;
+
+constructor TSafety4DGroupRegister.Create(aParent : iSafety4DGroup);
+begin
+ FParent := aParent;
+ FList := TDictionary.Create;
+end;
+
+function TSafety4DGroupRegister.description: String;
+begin
+ Result := FActions.description;
+end;
+
+function TSafety4DGroupRegister.description(
+ aValue: String): iSafety4DGroupRegister;
+begin
+ Result := FActions.description(aValue).&end;
+end;
+
+destructor TSafety4DGroupRegister.Destroy;
+begin
+ FList.DisposeOf;
+ inherited;
+end;
+
+class function TSafety4DGroupRegister.New(aParent : iSafety4DGroup) : iSafety4DGroupRegister;
+begin
+ Result := Self.Create(aParent);
+end;
+
+function TSafety4DGroupRegister.notActions: iSafety4DGroupNotActions;
+begin
+ Result := FActions.notActions;
+end;
+
+end.
diff --git a/src/Safety4D.Groups.pas b/src/Safety4D.Groups.pas
new file mode 100644
index 0000000..03d39fc
--- /dev/null
+++ b/src/Safety4D.Groups.pas
@@ -0,0 +1,116 @@
+unit Safety4D.Groups;
+
+interface
+
+uses
+ Safety4D.Interfaces, System.JSON;
+
+type
+ TSafety4DGroups = class(TInterfacedObject, iSafety4DGroup)
+ private
+ [weak]
+ FParent : iSafety4D;
+ FgroupRegister : iSafety4DGroupRegister;
+ public
+ constructor Create(aParent : iSafety4D);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4D) : iSafety4DGroup;
+ function groupRegister : iSafety4DGroupRegister;
+ function getGroups (var aJson : TJsonObject ) : iSafety4DGroup;
+ function getGroupPermission ( aValue : String ) : iSafety4DGroupListActions;
+ function &End : iSafety4D;
+ end;
+
+implementation
+
+uses
+ Safety4D.Groups.Register;
+
+{ TSafety4DGroups }
+
+function TSafety4DGroups.&end : iSafety4D;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DGroups.getGroupPermission(
+ aValue: String): iSafety4DGroupListActions;
+begin
+ FgroupRegister.getGroupsRegisters.TryGetValue(aValue, Result);
+end;
+
+function TSafety4DGroups.getGroups(
+ var aJson: TJsonObject): iSafety4DGroup;
+var
+ aJsonActions : TJsonArray;
+ aJsonGroups : TJsonObject;
+ aJsonGroup : TJsonObject;
+begin
+ Result := Self;
+ for var group in FgroupRegister.getGroupsRegisters do
+ begin
+ aJson.AddPair(group.Key, TJsonObject.Create);
+ aJsonGroup := aJson.GetValue(group.Key);
+ aJsonGroup
+ .AddPair('key', group.Value.key)
+ .AddPair('description', group.Value.description)
+ .AddPair('Actions', TJSONArray.Create)
+ .AddPair('NotActions', TJSONArray.Create);
+
+ for var Action in group.Value.actions.getActions do
+ begin
+ aJsonActions := aJsonGroup.GetValue('Actions');
+ aJsonActions.Add(Action);
+ end;
+
+ for var NotAction in group.Value.notActions.getNotActions do
+ begin
+ aJsonActions := aJsonGroup.GetValue('NotActions');
+ aJsonActions.Add(NotAction);
+ end;
+ end;
+// aJson
+// .AddPair('Key', FKey)
+// .AddPair('RoleName', FRoleName)
+// .AddPair('Description', FDescription)
+// .AddPair('Actions', TJSONArray.Create)
+// .AddPair('NotActions', TJSONArray.Create);
+
+// for var Action in FActions.getActions do
+// begin
+// aJsonActions := aJson.GetValue('Actions');
+// aJsonActions.Add(Action);
+// end;
+
+// for var NotAction in FNotActions.getNotActions do
+// begin
+// aJsonActions := aJson.GetValue('NotActions');
+// aJsonActions.Add(NotAction);
+// end;
+
+end;
+
+function TSafety4DGroups.groupRegister: iSafety4DGroupRegister;
+begin
+ if not Assigned(FgroupRegister) then
+ FgroupRegister := TSafety4DGroupRegister.New(Self);
+ Result := FgroupRegister;
+end;
+
+constructor TSafety4DGroups.Create(aParent : iSafety4D);
+begin
+ FParent := aParent;
+end;
+
+destructor TSafety4DGroups.Destroy;
+begin
+
+ inherited;
+end;
+
+class function TSafety4DGroups.New(aParent : iSafety4D): iSafety4DGroup;
+begin
+ Result := Self.Create(aParent);
+end;
+
+end.
diff --git a/src/Safety4D.Interfaces.pas b/src/Safety4D.Interfaces.pas
new file mode 100644
index 0000000..03ee417
--- /dev/null
+++ b/src/Safety4D.Interfaces.pas
@@ -0,0 +1,178 @@
+unit Safety4D.Interfaces;
+
+interface
+
+uses
+ System.Generics.Collections,
+ System.JSON;
+
+type
+ iSafety4DResourcesRegister = interface;
+ iSafety4DResourcesGroup = interface;
+ iSafety4DResourcesGroupProvider = interface;
+ iSafety4DResourcesGroupProviderActions = interface;
+ iSafety4DResources = interface;
+ iSafety4DResourcesGroupProviderActionsMsg = interface;
+ iSafety4DGroup = interface;
+ iSafety4DUserKey = interface;
+ iSafety4DValidation = interface;
+
+
+ iSafety4D = interface
+ ['{055941C3-EBA3-4D4E-ADB0-75C9FCE6DF18}']
+ function Validation : iSafety4DValidation;
+ function resources : iSafety4DResources;
+ function groupPermission : iSafety4DGroup;
+ function userKey : iSafety4DUserKey;
+ function getConfig (var aJson : TJsonObject ) : iSafety4D;
+ function SaveToStorage ( aPath : String = '' ) : iSafety4D;
+ function LoadConfig ( aJson : TJsonObject ) : iSafety4D;
+ end;
+
+ iSafety4DValidation = interface
+ ['{3EB75190-778C-4E0B-ABE7-A17A78103C5B}']
+ function userKey( aValue : String ) : iSafety4DValidation; overload;
+ function userKey : String; overload;
+ function resource ( aValue : String ) : iSafety4DValidation; overload;
+ function resource : string; overload;
+ function action ( aValue : String ) : iSafety4DValidation; overload;
+ function action : string; overload;
+ function application ( aValue : String ) : iSafety4DValidation; overload;
+ function application : string; overload;
+ function validate : boolean;
+ function &end : iSafety4D;
+ end;
+
+ {$region 'Resources'}
+
+ iSafety4DResources = interface
+ ['{B6BDB9F9-0E07-42C2-82BF-B3425CA2C3FA}']
+ function registerResources : iSafety4DResourcesRegister;
+ function getResource ( var aJson : TJsonObject ) : iSafety4DResources;
+ function exists ( aApplication : String; aResource : String; aAction : String ) : Boolean;
+ function &end : iSafety4D;
+ end;
+
+ iSafety4DResourcesRegister = interface
+ ['{11448984-3C63-45C5-8F8A-3B6D679B93A9}']
+ function resourcesGroupName : iSafety4DResourcesGroup;
+ function getResourceGroups : TDictionary;
+ function &end : iSafety4DResources;
+ end;
+
+ iSafety4DResourcesGroup = interface
+ ['{02F44B1B-3AEB-4DCB-BB60-6959EB46830D}']
+ function add ( aValue : String ) : iSafety4DResourcesGroup;
+ function providerName : iSafety4DResourcesGroupProvider;
+ function getResourcesGroupList : TDictionary;
+ function &end : iSafety4DResourcesRegister;
+ end;
+
+ iSafety4DResourcesGroupProvider = interface
+ ['{FB08025C-9831-4616-AFEE-22D40F25147D}']
+ function add(aValue : String) : iSafety4DResourcesGroupProvider;
+ function getProviderNames : TDictionary;
+ function actions : iSafety4DResourcesGroupProviderActions;
+ function &end : iSafety4DResourcesGroup;
+ end;
+
+ iSafety4DResourcesGroupProviderActions = interface
+ ['{94AAE52D-4317-4262-9E1A-DB04D8A95E68}']
+ function add(aValue : String) : iSafety4DResourcesGroupProviderActionsMsg;
+ function getActions : TDictionary;
+ function &end : iSafety4DResourcesGroupProvider;
+ end;
+
+ iSafety4DResourcesGroupProviderActionsMsg = interface
+ ['{36CAC0FD-138E-41CE-A483-3D2AE768AACD}']
+ function description( aValue : String ) : iSafety4DResourcesGroupProviderActionsMsg; overload;
+ function errormsg ( aValue : String ) : iSafety4DResourcesGroupProviderActionsMsg; overload;
+ function description : String; overload;
+ function errormsg : String; overload;
+ function &end : iSafety4DResourcesGroupProviderActions;
+ end;
+ {$endregion}
+
+ {$region 'Group'}
+ iSafety4DGroupActions = interface;
+ iSafety4DGroupNotActions = interface;
+ iSafety4DGroupRegister = interface;
+ iSafety4DGroupListActions = interface;
+
+ iSafety4DGroup = interface
+ ['{F3E9A643-5FA7-49FA-994A-430B7DDE9FBF}']
+ function groupRegister : iSafety4DGroupRegister;
+ function getGroups (var aJson : TJsonObject ) : iSafety4DGroup;
+ function getGroupPermission ( aValue : String ) : iSafety4DGroupListActions;
+ function &end : iSafety4D;
+ end;
+
+ iSafety4DGroupRegister = interface
+ function add ( aRoleName : String ) : iSafety4DGroupRegister;
+ function actions : iSafety4DGroupActions;
+ function notActions : iSafety4DGroupNotActions;
+ function key ( aValue : String ) : iSafety4DGroupRegister; overload;
+ function key : String; overload;
+ function description (aValue : String ) : iSafety4DGroupRegister; overload;
+ function description : String; overload;
+ function getGroupsRegisters : TDictionary;
+ function &end : iSafety4DGroup;
+ end;
+
+ iSafety4DGroupListActions = interface
+ function key ( aValue : String ) : iSafety4DGroupListActions; overload;
+ function key : string; overload;
+ function description ( aValue : String ) : iSafety4DGroupListActions; overload;
+ function description : String; overload;
+ function actions : iSafety4DGroupActions;
+ function notActions : iSafety4DGroupNotActions;
+ function &end : iSafety4DGroupRegister;
+ end;
+
+ iSafety4DGroupActions = interface
+ function add ( aValue : String ) : iSafety4DGroupActions;
+ function getActions : TList;
+ function &end : iSafety4DGroupRegister;
+ end;
+
+ iSafety4DGroupNotActions = interface
+ function add ( aValue : String ) : iSafety4DGroupNotActions;
+ function getNotActions : TList;
+ function &end : iSafety4DGroupRegister;
+ end;
+
+ {$endregion}
+
+ {$region 'userkey'}
+ iSafety4DUserKeyRegister = interface;
+ iSafety4DUserKeyRegisterGroupPermission = interface;
+
+ iSafety4DUserKey = interface
+ ['{89576374-693F-44F5-9B96-42DECA780927}']
+ function registerUserKey : iSafety4DUserKeyRegister;
+ function getUserKey (var aJson : TJsonObject ) : iSafety4DUserKey;
+ function getUserKeyPermissions (aUserKey : String) : TArray;
+ function exists ( aUserKey : String ) : Boolean;
+ function &end : iSafety4D;
+ end;
+
+ iSafety4DUserKeyRegister = interface
+ ['{ACA41435-459E-4394-849B-E260B7993068}']
+ function add ( aValue : String ) : iSafety4DUserKeyRegisterGroupPermission;
+ function GetUserKeyRegister : TDictionary;
+ function &end : iSafety4DUserKey;
+ end;
+
+ iSafety4DUserKeyRegisterGroupPermission = interface
+ ['{5D217EF2-579D-48AB-BCF9-432E68BFACD8}']
+ function description ( aValue : String ) : iSafety4DUserKeyRegisterGroupPermission; overload;
+ function description : String; overload;
+ function addPermission ( aValue : String ) : iSafety4DUserKeyRegisterGroupPermission;
+ function GetPermissions : TList;
+ function &end : iSafety4DUserKeyRegister;
+ end;
+ {$endregion}
+
+implementation
+
+end.
diff --git a/src/Safety4D.Resources.Group.Provider.Actions.Msg.pas b/src/Safety4D.Resources.Group.Provider.Actions.Msg.pas
new file mode 100644
index 0000000..d34ac83
--- /dev/null
+++ b/src/Safety4D.Resources.Group.Provider.Actions.Msg.pas
@@ -0,0 +1,74 @@
+unit Safety4D.Resources.Group.Provider.Actions.Msg;
+
+interface
+
+uses
+ Safety4D.Interfaces;
+
+type
+ TSafety4DResourcesGroupProviderActionsMsg = class(TInterfacedObject, iSafety4DResourcesGroupProviderActionsMsg)
+ private
+ [weak]
+ FParent : iSafety4DResourcesGroupProviderActions;
+ FDescription : String;
+ FErrorMsg : String;
+ public
+ constructor Create(aParent : iSafety4DResourcesGroupProviderActions);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4DResourcesGroupProviderActions) : iSafety4DResourcesGroupProviderActionsMsg;
+ function description( aValue : String ) : iSafety4DResourcesGroupProviderActionsMsg; overload;
+ function errormsg ( aValue : String ) : iSafety4DResourcesGroupProviderActionsMsg; overload;
+ function description : String; overload;
+ function errormsg : String; overload;
+ function &End : iSafety4DResourcesGroupProviderActions;
+ end;
+
+implementation
+
+{ TSafety4DResourcesGroupProviderActionsMsg }
+
+function TSafety4DResourcesGroupProviderActionsMsg.&end : iSafety4DResourcesGroupProviderActions;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DResourcesGroupProviderActionsMsg.errormsg: String;
+begin
+ Result := FErrorMsg;
+end;
+
+function TSafety4DResourcesGroupProviderActionsMsg.errormsg(aValue: String): iSafety4DResourcesGroupProviderActionsMsg;
+begin
+ Result := Self;
+ FErrorMsg := aValue;
+end;
+
+constructor TSafety4DResourcesGroupProviderActionsMsg.Create(aParent : iSafety4DResourcesGroupProviderActions);
+begin
+ FParent := aParent;
+end;
+
+function TSafety4DResourcesGroupProviderActionsMsg.description(
+ aValue: String): iSafety4DResourcesGroupProviderActionsMsg;
+begin
+ Result := Self;
+ FDescription := aValue;
+end;
+
+function TSafety4DResourcesGroupProviderActionsMsg.description: String;
+begin
+ Result := FDescription;
+end;
+
+destructor TSafety4DResourcesGroupProviderActionsMsg.Destroy;
+begin
+
+ inherited;
+end;
+
+class function TSafety4DResourcesGroupProviderActionsMsg.New(aParent : iSafety4DResourcesGroupProviderActions): iSafety4DResourcesGroupProviderActionsMsg;
+begin
+ Result := Self.Create(aParent);
+end;
+
+end.
diff --git a/src/Safety4D.Resources.Group.Provider.Actions.pas b/src/Safety4D.Resources.Group.Provider.Actions.pas
new file mode 100644
index 0000000..e509505
--- /dev/null
+++ b/src/Safety4D.Resources.Group.Provider.Actions.pas
@@ -0,0 +1,66 @@
+unit Safety4D.Resources.Group.Provider.Actions;
+
+interface
+
+uses
+ Safety4D.Interfaces,
+ System.Generics.Collections;
+
+type
+ TSafety4DResourcesGroupProviderActions = class(TInterfacedObject, iSafety4DResourcesGroupProviderActions)
+ private
+ [weak]
+ FParent : iSafety4DResourcesGroupProvider;
+ FActionList : TDictionary;
+ FActionsMsg : iSafety4DResourcesGroupProviderActionsMsg;
+ public
+ constructor Create(aParent : iSafety4DResourcesGroupProvider);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4DResourcesGroupProvider) : iSafety4DResourcesGroupProviderActions;
+ function add(aValue : String) : iSafety4DResourcesGroupProviderActionsMsg;
+ function getActions : TDictionary;
+ function &end : iSafety4DResourcesGroupProvider;
+ end;
+
+implementation
+
+uses
+ Safety4D.Resources.Group.Provider.Actions.Msg;
+
+{ TSafety4DProviderName }
+
+function TSafety4DResourcesGroupProviderActions.&end: iSafety4DResourcesGroupProvider;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DResourcesGroupProviderActions.getActions: TDictionary;
+begin
+ Result := FActionList;
+end;
+
+function TSafety4DResourcesGroupProviderActions.add(
+ aValue: String): iSafety4DResourcesGroupProviderActionsMsg;
+begin
+ FActionList.Add(aValue, TSafety4DResourcesGroupProviderActionsMsg.New(Self));
+ Result := FActionList.Items[aValue];
+end;
+
+constructor TSafety4DResourcesGroupProviderActions.Create(aParent : iSafety4DResourcesGroupProvider);
+begin
+ FParent := aParent;
+ FActionList := TDictionary.Create;
+end;
+
+destructor TSafety4DResourcesGroupProviderActions.Destroy;
+begin
+ FActionList.DisposeOf;
+ inherited;
+end;
+
+class function TSafety4DResourcesGroupProviderActions.New(aParent : iSafety4DResourcesGroupProvider): iSafety4DResourcesGroupProviderActions;
+begin
+ Result := Self.Create(aParent);
+end;
+
+end.
diff --git a/src/Safety4D.Resources.Group.Provider.pas b/src/Safety4D.Resources.Group.Provider.pas
new file mode 100644
index 0000000..06617fb
--- /dev/null
+++ b/src/Safety4D.Resources.Group.Provider.pas
@@ -0,0 +1,79 @@
+unit Safety4D.Resources.Group.Provider;
+
+interface
+
+uses
+ System.Generics.Collections,
+ Safety4D.Interfaces;
+
+type
+ TSafety4DResourcesGroupProvider = class(TInterfacedObject, iSafety4DResourcesGroupProvider)
+ private
+ [weak]
+ FParent : iSafety4DResourcesGroup;
+ FProviderName : String;
+ FProviderNameList : TDictionary;
+ public
+ constructor Create(aParent : iSafety4DResourcesGroup);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4DResourcesGroup) : iSafety4DResourcesGroupProvider;
+ function add(aValue : String) : iSafety4DResourcesGroupProvider;
+ function getProviderNames : TDictionary;
+ function actions : iSafety4DResourcesGroupProviderActions;
+ function &End : iSafety4DResourcesGroup;
+ end;
+
+implementation
+
+uses
+ Safety4D.Resources.Group.Provider.Actions;
+
+{ TSafety4DProviderName }
+
+function TSafety4DResourcesGroupProvider.&end : iSafety4DResourcesGroup;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DResourcesGroupProvider.getProviderNames: TDictionary;
+begin
+ Result := FProviderNameList;
+end;
+
+function TSafety4DResourcesGroupProvider.actions: iSafety4DResourcesGroupProviderActions;
+begin
+ Result := FProviderNameList.Items[FProviderName];
+end;
+
+function TSafety4DResourcesGroupProvider.add(aValue: String): iSafety4DResourcesGroupProvider;
+begin
+ Result := Self;
+ FProviderName := aValue;
+ FProviderNameList.Add(aValue, TSafety4DResourcesGroupProviderActions.New(Self));
+// FProviderNameList
+// .Items[aValue]
+// .add('*')
+// .add('read')
+// .add('write')
+// .add('delete')
+// .add('view');
+end;
+
+constructor TSafety4DResourcesGroupProvider.Create(aParent : iSafety4DResourcesGroup);
+begin
+ FParent := aParent;
+ FProviderNameList := TDictionary.Create;
+end;
+
+destructor TSafety4DResourcesGroupProvider.Destroy;
+begin
+ FProviderNameList.DisposeOf;
+ inherited;
+end;
+
+class function TSafety4DResourcesGroupProvider.New(aParent : iSafety4DResourcesGroup): iSafety4DResourcesGroupProvider;
+begin
+ Result := Self.Create(aParent);
+end;
+
+end.
diff --git a/src/Safety4D.Resources.Group.pas b/src/Safety4D.Resources.Group.pas
new file mode 100644
index 0000000..3fd9a35
--- /dev/null
+++ b/src/Safety4D.Resources.Group.pas
@@ -0,0 +1,73 @@
+unit Safety4D.Resources.Group;
+
+interface
+
+uses
+ System.Generics.Collections,
+ Safety4D.Interfaces;
+
+type
+ TSafety4DResourcesGroup = class(TInterfacedObject, iSafety4DResourcesGroup)
+ private
+ [weak]
+ FParent : iSafety4DResourcesRegister;
+ FResourceGroup : String;
+ FResourceGroupNameList : TDictionary;
+ public
+ constructor Create(aParent : iSafety4DResourcesRegister);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4DResourcesRegister) : iSafety4DResourcesGroup;
+ function add ( aValue : String ) : iSafety4DResourcesGroup;
+ function getResourcesGroupList : TDictionary;
+ function providerName : iSafety4DResourcesGroupProvider;
+ function &end : iSafety4DResourcesRegister;
+ end;
+
+implementation
+
+{ TSafety4DResourcesGrupName }
+
+uses
+ Safety4D.Resources.Group.Provider;
+
+function TSafety4DResourcesGroup.&end : iSafety4DResourcesRegister;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DResourcesGroup.getResourcesGroupList: TDictionary;
+begin
+ Result := FResourceGroupNameList;
+end;
+
+function TSafety4DResourcesGroup.add(
+ aValue: String): iSafety4DResourcesGroup;
+begin
+ Result := Self;
+ FResourceGroup := aValue;
+ FResourceGroupNameList.Add(aValue, TSafety4DResourcesGroupProvider.New(Self));
+end;
+
+constructor TSafety4DResourcesGroup.Create(aParent : iSafety4DResourcesRegister);
+begin
+ FParent := aParent;
+ FResourceGroupNameList := TDictionary.Create;
+end;
+
+destructor TSafety4DResourcesGroup.Destroy;
+begin
+ FResourceGroupNameList.DisposeOf;
+ inherited;
+end;
+
+class function TSafety4DResourcesGroup.New(aParent : iSafety4DResourcesRegister): iSafety4DResourcesGroup;
+begin
+ Result := Self.Create(aParent);
+end;
+
+function TSafety4DResourcesGroup.providerName: iSafety4DResourcesGroupProvider;
+begin
+ Result := FResourceGroupNameList.Items[FResourceGroup];
+end;
+
+end.
diff --git a/src/Safety4D.Resources.Register.pas b/src/Safety4D.Resources.Register.pas
new file mode 100644
index 0000000..343e5df
--- /dev/null
+++ b/src/Safety4D.Resources.Register.pas
@@ -0,0 +1,65 @@
+unit Safety4D.Resources.Register;
+
+interface
+
+uses
+ System.Generics.Collections,
+ Safety4D.Interfaces;
+
+type
+ TSafety4DResourcesRegister = class(TInterfacedObject, iSafety4DResourcesRegister)
+ private
+ [weak]
+ FParent : iSafety4DResources;
+ FResourceGroupName : iSafety4DResourcesGroup;
+ public
+ constructor Create(aParent : iSafety4DResources);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4DResources) : iSafety4DResourcesRegister;
+ function resourcesGroupName : iSafety4DResourcesGroup;
+ function getResourceGroups : TDictionary;
+ function &End : iSafety4DResources;
+ end;
+
+implementation
+
+uses
+ Safety4D.Resources.Group;
+
+{ TSafety4DRegisterResources }
+
+function TSafety4DResourcesRegister.&end : iSafety4DResources;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DResourcesRegister.getResourceGroups: TDictionary;
+begin
+ Result := FResourceGroupName.getResourcesGroupList;
+end;
+
+constructor TSafety4DResourcesRegister.Create(aParent : iSafety4DResources);
+begin
+ FParent := aParent;
+end;
+
+destructor TSafety4DResourcesRegister.Destroy;
+begin
+
+ inherited;
+end;
+
+class function TSafety4DResourcesRegister.New(aParent : iSafety4DResources) : iSafety4DResourcesRegister;
+begin
+ Result := Self.Create(aParent);
+end;
+
+function TSafety4DResourcesRegister.resourcesGroupName: iSafety4DResourcesGroup;
+begin
+ if not assigned(FResourceGroupName) then
+ FResourceGroupName := TSafety4DResourcesGroup.New(Self);
+
+ Result := FResourceGroupName;
+end;
+
+end.
diff --git a/src/Safety4D.Resources.pas b/src/Safety4D.Resources.pas
new file mode 100644
index 0000000..5fd3f56
--- /dev/null
+++ b/src/Safety4D.Resources.pas
@@ -0,0 +1,110 @@
+unit Safety4D.Resources;
+
+interface
+
+uses
+ System.JSON,
+ Safety4D.Interfaces;
+
+type
+ TSafety4DResources = class(TInterfacedObject, iSafety4DResources)
+ private
+ [weak]
+ FParent : iSafety4D;
+ FRegisterResources : iSafety4DResourcesRegister;
+ public
+ constructor Create(aParent : iSafety4D);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4D) : iSafety4DResources;
+ function registerResources : iSafety4DResourcesRegister;
+ function getResource ( var aJson : TJsonObject ) : iSafety4DResources;
+ function exists ( aApplication : String; aResource : String; aAction : String ) : Boolean;
+ function &End : iSafety4D;
+ end;
+
+implementation
+
+uses
+ Safety4D.Resources.Register, System.SysUtils;
+
+{ TSafety4DResources }
+
+function TSafety4DResources.&end : iSafety4D;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DResources.exists( aApplication : String; aResource : String; aAction : String ) : Boolean;
+var
+ iResource : iSafety4DResourcesGroupProvider;
+ iResourceActions : iSafety4DResourcesGroupProviderActions;
+ iActionMessage : iSafety4DResourcesGroupProviderActionsMsg;
+begin
+ Result := False;
+
+ if not FRegisterResources.getResourceGroups.TryGetValue(aApplication, iResource) then
+ raise Exception.Create('Unregistered Application');
+
+ if not iResource.getProviderNames.TryGetValue(aResource, iResourceActions) then
+ raise Exception.Create('Unregistered resource');
+
+ if not iResourceActions.getActions.TryGetValue(aAction, iActionMessage) then
+ raise Exception.Create('unregistered action');
+end;
+
+function TSafety4DResources.getResource(
+ var aJson: TJsonObject): iSafety4DResources;
+var
+ aJsonResources : TJsonObject;
+ aJsonGroup : TJsonObject;
+ aJsonProvider : TJsonObject;
+ aJsonActions : TJsonObject;
+begin
+ Result := Self;
+ //aJson.AddPair('resources', TJSONArray.Create.Add(TJSONObject.Create));
+ for var Resource in FRegisterResources.getResourceGroups do
+ begin
+ //aJsonResources := (aJson.GetValue('resources').Items[0] as TJsonObject);
+ aJson.AddPair(Resource.Key, TJSONObject.Create);
+ for var Provider in Resource.Value.getProviderNames do
+ begin
+ aJsonGroup := aJson.GetValue(Resource.Key);
+ aJsonGroup.AddPair(Provider.Key, TJSONObject.Create);
+ aJsonProvider := aJsonGroup.GetValue(Provider.Key);
+ aJsonProvider.AddPair('actions', TJSONObject.Create);
+ for var Action in Provider.Value.getActions do
+ begin
+ aJsonActions := aJsonProvider.GetValue('actions');
+ aJsonActions.AddPair(Action.Key, TJsonObject.Create);
+ aJsonActions.GetValue(Action.Key).AddPair('description', Action.Value.description);
+ aJsonActions.GetValue(Action.Key).AddPair('errormsg', Action.Value.errormsg);
+ end;
+ end;
+ end;
+end;
+
+constructor TSafety4DResources.Create(aParent : iSafety4D);
+begin
+ FParent := aParent;
+end;
+
+destructor TSafety4DResources.Destroy;
+begin
+
+ inherited;
+end;
+
+class function TSafety4DResources.New(aParent : iSafety4D): iSafety4DResources;
+begin
+ Result := Self.Create(aParent);
+end;
+
+function TSafety4DResources.registerResources: iSafety4DResourcesRegister;
+begin
+ if not assigned(FRegisterResources) then
+ FRegisterResources := TSafety4DResourcesRegister.New(Self);
+
+ Result := FRegisterResources;
+end;
+
+end.
diff --git a/src/Safety4D.UserKey.Register.PermissionGroup.pas b/src/Safety4D.UserKey.Register.PermissionGroup.pas
new file mode 100644
index 0000000..1d32180
--- /dev/null
+++ b/src/Safety4D.UserKey.Register.PermissionGroup.pas
@@ -0,0 +1,77 @@
+unit Safety4D.UserKey.Register.PermissionGroup;
+
+interface
+
+uses
+ System.Generics.Collections,
+ Safety4D.Interfaces;
+
+type
+ TSafety4DUserKeyRegisterPermissionGroup = class(TInterfacedObject, iSafety4DUserKeyRegisterGroupPermission)
+ private
+ [weak]
+ FParent : iSafety4DUserKeyRegister;
+ FList : TList;
+ FDescription : String;
+ public
+ constructor Create(aParent : iSafety4DUserKeyRegister);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4DUserKeyRegister) : iSafety4DUserKeyRegisterGroupPermission;
+ function addPermission ( aValue : String ) : iSafety4DUserKeyRegisterGroupPermission;
+ function description ( aValue : String ) : iSafety4DUserKeyRegisterGroupPermission; overload;
+ function description : String; overload;
+ function GetPermissions : TList;
+ function &End : iSafety4DUserKeyRegister;
+ end;
+
+implementation
+
+{ TSafety4DUserKeyRegisterPermissionGroup }
+
+function TSafety4DUserKeyRegisterPermissionGroup.&end : iSafety4DUserKeyRegister;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DUserKeyRegisterPermissionGroup.GetPermissions: TList;
+begin
+ Result := FList;
+end;
+
+function TSafety4DUserKeyRegisterPermissionGroup.addPermission(
+ aValue: String): iSafety4DUserKeyRegisterGroupPermission;
+begin
+ Result := Self;
+ FList.Add(aValue);
+end;
+
+constructor TSafety4DUserKeyRegisterPermissionGroup.Create(aParent : iSafety4DUserKeyRegister);
+begin
+ FParent := aParent;
+ FList := TList.Create;
+end;
+
+function TSafety4DUserKeyRegisterPermissionGroup.description: String;
+begin
+ Result := FDescription;
+end;
+
+function TSafety4DUserKeyRegisterPermissionGroup.description(
+ aValue: String): iSafety4DUserKeyRegisterGroupPermission;
+begin
+ Result := Self;
+ FDescription := aValue;
+end;
+
+destructor TSafety4DUserKeyRegisterPermissionGroup.Destroy;
+begin
+ FList.DisposeOf;
+ inherited;
+end;
+
+class function TSafety4DUserKeyRegisterPermissionGroup.New(aParent : iSafety4DUserKeyRegister): iSafety4DUserKeyRegisterGroupPermission;
+begin
+ Result := Self.Create(aParent);
+end;
+
+end.
diff --git a/src/Safety4D.UserKey.Register.pas b/src/Safety4D.UserKey.Register.pas
new file mode 100644
index 0000000..278959b
--- /dev/null
+++ b/src/Safety4D.UserKey.Register.pas
@@ -0,0 +1,74 @@
+unit Safety4D.UserKey.Register;
+
+interface
+
+uses
+ System.Generics.Collections,
+ Safety4D.Interfaces;
+
+type
+ TSafety4DUserKeyRegister = class(TInterfacedObject, iSafety4DUserKeyRegister)
+ private
+ [weak]
+ FParent : iSafety4DUserKey;
+ FList : TDictionary;
+ public
+ constructor Create(aParent : iSafety4DUserKey);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4DUserKey) : iSafety4DUserKeyRegister;
+ function GetUserKeyRegister : TDictionary;
+ function add ( aValue : String ) : iSafety4DUserKeyRegisterGroupPermission;
+ function &End : iSafety4DUserKey;
+ end;
+
+implementation
+
+uses
+ Safety4D.UserKey.Register.PermissionGroup,
+ System.SysUtils,
+ System.StrUtils;
+
+{ TSafety4DUserKeyRegister }
+
+function TSafety4DUserKeyRegister.&end : iSafety4DUserKey;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DUserKeyRegister.GetUserKeyRegister: TDictionary;
+begin
+ Result := FList;
+end;
+
+function TSafety4DUserKeyRegister.add(
+ aValue: String): iSafety4DUserKeyRegisterGroupPermission;
+var
+ aGuid : String;
+begin
+ aGuid := TGuid.NewGuid.ToString;
+
+ if ContainsText(aValue, '{') and ContainsText(aValue, '}') then
+ aGuid := aValue;
+
+ FList.Add(aGuid, TSafety4DUserKeyRegisterPermissionGroup.New(Self));
+ Result := FList.Items[aGuid].description(aValue);
+end;
+
+constructor TSafety4DUserKeyRegister.Create(aParent : iSafety4DUserKey);
+begin
+ FParent := aParent;
+ FList := TDictionary.Create;
+end;
+
+destructor TSafety4DUserKeyRegister.Destroy;
+begin
+ FList.DisposeOf;
+ inherited;
+end;
+
+class function TSafety4DUserKeyRegister.New(aParent : iSafety4DUserKey): iSafety4DUserKeyRegister;
+begin
+ Result := Self.Create(aParent);
+end;
+
+end.
diff --git a/src/Safety4D.UserKey.pas b/src/Safety4D.UserKey.pas
new file mode 100644
index 0000000..c125d0f
--- /dev/null
+++ b/src/Safety4D.UserKey.pas
@@ -0,0 +1,99 @@
+unit Safety4D.UserKey;
+
+interface
+
+uses
+ Safety4D.Interfaces, System.JSON;
+
+type
+ TSafety4DUserKey = class(TInterfacedObject, iSafety4DUserKey)
+ private
+ [weak]
+ FParent : iSafety4D;
+ FRegisterUserKey : iSafety4DUserKeyRegister;
+ public
+ constructor Create(aParent : iSafety4D);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4D) : iSafety4DUserKey;
+ function registerUserKey : iSafety4DUserKeyRegister;
+ function getUserKey (var aJson : TJsonObject ) : iSafety4DUserKey;
+ function exists ( aUserKey : String ) : Boolean;
+ function getUserKeyPermissions(aUserKey : String) : TArray;
+ function &End : iSafety4D;
+ end;
+
+implementation
+
+uses
+ Safety4D.UserKey.Register, System.SysUtils;
+
+{ TSafety4DUserKey }
+
+function TSafety4DUserKey.&end : iSafety4D;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DUserKey.exists(aUserKey: String): Boolean;
+var
+ iUser : iSafety4DUserKeyRegisterGroupPermission;
+begin
+ if not FRegisterUserKey.GetUserKeyRegister.TryGetValue(aUserKey, iUser) then
+ raise Exception.Create('User key not registered');
+end;
+
+function TSafety4DUserKey.getUserKey(var aJson: TJsonObject): iSafety4DUserKey;
+var
+ aJsonRegister : TJsonObject;
+ aJsonPermission : TJsonArray;
+begin
+ for var userRegister in FRegisterUserKey.GetUserKeyRegister do
+ begin
+ aJson.AddPair(userRegister.Key, TJsonObject.Create);
+ aJsonRegister := aJson.GetValue(userRegister.Key);
+ aJsonRegister.AddPair('description', userRegister.Value.description);
+ aJsonRegister.AddPair('permissionGroups', TJsonArray.Create);
+
+ for var Permission in userRegister.Value.GetPermissions do
+ begin
+ aJsonPermission := aJsonRegister.GetValue('permissionGroups');
+ aJsonPermission.Add(Permission);
+ end;
+
+ end;
+
+end;
+
+function TSafety4DUserKey.getUserKeyPermissions(aUserKey : String): TArray;
+var
+ iUserPermitions : iSafety4DUserKeyRegisterGroupPermission;
+begin
+ if FRegisterUserKey.GetUserKeyRegister.TryGetValue(aUserKey, iUserPermitions) then
+ Result := iUserPermitions.GetPermissions.ToArray;
+end;
+
+constructor TSafety4DUserKey.Create(aParent : iSafety4D);
+begin
+ FParent := aParent;
+end;
+
+destructor TSafety4DUserKey.Destroy;
+begin
+
+ inherited;
+end;
+
+class function TSafety4DUserKey.New(aParent : iSafety4D): iSafety4DUserKey;
+begin
+ Result := Self.Create(aParent);
+end;
+
+function TSafety4DUserKey.registerUserKey: iSafety4DUserKeyRegister;
+begin
+ if not Assigned(FRegisterUserKey) then
+ FRegisterUserKey := TSafety4DUserKeyRegister.New(Self);
+
+ Result := FRegisterUserKey;
+end;
+
+end.
diff --git a/src/Safety4D.Validation.pas b/src/Safety4D.Validation.pas
new file mode 100644
index 0000000..f690cdb
--- /dev/null
+++ b/src/Safety4D.Validation.pas
@@ -0,0 +1,154 @@
+unit Safety4D.Validation;
+
+interface
+
+uses
+ Safety4D.Interfaces;
+
+type
+ TSafety4DValidation = class(TInterfacedObject, iSafety4DValidation)
+ private
+ [weak]
+ FParent : iSafety4D;
+ FuserKey : String;
+ FResource : String;
+ FAction : String;
+ FApplication : String;
+ public
+ constructor Create(aParent : iSafety4D);
+ destructor Destroy; override;
+ class function New(aParent : iSafety4D) : iSafety4DValidation;
+ function userKey( aValue : String ) : iSafety4DValidation; overload;
+ function userKey : String; overload;
+ function resource ( aValue : String ) : iSafety4DValidation; overload;
+ function resource : string; overload;
+ function action ( aValue : String ) : iSafety4DValidation; overload;
+ function action : string; overload;
+ function application ( aValue : String ) : iSafety4DValidation; overload;
+ function application : string; overload;
+ function validate : boolean;
+ function &End : iSafety4D;
+ end;
+
+implementation
+
+uses
+ System.SysUtils;
+
+{ TSafety4DValidation }
+
+function TSafety4DValidation.&end : iSafety4D;
+begin
+ Result := FParent;
+end;
+
+function TSafety4DValidation.action(aValue: String): iSafety4DValidation;
+begin
+ Result := Self;
+ FAction := aValue;
+end;
+
+function TSafety4DValidation.action: string;
+begin
+ Result := FAction;
+end;
+
+function TSafety4DValidation.application: string;
+begin
+ Result := FApplication;
+end;
+
+function TSafety4DValidation.application(aValue: String): iSafety4DValidation;
+begin
+ Result := Self;
+ FApplication := aValue;
+end;
+
+constructor TSafety4DValidation.Create(aParent : iSafety4D);
+begin
+ FParent := aParent;
+end;
+
+destructor TSafety4DValidation.Destroy;
+begin
+
+ inherited;
+end;
+
+class function TSafety4DValidation.New(aParent : iSafety4D): iSafety4DValidation;
+begin
+ Result := Self.Create(aParent);
+end;
+
+function TSafety4DValidation.resource: string;
+begin
+ Result := FResource;
+end;
+
+function TSafety4DValidation.resource(aValue: String): iSafety4DValidation;
+begin
+ Result := Self;
+ FResource := aValue;
+end;
+
+function TSafety4DValidation.userKey(aValue: String): iSafety4DValidation;
+begin
+ Result := Self;
+ FuserKey := aValue;
+end;
+
+function TSafety4DValidation.userKey: String;
+begin
+ Result := FuserKey;
+end;
+
+function TSafety4DValidation.validate: boolean;
+var
+ aTeste : String;
+ FAllAcess : Boolean;
+ FAllBlock : Boolean;
+ iGroupPermission : iSafety4DGroupListActions;
+begin
+ Result := False;
+ FAllAcess := False;
+ FAllBlock := False;
+ try
+ FParent.resources.exists(FApplication, FResource, FAction);
+ FParent.userKey.exists(FuserKey);
+
+ for var UserPermission in FParent.userKey.getUserKeyPermissions(FuserKey) do
+ begin
+ aTeste := UserPermission;
+ iGroupPermission := FParent.groupPermission.getGroupPermission(UserPermission);
+
+ for var aAction in iGroupPermission.actions.getActions do
+ begin
+ if UpperCase(aAction) = UpperCase(FResource+'.'+FAction) then
+ begin
+ Result := True;
+ exit;
+ end;
+
+ if aAction = '*' then
+ FAllAcess := True;
+ end;
+
+ for var aNotAction in iGroupPermission.notActions.getNotActions do
+ begin
+ if UpperCase(aNotAction) = UpperCase(FResource+'.'+FAction) then
+ raise Exception.Create('Access not allowed to these resources');
+
+ if aNotAction = '*' then
+ FAllBlock := True;
+ end;
+
+ if not Result and FAllAcess then Result := FAllAcess;
+ if not Result and FAllBlock then
+ raise Exception.Create('Access not allowed to these resources');
+ end;
+ except on e : Exception do
+ raise Exception.Create(e.Message);
+ end;
+end;
+
+end.
diff --git a/src/Safety4D.pas b/src/Safety4D.pas
new file mode 100644
index 0000000..02a6353
--- /dev/null
+++ b/src/Safety4D.pas
@@ -0,0 +1,262 @@
+unit Safety4D;
+
+interface
+
+uses
+ Safety4D.Interfaces, System.JSON;
+
+type
+ TSafety4D = class(TInterfacedObject, iSafety4D)
+ private
+ FResources : iSafety4DResources;
+ FGroupPermission : iSafety4DGroup;
+ FuserKey : iSafety4DUserKey;
+ FValidation : iSafety4DValidation;
+ procedure __loadResourcesJson(var aJson : TJsonObject);
+ procedure __loadGroupPermissionJson(var aJson : TJsonObject);
+ procedure __loadUserKeysJson(var aJson : TJsonObject);
+ public
+ constructor Create;
+ destructor Destroy; override;
+ class function New : iSafety4D;
+ function Validation : iSafety4DValidation;
+ function resources : iSafety4DResources;
+ function groupPermission : iSafety4DGroup;
+ function userKey : iSafety4DUserKey;
+ function getConfig (var aJson : TJsonObject ) : iSafety4D;
+ function SaveToStorage ( aPath : String = '' ) : iSafety4D;
+ function LoadConfig ( aJson : TJsonObject ) : iSafety4D;
+ end;
+
+var
+ vSafety4D : iSafety4D;
+
+implementation
+
+uses
+ Safety4D.Resources.Register,
+ Safety4D.Resources,
+ Safety4D.Groups,
+ Safety4D.UserKey,
+ System.SysUtils,
+ System.Classes,
+ Rest.Json, Safety4D.Validation;
+
+{ TSafety4D }
+
+constructor TSafety4D.Create;
+begin
+
+end;
+
+destructor TSafety4D.Destroy;
+begin
+
+ inherited;
+end;
+
+function TSafety4D.getConfig(var aJson: TJsonObject): iSafety4D;
+var
+ aResource, aGroup, aUser : TJsonObject;
+begin
+ Result := Self;
+ aJson
+ .AddPair('resources', TJSONObject.Create)
+ .AddPair('groupPermission', TJSONObject.Create)
+ .AddPair('userKeys', TJSONObject.Create);
+ aResource := aJson.GetValue('resources');
+ aGroup := aJson.GetValue('groupPermission');
+ aUser := aJson.GetValue('userKeys');
+ FResources.getResource(aResource);
+ FGroupPermission.getGroups(aGroup);
+ FuserKey.getUserKey(aUser);
+end;
+
+function TSafety4D.groupPermission: iSafety4DGroup;
+begin
+ if not Assigned(FGroupPermission) then
+ FGroupPermission := TSafety4DGroups.New(self);
+
+ Result := FGroupPermission;
+end;
+
+function TSafety4D.LoadConfig(aJson: TJsonObject): iSafety4D;
+var
+ aJsonResources : TJsonObject;
+ aJsonGroupPermission : TJsonObject;
+ aJsonUserKeys : TJsonObject;
+ aTeste: string;
+begin
+ aTeste := aJson.ToString;
+ if aJson.TryGetValue('resources', aJsonResources) then
+ __loadResourcesJson(aJsonResources);
+
+ if aJson.TryGetValue('groupPermission', aJsonGroupPermission) then
+ __loadGroupPermissionJson(aJsonGroupPermission);
+
+ if aJson.TryGetValue('userKeys', aJsonUserKeys) then
+ __loadUserKeysJson(aJsonUserKeys);
+end;
+
+class function TSafety4D.New: iSafety4D;
+begin
+ if not Assigned(vSafety4D) then
+ vSafety4D := Self.Create;
+
+ Result := vSafety4D;
+end;
+
+function TSafety4D.resources: iSafety4DResources;
+begin
+ if not Assigned(FResources) then
+ FResources := TSafety4DResources.New(Self);
+
+ Result := FResources;
+end;
+
+function TSafety4D.SaveToStorage(aPath: String): iSafety4D;
+var
+ aJsonResult : TJsonObject;
+ StrList : TStringList;
+begin
+ if Trim(aPath) = '' then
+ aPath := ChangeFileExt(ParamStr(0), '.s4d');
+ aJsonResult := TJsonObject.Create;
+ StrList := TStringList.Create;
+ try
+ Self.getConfig(aJsonResult);
+ StrList.Add(TJson.Format(aJsonResult));
+ StrList.SaveToFile(aPath);
+ finally
+ StrList.DisposeOf;
+ aJsonResult.DisposeOf;
+ end;
+end;
+
+function TSafety4D.userKey: iSafety4DUserKey;
+begin
+ if not assigned(FuserKey) then
+ FuserKey := TSafety4DUserKey.New(Self);
+
+ Result := FuserKey;
+end;
+
+function TSafety4D.Validation: iSafety4DValidation;
+begin
+ if not Assigned(FValidation) then
+ FValidation := TSafety4DValidation.New(Self);
+
+ Result := FValidation;
+end;
+
+procedure TSafety4D.__loadGroupPermissionJson(var aJson: TJsonObject);
+var
+ I : Integer;
+ FGroupName : String;
+ aJsonGroup : TJsonObject;
+ iAction : iSafety4DGroupActions;
+ iNotAction : iSafety4DGroupNotActions;
+ aJsonActions : TJsonArray;
+ aJsonNotActions : TJsonArray;
+ X: Integer;
+begin
+ for I := 0 to Pred(aJson.Count) do
+ begin
+ FGroupName := aJson.Get(I).JsonString.Value;
+ aJsonGroup := aJson.Get(I).JsonValue as TJsonObject;
+ aJsonActions := aJsonGroup.GetValue('Actions');
+ aJsonNotActions := aJsonGroup.GetValue('NotActions');
+
+ iAction :=
+ groupPermission
+ .groupRegister
+ .add(FGroupName)
+ .description(aJsonGroup.GetValue('description'))
+ .key(aJsonGroup.GetValue('key'))
+ .actions;
+
+ for X := 0 to Pred(aJsonActions.Count) do
+ begin
+ iAction.add(aJsonActions.Get(X).Value);
+ end;
+
+ iNotAction := iAction.&end.notActions;
+
+ for X := 0 to Pred(aJsonNotActions.Count) do
+ begin
+ iNotAction.add(aJsonNotActions.Get(X).Value);
+ end;
+ end;
+end;
+
+procedure TSafety4D.__loadResourcesJson(var aJson : TJsonObject);
+var
+ I: Integer;
+ FGroupName: string;
+ FProviderName : String;
+ aJsonGroup : TJsonObject;
+ aJsonProvider : TJsonObject;
+ aJsonActions : TJsonObject;
+ J: Integer;
+ iProviderAction : iSafety4DResourcesGroupProviderActions;
+ K: Integer;
+begin
+ for I := 0 to Pred(aJson.Count) do
+ begin
+ FGroupName := aJson.Get(I).JsonString.Value;
+ aJsonGroup := aJson.Get(I).JsonValue as TJSONObject;
+ for J := 0 to Pred(aJsonGroup.Count) do
+ begin
+ FProviderName := aJsonGroup.Get(J).JsonString.Value;
+ aJsonProvider := aJsonGroup.Get(I).JsonValue as TJSONObject;
+ aJsonActions := aJsonProvider.GetValue('actions');
+
+ iProviderAction :=
+ resources
+ .registerResources
+ .resourcesGroupName
+ .add(FGroupName)
+ .providerName
+ .add(FProviderName)
+ .actions;
+
+ for K := 0 to Pred(aJsonActions.Count) do
+ begin
+ iProviderAction
+ .add(aJsonActions.Get(K).JsonString.Value)
+ .description(aJsonActions.Get(K).JsonValue.GetValue('description'))
+ .errormsg(aJsonActions.Get(K).JsonValue.GetValue('errormsg'))
+ end;
+ end;
+ end;
+end;
+
+procedure TSafety4D.__loadUserKeysJson(var aJson: TJsonObject);
+var
+ I : Integer;
+ FGroupName : String;
+ aJsonGroup : TJsonObject;
+ aJsonPermission : TJsonArray;
+ X: Integer;
+ iPermissionGroup : iSafety4DUserKeyRegisterGroupPermission;
+begin
+ for I := 0 to Pred(aJson.Count) do
+ begin
+ FGroupName := aJson.Get(I).JsonString.Value;
+ aJsonGroup := aJson.Get(I).JsonValue as TJsonObject;
+ aJsonPermission := aJsonGroup.GetValue('permissionGroups');
+
+ iPermissionGroup :=
+ userKey
+ .registerUserKey
+ .add(FGroupName)
+ .description(aJsonGroup.GetValue('description'));
+
+ for X := 0 to Pred(aJsonPermission.Count) do
+ begin
+ iPermissionGroup.addPermission(aJsonPermission.Get(X).Value);
+ end;
+ end;
+end;
+
+end.