From ed0c5ee942aa1b4fc473dcbd2afb07d43443c671 Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Sat, 1 Jul 2023 00:23:19 +0200 Subject: [PATCH] Removed old code; renamed TProtocolFilter to TCustomProtocolFilter and TControllerFilter to TCustomControllerFilter --- samples/CustomAuth/AuthHandlerU.pas | 135 -- samples/CustomAuth/CustomAuthClient.dpr | 14 - samples/CustomAuth/CustomAuthClient.dproj | 1234 ----------------- samples/CustomAuth/CustomAuthGroup.groupproj | 48 - samples/CustomAuth/CustomAuthServer.dpr | 47 - samples/CustomAuth/MainClientFormU.dfm | 196 --- samples/CustomAuth/MainClientFormU.pas | 188 --- samples/CustomAuth/MyWebModuleU.dfm | 8 - samples/CustomAuth/MyWebModuleU.pas | 94 -- samples/CustomAuth/PrivateControllerU.pas | 78 -- samples/CustomAuth/PublicControllerU.pas | 52 - .../AppControllerU.pas | 66 +- .../FiltersSamples.dpr} | 92 +- .../FiltersSamples.dproj} | 918 +++++------- samples/custom_filters/MiddlewareSample1.pas | 48 + .../WebModuleUnit1.dfm | 23 +- .../WebModuleUnit1.pas | 92 +- samples/jsonwriterrenders/WebModuleU.dfm | 1 - samples/jsonwriterrenders/WebModuleU.pas | 4 +- .../jsonwriterrenders/jsonwriterrenders.dpr | 18 +- .../jsonwriterrenders/jsonwriterrenders.dproj | 642 ++++----- samples/middleware/MiddlewareSample1.pas | 89 -- samples/middleware/MiddlewareSamples.dproj | 171 --- sources/MVCFramework.Filters.Action.pas | 2 +- ...rs.Authentication.RoleBasedAuthHandler.pas | 90 -- .../MVCFramework.Filters.Authentication.pas | 366 +---- sources/MVCFramework.Filters.Compression.pas | 2 +- sources/MVCFramework.Filters.JWT.pas | 6 +- sources/MVCFramework.Filters.Router.pas | 2 +- sources/MVCFramework.Filters.StaticFiles.pas | 2 +- sources/MVCFramework.pas | 20 +- unittests/general/Several/LiveServerTestU.pas | 316 ++--- .../TestServer/SpeedProtocolFilterU.pas | 2 +- .../general/TestServer/WebModuleUnit.pas | 1 - 34 files changed, 992 insertions(+), 4075 deletions(-) delete mode 100644 samples/CustomAuth/AuthHandlerU.pas delete mode 100644 samples/CustomAuth/CustomAuthClient.dpr delete mode 100644 samples/CustomAuth/CustomAuthClient.dproj delete mode 100644 samples/CustomAuth/CustomAuthGroup.groupproj delete mode 100644 samples/CustomAuth/CustomAuthServer.dpr delete mode 100644 samples/CustomAuth/MainClientFormU.dfm delete mode 100644 samples/CustomAuth/MainClientFormU.pas delete mode 100644 samples/CustomAuth/MyWebModuleU.dfm delete mode 100644 samples/CustomAuth/MyWebModuleU.pas delete mode 100644 samples/CustomAuth/PrivateControllerU.pas delete mode 100644 samples/CustomAuth/PublicControllerU.pas rename samples/{middleware => custom_filters}/AppControllerU.pas (93%) rename samples/{middleware/MiddlewareSamples.dpr => custom_filters/FiltersSamples.dpr} (92%) rename samples/{CustomAuth/CustomAuthServer.dproj => custom_filters/FiltersSamples.dproj} (66%) create mode 100644 samples/custom_filters/MiddlewareSample1.pas rename samples/{middleware => custom_filters}/WebModuleUnit1.dfm (84%) rename samples/{middleware => custom_filters}/WebModuleUnit1.pas (81%) delete mode 100644 samples/middleware/MiddlewareSample1.pas delete mode 100644 samples/middleware/MiddlewareSamples.dproj diff --git a/samples/CustomAuth/AuthHandlerU.pas b/samples/CustomAuth/AuthHandlerU.pas deleted file mode 100644 index c4ad8a08..00000000 --- a/samples/CustomAuth/AuthHandlerU.pas +++ /dev/null @@ -1,135 +0,0 @@ -// *************************************************************************** -// -// Delphi MVC Framework -// -// Copyright (c) 2010-2023 Daniele Teti and the DMVCFramework Team -// -// https://github.com/danieleteti/delphimvcframework -// -// *************************************************************************** -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// *************************************************************************** } - -unit AuthHandlerU; - -interface - -uses - MVCFramework.Commons, MVCFramework, System.Generics.Collections; - -type - TCustomAuth = class(TInterfacedObject, IMVCAuthenticationHandler) - public - // called at each request to know if the request requires an authentication - procedure OnRequest(const AContext: TWebContext; const ControllerQualifiedClassName: string; - const ActionName: string; var AuthenticationRequired: Boolean); - - // if authentication is required, this method must execute the user authentication - procedure OnAuthentication(const AContext: TWebContext; const UserName: string; const Password: string; - UserRoles: TList; - var IsValid: Boolean; - const SessionData: System.Generics.Collections.TDictionary); - - // if authenticated, this method defines the user roles - procedure OnAuthorization(const AContext: TWebContext; UserRoles: System.Generics.Collections.TList; - const ControllerQualifiedClassName: string; const ActionName: string; - var IsAuthorized: Boolean); - - end; - -implementation - -uses - System.SysUtils; - -{ TCustomAuth } - -procedure TCustomAuth.OnAuthentication(const AContext: TWebContext; const UserName: string; const Password: string; - UserRoles: TList; - var IsValid: Boolean; - const SessionData: System.Generics.Collections.TDictionary); -begin - { - Here you should do the actual query on database or other "users store" to - check if the user identified by UserName and Password is a valid user. - You have to fill also the UserRoles list with the roles of the user. - Moreover additional user properties can be added in the SessionData dictionary - } - - // We defined 3 statc users here: admin, user1, user2 - IsValid := False; - if (UserName = 'admin') and (Password = 'adminpass') then - begin - IsValid := True; - UserRoles.Add('admin'); - end - else if (UserName = 'user1') and (Password = 'user1pass') then - begin - IsValid := True; - UserRoles.Add('role1'); - end - else if (UserName = 'user2') and (Password = 'user2pass') then - begin - IsValid := True; - UserRoles.Add('role2'); - end; - - // if you dont have "roles" concept in your system, you can also avoid to use them and - // sets only IsValid := True; -end; - -procedure TCustomAuth.OnAuthorization(const AContext: TWebContext; UserRoles: System.Generics.Collections.TList; - const ControllerQualifiedClassName: string; const ActionName: string; - var IsAuthorized: Boolean); -begin - if ControllerQualifiedClassName = 'PrivateControllerU.TPrivateController' then - begin - IsAuthorized := UserRoles.Contains('admin'); - if not IsAuthorized then - IsAuthorized := (UserRoles.Contains('role1')) and (ActionName = 'OnlyRole1'); - if not IsAuthorized then - IsAuthorized := (UserRoles.Contains('role2')) and (ActionName = 'OnlyRole2'); - end - else - begin - // You can always navigate in the public section of API - IsAuthorized := True; - end; - -end; - -procedure TCustomAuth.OnRequest(const AContext: TWebContext; const ControllerQualifiedClassName: string; - const ActionName: string; var AuthenticationRequired: Boolean); -begin - { - This is the the auth schema implemented: All the actions present in the - 'PrivateControllerU.TPrivateController' requires authentication but - the action 'PublicAction'. In other words, 'PublicAction' can be called also - without authentication. - } - - AuthenticationRequired := - ControllerQualifiedClassName = 'PrivateControllerU.TPrivateController'; - if AuthenticationRequired then - begin - if ActionName = 'PublicAction' then - begin - AuthenticationRequired := False; - end; - end; - -end; - -end. diff --git a/samples/CustomAuth/CustomAuthClient.dpr b/samples/CustomAuth/CustomAuthClient.dpr deleted file mode 100644 index fece9e42..00000000 --- a/samples/CustomAuth/CustomAuthClient.dpr +++ /dev/null @@ -1,14 +0,0 @@ -program CustomAuthClient; - -uses - Vcl.Forms, - MainClientFormU in 'MainClientFormU.pas' {Form7}; - -{$R *.res} - -begin - Application.Initialize; - Application.MainFormOnTaskbar := True; - Application.CreateForm(TForm7, Form7); - Application.Run; -end. diff --git a/samples/CustomAuth/CustomAuthClient.dproj b/samples/CustomAuth/CustomAuthClient.dproj deleted file mode 100644 index 3f3a5020..00000000 --- a/samples/CustomAuth/CustomAuthClient.dproj +++ /dev/null @@ -1,1234 +0,0 @@ - - - {B42B1969-7408-4E0A-8624-A48DADE46556} - 19.1 - VCL - CustomAuthClient.dpr - True - Debug - Win32 - 1 - Application - - - true - - - true - Base - true - - - true - Base - true - - - true - Base - true - - - true - Cfg_1 - true - true - - - true - Base - true - - - true - Cfg_2 - true - true - - - 1040 - CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName) - ..\..\lib\loggerpro;..\..\lib\delphistompclient;..\..\lib\dmustache;..\..\..\delphiredisclient\sources;$(DCC_UnitSearchPath) - $(BDS)\bin\delphi_PROJECTICON.ico - CustomAuthClient - System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) - .\$(Platform)\$(Config) - .\$(Platform)\$(Config) - false - false - false - false - false - - - $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png - $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png - 1033 - DBXSqliteDriver;RESTComponents;fmxase;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;emsclientfiredac;tethering;svnui;DataSnapFireDAC;JvGlobus;FireDACADSDriver;JvPluginSystem;DBXMSSQLDriver;OrpheusDR;JvMM;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;PngComponentsD;vcltouch;JvBands;vcldb;bindcompfmx;svn;JvJans;DBXOracleDriver;JvNet;inetdb;FrameViewerXE8;JvAppFrm;VirtualTreesDR;FmxTeeUI;emsedge;JvDotNetCtrls;FireDACIBDriver;fmx;fmxdae;DelphiCookbookListViewAppearance;frx24;vclib;JvWizards;FireDACDBXDriver;dbexpress;IndyCore;OrpheusDBDR;vclx;JvPageComps;dsnap;emsclient;DataSnapCommon;FireDACCommon;JvDB;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;JclDeveloperTools;SampleListViewRatingsAppearancePackage;vclie;bindengine;DBXMySQLDriver;CloudService;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;RosiDBSorters_DX101;JvCmp;JvHMI;FireDACCommonODBC;FireDACCommonDriver;DataSnapClient;inet;IupOrmProject;IndyIPCommon;bindcompdbx;TsiLang_XE101r;JvCustom;vcl;IndyIPServer;DBXSybaseASEDriver;JvXPCtrls;IndySystem;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;Python_XE7;TeeDB;FireDAC;SchGridPackage;RosiDBComp_DX101;Jcl;emshosting;JvCore;JvCrypt;FireDACSqliteDriver;FireDACPgDriver;ibmonitor;FireDACASADriver;ChromeTabs_R;DBXOdbcDriver;FireDACTDataDriver;FMXTee;soaprtl;DbxCommonDriver;JvDlgs;JvRuntimeDesign;ibxpress;Tee;JvManagedThreads;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;ibxbindings;DbxClientDriver;JvTimeFramework;DBXSybaseASADriver;frxTee24;CustomIPTransport;vcldsnap;JvSystem;JvStdCtrls;SynEditDR;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;frxe24;TeeUI;TGridExtendedColumns;dbxcds;VclSmp;JvDocking;adortl;FireDACODBCDriver;JvPascalInterpreter;JclVcl;DataSnapIndy10ServerTransport;frxDB24;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;PowerPDFDR;JvControls;JvPrintPreview;JclContainers;DataSnapServerMidas;$(DCC_UsePackage) - $(BDS)\bin\default_app.manifest - Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) - CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(ModuleName);FileDescription=$(ModuleName);ProductName=$(ModuleName) - true - - - $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png - $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png - DBXSqliteDriver;RESTComponents;fmxase;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;emsclientfiredac;tethering;DataSnapFireDAC;FireDACADSDriver;DBXMSSQLDriver;OrpheusDR;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;PngComponentsD;vcltouch;vcldb;bindcompfmx;DBXOracleDriver;inetdb;VirtualTreesDR;FmxTeeUI;emsedge;FireDACIBDriver;fmx;fmxdae;vclib;FireDACDBXDriver;dbexpress;IndyCore;OrpheusDBDR;vclx;dsnap;emsclient;DataSnapCommon;FireDACCommon;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;vclie;bindengine;DBXMySQLDriver;CloudService;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;RosiDBSorters_DX101;FireDACCommonODBC;FireDACCommonDriver;DataSnapClient;inet;IndyIPCommon;bindcompdbx;vcl;IndyIPServer;DBXSybaseASEDriver;IndySystem;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;TeeDB;FireDAC;RosiDBComp_DX101;emshosting;FireDACSqliteDriver;FireDACPgDriver;ibmonitor;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;soaprtl;DbxCommonDriver;ibxpress;Tee;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;ibxbindings;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;SynEditDR;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;TeeUI;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;PowerPDFDR;DataSnapServerMidas;$(DCC_UsePackage) - - - DEBUG;$(DCC_Define) - true - false - true - true - true - - - true - 1033 - Debug - true - false - PerMonitor - CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(ModuleName);FileDescription=$(ModuleName);ProductName=$(ModuleName) - - - false - RELEASE;$(DCC_Define) - 0 - 0 - - - true - PerMonitor - - - - MainSource - - -
Form7
- dfm -
- - Cfg_2 - Base - - - Base - - - Cfg_1 - Base - -
- - Delphi.Personality.12 - Application - - - - CustomAuthClient.dpr - - - Embarcadero C++Builder Office 2000 Servers Package - Embarcadero C++Builder Office XP Servers Package - Microsoft Office 2000 Sample Automation Server Wrapper Components - Microsoft Office XP Sample Automation Server Wrapper Components - - - - - - CustomAuthClient.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-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 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset - 1 - - - ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 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 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset - 1 - - - ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset - 1 - - - - - 1 - - - 1 - - - 1 - - - - - ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset - 1 - - - ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 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 - - - 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/CustomAuth/CustomAuthGroup.groupproj b/samples/CustomAuth/CustomAuthGroup.groupproj deleted file mode 100644 index 27346469..00000000 --- a/samples/CustomAuth/CustomAuthGroup.groupproj +++ /dev/null @@ -1,48 +0,0 @@ - - - {CF5DB084-7815-4A94-85E3-F9FC0074C8AC} - - - - - - - - - - - Default.Personality.12 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/CustomAuth/CustomAuthServer.dpr b/samples/CustomAuth/CustomAuthServer.dpr deleted file mode 100644 index 063b60dd..00000000 --- a/samples/CustomAuth/CustomAuthServer.dpr +++ /dev/null @@ -1,47 +0,0 @@ -program CustomAuthServer; - -{$APPTYPE CONSOLE} - -uses - System.SysUtils, - Web.WebReq, - Web.WebBroker, - IdHTTPWebBrokerBridge, - PublicControllerU in 'PublicControllerU.pas', - MyWebModuleU in 'MyWebModuleU.pas' {MyWebModule: TWebModule} , - PrivateControllerU in 'PrivateControllerU.pas', - AuthHandlerU in 'AuthHandlerU.pas'; - -{$R *.res} - -procedure RunServer(APort: Integer); -var - LServer: TIdHTTPWebBrokerBridge; -begin - Writeln('** DMVCFramework Server **'); - Writeln(Format('Starting HTTP Server on port %d', [APort])); - LServer := TIdHTTPWebBrokerBridge.Create(nil); - try - LServer.DefaultPort := APort; - LServer.Active := True; - // ShellExecute(0, 'open', pChar('http://localhost:' + inttostr(APort)), nil, nil, SW_SHOWMAXIMIZED); - Writeln('Press RETURN to stop the server'); - ReadLn; - finally - LServer.Free; - end; -end; - -begin - ReportMemoryLeaksOnShutdown := True; - try - if WebRequestHandler <> nil then - WebRequestHandler.WebModuleClass := WebModuleClass; - WebRequestHandlerProc.MaxConnections := 1024; - RunServer(8080); - except - on E: Exception do - Writeln(E.ClassName, ': ', E.Message); - end; - -end. diff --git a/samples/CustomAuth/MainClientFormU.dfm b/samples/CustomAuth/MainClientFormU.dfm deleted file mode 100644 index 76845345..00000000 --- a/samples/CustomAuth/MainClientFormU.dfm +++ /dev/null @@ -1,196 +0,0 @@ -object Form7: TForm7 - Left = 0 - Top = 0 - Caption = 'Form7' - ClientHeight = 353 - ClientWidth = 602 - Color = clBtnFace - Font.Charset = DEFAULT_CHARSET - Font.Color = clWindowText - Font.Height = -11 - Font.Name = 'Tahoma' - Font.Style = [] - OldCreateOrder = False - OnCreate = FormCreate - DesignSize = ( - 602 - 353) - PixelsPerInch = 96 - TextHeight = 13 - object Label3: TLabel - Left = 8 - Top = 31 - Width = 89 - Height = 13 - Caption = 'Available accounts' - end - object Label4: TLabel - Left = 8 - Top = 8 - Width = 42 - Height = 14 - Caption = 'STEP 1' - Color = clWindowText - Font.Charset = DEFAULT_CHARSET - Font.Color = clRed - Font.Height = 14 - Font.Name = 'Tahoma' - Font.Style = [fsBold] - ParentColor = False - ParentFont = False - Transparent = True - end - object Label5: TLabel - Left = 145 - Top = 8 - Width = 42 - Height = 14 - Caption = 'STEP 2' - Color = clWindowText - Font.Charset = DEFAULT_CHARSET - Font.Color = clRed - Font.Height = 14 - Font.Name = 'Tahoma' - Font.Style = [fsBold] - ParentColor = False - ParentFont = False - Transparent = True - end - object Label6: TLabel - Left = 312 - Top = 8 - Width = 42 - Height = 14 - Caption = 'STEP 3' - Color = clWindowText - Font.Charset = DEFAULT_CHARSET - Font.Color = clRed - Font.Height = 14 - Font.Name = 'Tahoma' - Font.Style = [fsBold] - ParentColor = False - ParentFont = False - Transparent = True - end - object Label7: TLabel - Left = 8 - Top = 116 - Width = 123 - Height = 39 - Caption = 'user1 has "role1", user2 has "role2", admin has all the roles' - WordWrap = True - end - object GroupBox1: TGroupBox - Left = 145 - Top = 31 - Width = 161 - Height = 147 - Caption = 'Login/Logout' - TabOrder = 2 - object Label1: TLabel - Left = 16 - Top = 20 - Width = 48 - Height = 13 - Caption = 'Username' - end - object Label2: TLabel - Left = 16 - Top = 66 - Width = 46 - Height = 13 - Caption = 'Password' - end - object edtUsername: TEdit - Left = 16 - Top = 39 - Width = 121 - Height = 21 - TabOrder = 0 - Text = 'user1' - end - object edtPassword: TEdit - Left = 16 - Top = 85 - Width = 121 - Height = 21 - TabOrder = 1 - Text = 'user1pass' - end - object btnLogInLogOut: TButton - Left = 16 - Top = 112 - Width = 121 - Height = 25 - Caption = 'btnLogInLogOut' - TabOrder = 2 - OnClick = btnLogInLogOutClick - end - end - object Panel1: TPanel - Left = 0 - Top = 326 - Width = 602 - Height = 27 - Align = alBottom - TabOrder = 6 - end - object Button1: TButton - Left = 311 - Top = 31 - Width = 283 - Height = 45 - Anchors = [akLeft, akTop, akRight] - Caption = 'Call Public Action (no login required)' - TabOrder = 0 - OnClick = Button1Click - end - object Memo1: TMemo - Left = 8 - Top = 184 - Width = 586 - Height = 136 - Anchors = [akLeft, akTop, akRight, akBottom] - Lines.Strings = ( - 'Memo1') - TabOrder = 5 - end - object Button2: TButton - Left = 311 - Top = 82 - Width = 283 - Height = 45 - Anchors = [akLeft, akTop, akRight] - Caption = 'Call action allowed only for "role1"' - TabOrder = 3 - OnClick = Button2Click - end - object Button3: TButton - Left = 312 - Top = 133 - Width = 283 - Height = 45 - Anchors = [akLeft, akTop, akRight] - Caption = 'Call action allowed only for "role2"' - TabOrder = 4 - OnClick = Button3Click - end - object ListBox1: TListBox - Left = 8 - Top = 51 - Width = 131 - Height = 59 - ItemHeight = 13 - Items.Strings = ( - 'user1:user1pass' - 'user2:user2pass' - 'admin:adminpass') - TabOrder = 1 - OnClick = ListBox1Click - end - object ApplicationEvents1: TApplicationEvents - OnIdle = ApplicationEvents1Idle - Left = 16 - Top = 184 - end -end diff --git a/samples/CustomAuth/MainClientFormU.pas b/samples/CustomAuth/MainClientFormU.pas deleted file mode 100644 index 6cf5fec9..00000000 --- a/samples/CustomAuth/MainClientFormU.pas +++ /dev/null @@ -1,188 +0,0 @@ -// *************************************************************************** -// -// Delphi MVC Framework -// -// Copyright (c) 2010-2023 Daniele Teti and the DMVCFramework Team -// -// https://github.com/danieleteti/delphimvcframework -// -// *************************************************************************** -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// *************************************************************************** } - -unit MainClientFormU; - -interface - -uses - Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, - Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.AppEvnts, MVCFramework.RESTClient.Intf, MVCFramework.RESTClient, - Vcl.ExtCtrls; - -type - TForm7 = class(TForm) - GroupBox1: TGroupBox; - edtUsername: TEdit; - edtPassword: TEdit; - btnLogInLogOut: TButton; - ApplicationEvents1: TApplicationEvents; - Panel1: TPanel; - Button1: TButton; - Memo1: TMemo; - Button2: TButton; - Button3: TButton; - Label1: TLabel; - Label2: TLabel; - ListBox1: TListBox; - Label3: TLabel; - Label4: TLabel; - Label5: TLabel; - Label6: TLabel; - Label7: TLabel; - procedure FormCreate(Sender: TObject); - procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); - procedure btnLogInLogOutClick(Sender: TObject); - procedure Button1Click(Sender: TObject); - procedure Button2Click(Sender: TObject); - procedure Button3Click(Sender: TObject); - procedure ListBox1Click(Sender: TObject); - private - FRESTClient: IMVCRESTClient; - FLogoutUrl: string; - FLogoutMethod: string; - procedure FillMemo(Response: IMVCRESTResponse); - { Private declarations } - public - { Public declarations } - end; - -var - Form7: TForm7; - -implementation - -uses - System.JSON, - MVCFramework.SystemJSONUtils; - -{$R *.dfm} - - -procedure TForm7.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); -begin - if FRESTClient.SessionID.IsEmpty then - begin - btnLogInLogOut.Caption := 'LOGIN'; - Panel1.Caption := 'Not Logged'; - edtUsername.Enabled := True; - edtPassword.Enabled := True; - end - else - begin - btnLogInLogOut.Caption := 'LOGOUT'; - Panel1.Caption := 'SessionID = ' + FRESTClient.SessionID; - edtUsername.Enabled := False; - edtPassword.Enabled := False; - end; - -end; - -procedure TForm7.btnLogInLogOutClick(Sender: TObject); -var - lJObj: TJSONObject; - lRes: IMVCRESTResponse; -begin - if btnLogInLogOut.Caption = 'LOGIN' then - begin - lJObj := TJSONObject.Create; - try - lJObj.AddPair('username', edtUsername.Text); - lJObj.AddPair('password', edtPassword.Text); - lRes := FRESTClient.Post('/system/users/logged', TSystemJSON.JSONValueToString(lJObj, False)); - if not lRes.Success then - begin - ShowMessage(lRes.Content); - end; - FLogoutUrl := lRes.HeaderValue('X-LOGOUT-URL'); - FLogoutMethod := lRes.HeaderValue('X-LOGOUT-METHOD'); - finally - lJObj.Free; - end; - end - else - begin - Assert(FLogoutMethod = 'DELETE'); - lRes := FRESTClient.Delete(FLogoutUrl); - if not lRes.Success then - begin - ShowMessage(lRes.Content); - end; - end; -end; - -procedure TForm7.Button1Click(Sender: TObject); -var - lRes: IMVCRESTResponse; -begin - lRes := FRESTClient.Get('/private/public/action'); - FillMemo(lRes); -end; - -procedure TForm7.Button2Click(Sender: TObject); -var - lRes: IMVCRESTResponse; -begin - lRes := FRESTClient.Get('/private/role1'); - FillMemo(lRes); -end; - -procedure TForm7.Button3Click(Sender: TObject); -var - lRes: IMVCRESTResponse; -begin - lRes := FRESTClient.Get('/private/role2'); - FillMemo(lRes); -end; - -procedure TForm7.FillMemo(Response: IMVCRESTResponse); -begin - Memo1.Lines.Add( - Format('[%s] [%s] %s', - [TimeToStr(Time), - Response.StatusText, - Response.Content])); -end; - -procedure TForm7.FormCreate(Sender: TObject); -begin - FRESTClient := TMVCRESTClient.New.BaseURL('localhost', 8080); -end; - -procedure TForm7.ListBox1Click(Sender: TObject); -var - lText: string; - lPieces: TArray; -begin - if ListBox1.ItemIndex > -1 then - begin - lText := ListBox1.Items[ListBox1.ItemIndex]; - lPieces := lText.Split([':']); - edtUsername.Text := lPieces[0]; - edtPassword.Text := lPieces[1]; - ShowMessage('Now you can log in using the login/logout button'); - end; -end; - -end. diff --git a/samples/CustomAuth/MyWebModuleU.dfm b/samples/CustomAuth/MyWebModuleU.dfm deleted file mode 100644 index 018d0670..00000000 --- a/samples/CustomAuth/MyWebModuleU.dfm +++ /dev/null @@ -1,8 +0,0 @@ -object MyWebModule: TMyWebModule - OldCreateOrder = False - OnCreate = WebModuleCreate - OnDestroy = WebModuleDestroy - Actions = <> - Height = 230 - Width = 415 -end diff --git a/samples/CustomAuth/MyWebModuleU.pas b/samples/CustomAuth/MyWebModuleU.pas deleted file mode 100644 index e2a193ca..00000000 --- a/samples/CustomAuth/MyWebModuleU.pas +++ /dev/null @@ -1,94 +0,0 @@ -// *************************************************************************** -// -// Delphi MVC Framework -// -// Copyright (c) 2010-2023 Daniele Teti and the DMVCFramework Team -// -// https://github.com/danieleteti/delphimvcframework -// -// *************************************************************************** -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// *************************************************************************** } - -unit MyWebModuleU; - -interface - -uses System.SysUtils, - System.Classes, - Web.HTTPApp, - MVCFramework; - -type - TMyWebModule = class(TWebModule) - procedure WebModuleCreate(Sender: TObject); - procedure WebModuleDestroy(Sender: TObject); - private - FMVC: TMVCEngine; - public - { Public declarations } - end; - -var - WebModuleClass: TComponentClass = TMyWebModule; - -implementation - -{$R *.dfm} - - -uses - MVCFramework.Commons, - PublicControllerU, - PrivateControllerU, - MVCFramework.Middleware.Authentication, - MVCFramework.Middleware.StaticFiles, - AuthHandlerU; - -procedure TMyWebModule.WebModuleCreate(Sender: TObject); -begin - FMVC := TMVCEngine.Create(Self, - procedure(Config: TMVCConfig) - begin - // session timeout (0 means session cookie) - Config[TMVCConfigKey.SessionTimeout] := '0'; - // default content-type - Config[TMVCConfigKey.DefaultContentType] := TMVCConstants.DEFAULT_CONTENT_TYPE; - // default content charset - Config[TMVCConfigKey.DefaultContentCharset] := TMVCConstants.DEFAULT_CONTENT_CHARSET; - // unhandled actions are permitted? - Config[TMVCConfigKey.AllowUnhandledAction] := 'false'; - // default view file extension - Config[TMVCConfigKey.DefaultViewFileExtension] := 'html'; - // view path - Config[TMVCConfigKey.ViewPath] := 'templates'; - // Enable Server Signature in response - Config[TMVCConfigKey.ExposeServerSignature] := 'true'; - end); - FMVC.AddController(TPublicController); - FMVC.AddController(TPrivateController); - FMVC.AddMiddleware( - TMVCCustomAuthenticationMiddleware.Create( - TCustomAuth.Create, - '/system/users/logged' - )); -end; - -procedure TMyWebModule.WebModuleDestroy(Sender: TObject); -begin - FMVC.Free; -end; - -end. diff --git a/samples/CustomAuth/PrivateControllerU.pas b/samples/CustomAuth/PrivateControllerU.pas deleted file mode 100644 index b4d4a3a1..00000000 --- a/samples/CustomAuth/PrivateControllerU.pas +++ /dev/null @@ -1,78 +0,0 @@ -// *************************************************************************** -// -// Delphi MVC Framework -// -// Copyright (c) 2010-2023 Daniele Teti and the DMVCFramework Team -// -// https://github.com/danieleteti/delphimvcframework -// -// *************************************************************************** -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// *************************************************************************** } - -unit PrivateControllerU; - -interface - -uses - MVCFramework, MVCFramework.Commons; - -type - - [MVCPath('/private')] - TPrivateController = class(TMVCController) - public - [MVCPath('/')] - [MVCHTTPMethod([httpGET])] - procedure Index; - - [MVCPath('/public/action')] - [MVCHTTPMethod([httpGET])] - procedure PublicAction; - - [MVCPath('/role1')] - [MVCHTTPMethod([httpGET])] - procedure OnlyRole1; - - [MVCPath('/role2')] - [MVCHTTPMethod([httpGET])] - procedure OnlyRole2; - end; - -implementation - -procedure TPrivateController.Index; -begin - // use Context property to access to the HTTP request and response - Render('Hello World'); - -end; - -procedure TPrivateController.OnlyRole1; -begin - Render('OK from a "role1" action'); -end; - -procedure TPrivateController.OnlyRole2; -begin - Render('OK from a "role2" action'); -end; - -procedure TPrivateController.PublicAction; -begin - Render('OK from a public action (no login required)'); -end; - -end. diff --git a/samples/CustomAuth/PublicControllerU.pas b/samples/CustomAuth/PublicControllerU.pas deleted file mode 100644 index 57b9c684..00000000 --- a/samples/CustomAuth/PublicControllerU.pas +++ /dev/null @@ -1,52 +0,0 @@ -// *************************************************************************** -// -// Delphi MVC Framework -// -// Copyright (c) 2010-2023 Daniele Teti and the DMVCFramework Team -// -// https://github.com/danieleteti/delphimvcframework -// -// *************************************************************************** -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// *************************************************************************** } - -unit PublicControllerU; - -interface - -uses - MVCFramework, MVCFramework.Commons; - -type - - [MVCPath('/')] - TPublicController = class(TMVCController) - public - [MVCPath('/')] - [MVCHTTPMethod([httpGET])] - procedure Index; - - end; - -implementation - -procedure TPublicController.Index; -begin - // use Context property to access to the HTTP request and response - Render('Hello World'); - -end; - -end. diff --git a/samples/middleware/AppControllerU.pas b/samples/custom_filters/AppControllerU.pas similarity index 93% rename from samples/middleware/AppControllerU.pas rename to samples/custom_filters/AppControllerU.pas index 9e798913..288ba024 100644 --- a/samples/middleware/AppControllerU.pas +++ b/samples/custom_filters/AppControllerU.pas @@ -1,33 +1,33 @@ -unit AppControllerU; - -interface - -uses MVCFramework, - MVCFramework.Commons, - MVCFramework.Logger, - Web.HTTPApp; - -type - - [MVCPath('/')] - TApp1MainController = class(TMVCController) - public - [MVCPath('/')] - [MVCHTTPMethod([httpGET])] - procedure Index; - end; - -implementation - -uses - System.SysUtils; - -{ TApp1MainController } - -procedure TApp1MainController.Index; -begin - ContentType := TMVCMediaType.TEXT_PLAIN; - Render(StringOfChar('*', 1024)); -end; - -end. +unit AppControllerU; + +interface + +uses MVCFramework, + MVCFramework.Commons, + MVCFramework.Logger, + Web.HTTPApp; + +type + + [MVCPath('/')] + TApp1MainController = class(TMVCController) + public + [MVCPath('/')] + [MVCHTTPMethod([httpGET])] + procedure Index; + end; + +implementation + +uses + System.SysUtils; + +{ TApp1MainController } + +procedure TApp1MainController.Index; +begin + ContentType := TMVCMediaType.TEXT_PLAIN; + Render(StringOfChar('*', 1024)); +end; + +end. diff --git a/samples/middleware/MiddlewareSamples.dpr b/samples/custom_filters/FiltersSamples.dpr similarity index 92% rename from samples/middleware/MiddlewareSamples.dpr rename to samples/custom_filters/FiltersSamples.dpr index 4e9adf02..84c0e9a0 100644 --- a/samples/middleware/MiddlewareSamples.dpr +++ b/samples/custom_filters/FiltersSamples.dpr @@ -1,46 +1,46 @@ -program MiddlewareSamples; - -{$APPTYPE CONSOLE} - - -uses - System.SysUtils, - Web.WebReq, - Web.WebBroker, - IdHTTPWebBrokerBridge, - WebModuleUnit1 in 'WebModuleUnit1.pas' {WebModule1: TWebModule} , - AppControllerU in 'AppControllerU.pas', - MiddlewareSample1 in 'MiddlewareSample1.pas'; - -{$R *.res} - - -procedure RunServer(APort: Integer); -var - LServer: TIdHTTPWebBrokerBridge; -begin - Writeln(Format('Starting HTTP Server or port %d', [APort])); - LServer := TIdHTTPWebBrokerBridge.Create(nil); - try - LServer.DefaultPort := APort; - LServer.Active := True; - Writeln('Press RETURN to stop the server'); - ReadLn; - finally - LServer.Free; - end; -end; - -begin - ReportMemoryLeaksOnShutdown := True; - try - if WebRequestHandler <> nil then - WebRequestHandler.WebModuleClass := WebModuleClass; - WebRequestHandlerProc.MaxConnections := 1024; - RunServer(8080); - except - on E: Exception do - Writeln(E.ClassName, ': ', E.Message); - end - -end. +program FiltersSamples; + +{$APPTYPE CONSOLE} + + +uses + System.SysUtils, + Web.WebReq, + Web.WebBroker, + IdHTTPWebBrokerBridge, + WebModuleUnit1 in 'WebModuleUnit1.pas' {WebModule1: TWebModule} , + AppControllerU in 'AppControllerU.pas', + MiddlewareSample1 in 'MiddlewareSample1.pas'; + +{$R *.res} + + +procedure RunServer(APort: Integer); +var + LServer: TIdHTTPWebBrokerBridge; +begin + Writeln(Format('Starting HTTP Server or port %d', [APort])); + LServer := TIdHTTPWebBrokerBridge.Create(nil); + try + LServer.DefaultPort := APort; + LServer.Active := True; + Writeln('Press RETURN to stop the server'); + ReadLn; + finally + LServer.Free; + end; +end; + +begin + ReportMemoryLeaksOnShutdown := True; + try + if WebRequestHandler <> nil then + WebRequestHandler.WebModuleClass := WebModuleClass; + WebRequestHandlerProc.MaxConnections := 1024; + RunServer(8080); + except + on E: Exception do + Writeln(E.ClassName, ': ', E.Message); + end + +end. diff --git a/samples/CustomAuth/CustomAuthServer.dproj b/samples/custom_filters/FiltersSamples.dproj similarity index 66% rename from samples/CustomAuth/CustomAuthServer.dproj rename to samples/custom_filters/FiltersSamples.dproj index 1667bd94..6f57a376 100644 --- a/samples/CustomAuth/CustomAuthServer.dproj +++ b/samples/custom_filters/FiltersSamples.dproj @@ -1,9 +1,9 @@  - {0293A1B2-2793-41CE-9099-8B24A46AA8CF} - 19.1 + {0388D146-2B8B-427B-AEDD-EFD5F51D3139} + 19.5 VCL - CustomAuthServer.dpr + FiltersSamples.dpr True Debug Win32 @@ -40,15 +40,14 @@ true - CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName) + $(BDS)\bin\delphi_PROJECTICNS.icns + FiltersSamples + ..\..\sources;..\..\lib\delphistompclient;..\..\lib\loggerpro;..\..\lib\dmustache;$(DCC_UnitSearchPath) + CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= + None 1040 $(BDS)\bin\delphi_PROJECTICON.ico - $(BDS)\bin\delphi_PROJECTICNS.icns - CustomAuthServer - ..\..\lib\loggerpro;..\..\lib\delphistompclient;..\..\lib\dmustache;..\..\..\delphiredisclient\sources;$(DCC_UnitSearchPath) System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) - VCL;$(DCC_Framework) - true .\$(Platform)\$(Config) .\$(Platform)\$(Config) false @@ -58,13 +57,13 @@ false - 1033 - DBXSqliteDriver;RESTComponents;fmxase;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;emsclientfiredac;tethering;svnui;DataSnapFireDAC;JvGlobus;FireDACADSDriver;JvPluginSystem;DBXMSSQLDriver;OrpheusDR;JvMM;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;PngComponentsD;vcltouch;JvBands;vcldb;bindcompfmx;svn;JvJans;DBXOracleDriver;JvNet;inetdb;FrameViewerXE8;JvAppFrm;VirtualTreesDR;FmxTeeUI;emsedge;JvDotNetCtrls;FireDACIBDriver;fmx;fmxdae;DelphiCookbookListViewAppearance;frx24;vclib;JvWizards;FireDACDBXDriver;dbexpress;IndyCore;OrpheusDBDR;vclx;JvPageComps;dsnap;emsclient;DataSnapCommon;FireDACCommon;JvDB;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;JclDeveloperTools;SampleListViewRatingsAppearancePackage;vclie;bindengine;DBXMySQLDriver;CloudService;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;RosiDBSorters_DX101;JvCmp;JvHMI;FireDACCommonODBC;FireDACCommonDriver;DataSnapClient;inet;IupOrmProject;IndyIPCommon;bindcompdbx;TsiLang_XE101r;JvCustom;vcl;IndyIPServer;DBXSybaseASEDriver;JvXPCtrls;IndySystem;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;Python_XE7;TeeDB;FireDAC;SchGridPackage;RosiDBComp_DX101;Jcl;emshosting;JvCore;JvCrypt;FireDACSqliteDriver;FireDACPgDriver;ibmonitor;FireDACASADriver;ChromeTabs_R;DBXOdbcDriver;FireDACTDataDriver;FMXTee;soaprtl;DbxCommonDriver;JvDlgs;JvRuntimeDesign;ibxpress;Tee;JvManagedThreads;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;ibxbindings;DbxClientDriver;JvTimeFramework;DBXSybaseASADriver;frxTee24;CustomIPTransport;vcldsnap;JvSystem;JvStdCtrls;SynEditDR;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;frxe24;TeeUI;TGridExtendedColumns;dbxcds;VclSmp;JvDocking;adortl;FireDACODBCDriver;JvPascalInterpreter;JclVcl;DataSnapIndy10ServerTransport;frxDB24;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;PowerPDFDR;JvControls;JvPrintPreview;JclContainers;DataSnapServerMidas;$(DCC_UsePackage) Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) - CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(ModuleName);FileDescription=$(ModuleName);ProductName=$(ModuleName) + 1033 + cxPivotGridChartRS17;JvMM;dxSkinSevenRS17;dxSkinBlueprintRS17;dxSkinHighContrastRS17;dxSkinOffice2007BlackRS17;dxCoreRS17;cxPageControldxBarPopupMenuRS17;dxSkinXmas2008BlueRS17;dxPSDBTeeChartRS17;JvCrypt;dxPSTeeChartRS17;dxSkinSummer2008RS17;dxPScxSchedulerLnkRS17;dxSkinBlueRS17;dxSkinDarkRoomRS17;DBXInterBaseDriver;DataSnapServer;DataSnapCommon;dxPScxTLLnkRS17;JvNet;JvDotNetCtrls;dxRibbonRS17;DbxCommonDriver;cxDataRS17;vclimg;dxSkinsdxBarPainterRS17;dxPSdxDBTVLnkRS17;dbxcds;DatasnapConnectorsFreePascal;NxDBGridDsgn_dxe3;JvXPCtrls;dxSkinMoneyTwinsRS17;vcldb;cxExportRS17;dxPSCoreRS17;dxBarExtItemsRS17;dxGDIPlusRS17;FMXfrx17;dxNavBarRS17;CustomIPTransport;cxLibraryRS17;cxGridRS17;dxSkinOffice2010BlackRS17;dsnap;IndyIPServer;IndyCore;dxSkinMcSkinRS17;CloudService;dxPScxCommonRS17;FmxTeeUI;frxDB17;AnyDAC_PhysDb2_D17;dxSkinsdxDLPainterRS17;dxSkiniMaginaryRS17;JvDB;JvRuntimeDesign;dxPScxVGridLnkRS17;JclDeveloperTools;dxSkinSevenClassicRS17;dxPScxExtCommonRS17;MyFrameTestPackage;dxPScxSSLnkRS17;NxGridRun_dxe3;dxSkinLilianRS17;fs17;dxPSdxLCLnkRS17;dxSkinOffice2010BlueRS17;NxCommonRun_dxe3;bindcompfmx;DataBindingsVCL170;dxSkinOffice2010SilverRS17;vcldbx;cxSchedulerGridRS17;dbrtl;bindcomp;inetdb;JvPluginSystem;dxBarRS17;DataBindings;DBXOdbcDriver;IcsCommonDXE3Run;JvCmp;dxBarDBNavRS17;dxSkinWhiteprintRS17;JvTimeFramework;xmlrtl;dxSkinsdxRibbonPainterRS17;ibxpress;dxDockingRS17;vclactnband;bindengine;soaprtl;FMXTee;dxADOServerModeRS17;bindcompvcl;dxBarExtDBItemsRS17;dxPSPrVwRibbonRS17;Jcl;vclie;dxSkinOffice2007PinkRS17;cxPageControlRS17;dxSkinscxPCPainterRS17;AnyDAC_PhysADS_D17;AnyDAC_PhysIB_D17;dxmdsRS17;dxSkinTheAsphaltWorldRS17;DBXInformixDriver;Intraweb;dxPsPrVwAdvRS17;NxInspectorRun_dxe3;dxSkinSilverRS17;dxdborRS17;dsnapcon;DBXFirebirdDriver;fsDB17;inet;dorm_runtime_xe3;JvPascalInterpreter;vclx;dxSkinStardustRS17;cxEditorsRS17;DBXSybaseASADriver;NxInspectorDsgn_dxe3;dbexpress;IndyIPClient;AnyDAC_PhysMySQL_D17;cxTreeListdxBarPopupMenuRS17;dxSkinVS2010RS17;NxGridDsgn_dxe3;dxThemeRS17;DBXSqliteDriver;dxPScxGridLnkRS17;fmx;JvDlgs;IndySystem;TeeDB;dxSkinValentineRS17;vclib;inetdbbde;DataSnapClient;dxSkinDevExpressStyleRS17;DataSnapProviderClient;DBXSybaseASEDriver;cxBarEditItemRS17;AnyDAC_PhysMSAcc_D17;dxServerModeRS17;cxPivotGridOLAPRS17;cxSchedulerRS17;MetropolisUILiveTile;AnyDAC_PhysSQLITE_D17;dxPSLnksRS17;dxSkinPumpkinRS17;dxPSdxDBOCLnkRS17;cxVerticalGridRS17;dxSkinSpringTimeRS17;vcldsnap;dxSkinDevExpressDarkStyleRS17;DBXDb2Driver;AnyDAC_ComI_D17;DBXOracleDriver;AnyDAC_PhysMSSQL_D17;JvCore;NxDBGridRun_dxe3;vclribbon;AnyDAC_Comp_D17;cxSpreadSheetRS17;dxSkinLiquidSkyRS17;AnyDAC_PhysODBC_D17;fmxase;vcl;dxSkinOffice2007SilverRS17;AnyDAC_PhysPg_D17;IndyIPCommon;DBXMSSQLDriver;CodeSiteExpressPkg;dxPSdxOCLnkRS17;dcldxSkinsCoreRS17;JvAppFrm;AnyDAC_PhysASA_D17;inetdbxpress;webdsnap;NxCollectionRun_dxe3;AnyDAC_PhysOracle_D17;dxSkinCoffeeRS17;JvDocking;adortl;dxSkinscxSchedulerPainterRS17;JvWizards;NxCollectionDsgn_dxe3;frx17;NxCommonDsgn_dxe3;dxtrmdRS17;dxPScxPCProdRS17;AnyDAC_GUIxForms_D17;JvBands;rtl;DbxClientDriver;AnyDAC_PhysTDBX_D17;dxTabbedMDIRS17;dxComnRS17;dxSkinSharpPlusRS17;dxSkinsCoreRS17;dxSkinLondonLiquidSkyRS17;dxdbtrRS17;Tee;JclContainers;NxAddonsRun_dxe3;CPortLibDXE;JvSystem;dxorgcRS17;svnui;dxSkinBlackRS17;JvControls;NxSheetRun_dxe3;IndyProtocols;DBXMySQLDriver;dxLayoutControlRS17;bindcompdbx;TeeUI;JvJans;JvPrintPreview;JvPageComps;JvStdCtrls;JvCustom;dxSkinOffice2007BlueRS17;dxPScxPivotGridLnkRS17;dxSpellCheckerRS17;vcltouch;dxSkinOffice2007GreenRS17;dxSkinSharpRS17;websnap;dxSkinFoggyRS17;dxTileControlRS17;VclSmp;FMXfrxDB17;dxSkinDarkSideRS17;cxPivotGridRS17;DataSnapConnectors;AnyDAC_Phys_D17;fmxobj;SynEdit_RXE3;JclVcl;cxTreeListRS17;dxPSdxFCLnkRS17;dxSkinGlassOceansRS17;frxe17;svn;dxFlowChartRS17;fmxdae;dxSkinsdxNavBarPainterRS17;bdertl;VirtualTreesR;DataSnapIndy10ServerTransport;dxDBXServerModeRS17;dxSkinCaramelRS17;$(DCC_UsePackage) + .\bin - DBXSqliteDriver;RESTComponents;fmxase;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;emsclientfiredac;tethering;DataSnapFireDAC;FireDACADSDriver;DBXMSSQLDriver;OrpheusDR;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;PngComponentsD;vcltouch;vcldb;bindcompfmx;DBXOracleDriver;inetdb;VirtualTreesDR;FmxTeeUI;emsedge;FireDACIBDriver;fmx;fmxdae;vclib;FireDACDBXDriver;dbexpress;IndyCore;OrpheusDBDR;vclx;dsnap;emsclient;DataSnapCommon;FireDACCommon;RESTBackendComponents;DataSnapConnectors;VCLRESTComponents;soapserver;vclie;bindengine;DBXMySQLDriver;CloudService;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;RosiDBSorters_DX101;FireDACCommonODBC;FireDACCommonDriver;DataSnapClient;inet;IndyIPCommon;bindcompdbx;vcl;IndyIPServer;DBXSybaseASEDriver;IndySystem;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;TeeDB;FireDAC;RosiDBComp_DX101;emshosting;FireDACSqliteDriver;FireDACPgDriver;ibmonitor;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;soaprtl;DbxCommonDriver;ibxpress;Tee;DataSnapServer;xmlrtl;soapmidas;DataSnapNativeClient;fmxobj;vclwinx;FireDACDSDriver;rtl;ibxbindings;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;SynEditDR;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;TeeUI;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;inetdbxpress;FireDACMongoDBDriver;PowerPDFDR;DataSnapServerMidas;$(DCC_UsePackage) + cxPivotGridChartRS17;JvMM;dxSkinSevenRS17;dxSkinBlueprintRS17;dxSkinHighContrastRS17;dxSkinOffice2007BlackRS17;dxCoreRS17;cxPageControldxBarPopupMenuRS17;dxSkinXmas2008BlueRS17;dxPSDBTeeChartRS17;JvCrypt;dxPSTeeChartRS17;dxSkinSummer2008RS17;dxPScxSchedulerLnkRS17;dxSkinBlueRS17;dxSkinDarkRoomRS17;DBXInterBaseDriver;DataSnapServer;DataSnapCommon;dxPScxTLLnkRS17;JvNet;dxRibbonRS17;DbxCommonDriver;cxDataRS17;vclimg;dxSkinsdxBarPainterRS17;dxPSdxDBTVLnkRS17;dbxcds;DatasnapConnectorsFreePascal;NxDBGridDsgn_dxe3;dxSkinMoneyTwinsRS17;vcldb;cxExportRS17;dxPSCoreRS17;dxBarExtItemsRS17;dxGDIPlusRS17;dxNavBarRS17;CustomIPTransport;cxLibraryRS17;cxGridRS17;dxSkinOffice2010BlackRS17;dsnap;IndyIPServer;IndyCore;dxSkinMcSkinRS17;dxPScxCommonRS17;AnyDAC_PhysDb2_D17;dxSkinsdxDLPainterRS17;dxSkiniMaginaryRS17;JvDB;dxPScxVGridLnkRS17;dxSkinSevenClassicRS17;dxPScxExtCommonRS17;dxPScxSSLnkRS17;NxGridRun_dxe3;dxSkinLilianRS17;dxPSdxLCLnkRS17;dxSkinOffice2010BlueRS17;NxCommonRun_dxe3;bindcompfmx;dxSkinOffice2010SilverRS17;cxSchedulerGridRS17;dbrtl;bindcomp;inetdb;JvPluginSystem;dxBarRS17;DBXOdbcDriver;JvCmp;dxBarDBNavRS17;dxSkinWhiteprintRS17;JvTimeFramework;xmlrtl;dxSkinsdxRibbonPainterRS17;ibxpress;dxDockingRS17;vclactnband;bindengine;soaprtl;dxADOServerModeRS17;bindcompvcl;dxBarExtDBItemsRS17;dxPSPrVwRibbonRS17;vclie;dxSkinOffice2007PinkRS17;cxPageControlRS17;dxSkinscxPCPainterRS17;AnyDAC_PhysADS_D17;AnyDAC_PhysIB_D17;dxmdsRS17;dxSkinTheAsphaltWorldRS17;DBXInformixDriver;dxPsPrVwAdvRS17;NxInspectorRun_dxe3;dxSkinSilverRS17;dxdborRS17;dsnapcon;DBXFirebirdDriver;inet;JvPascalInterpreter;vclx;dxSkinStardustRS17;cxEditorsRS17;DBXSybaseASADriver;NxInspectorDsgn_dxe3;dbexpress;IndyIPClient;AnyDAC_PhysMySQL_D17;cxTreeListdxBarPopupMenuRS17;dxSkinVS2010RS17;NxGridDsgn_dxe3;dxThemeRS17;DBXSqliteDriver;dxPScxGridLnkRS17;fmx;JvDlgs;IndySystem;TeeDB;dxSkinValentineRS17;vclib;DataSnapClient;dxSkinDevExpressStyleRS17;DataSnapProviderClient;DBXSybaseASEDriver;cxBarEditItemRS17;AnyDAC_PhysMSAcc_D17;dxServerModeRS17;cxPivotGridOLAPRS17;cxSchedulerRS17;AnyDAC_PhysSQLITE_D17;dxPSLnksRS17;dxSkinPumpkinRS17;dxPSdxDBOCLnkRS17;cxVerticalGridRS17;dxSkinSpringTimeRS17;vcldsnap;dxSkinDevExpressDarkStyleRS17;DBXDb2Driver;AnyDAC_ComI_D17;DBXOracleDriver;AnyDAC_PhysMSSQL_D17;JvCore;NxDBGridRun_dxe3;AnyDAC_Comp_D17;cxSpreadSheetRS17;dxSkinLiquidSkyRS17;AnyDAC_PhysODBC_D17;fmxase;vcl;dxSkinOffice2007SilverRS17;AnyDAC_PhysPg_D17;IndyIPCommon;DBXMSSQLDriver;dxPSdxOCLnkRS17;dcldxSkinsCoreRS17;JvAppFrm;AnyDAC_PhysASA_D17;inetdbxpress;webdsnap;NxCollectionRun_dxe3;AnyDAC_PhysOracle_D17;dxSkinCoffeeRS17;adortl;dxSkinscxSchedulerPainterRS17;JvWizards;NxCollectionDsgn_dxe3;NxCommonDsgn_dxe3;dxtrmdRS17;dxPScxPCProdRS17;AnyDAC_GUIxForms_D17;JvBands;rtl;DbxClientDriver;AnyDAC_PhysTDBX_D17;dxTabbedMDIRS17;dxComnRS17;dxSkinSharpPlusRS17;dxSkinsCoreRS17;dxSkinLondonLiquidSkyRS17;dxdbtrRS17;Tee;NxAddonsRun_dxe3;JvSystem;dxorgcRS17;dxSkinBlackRS17;JvControls;NxSheetRun_dxe3;IndyProtocols;DBXMySQLDriver;dxLayoutControlRS17;bindcompdbx;TeeUI;JvJans;JvPrintPreview;JvPageComps;JvStdCtrls;JvCustom;dxSkinOffice2007BlueRS17;dxPScxPivotGridLnkRS17;dxSpellCheckerRS17;vcltouch;dxSkinOffice2007GreenRS17;dxSkinSharpRS17;websnap;dxSkinFoggyRS17;dxTileControlRS17;VclSmp;dxSkinDarkSideRS17;cxPivotGridRS17;DataSnapConnectors;AnyDAC_Phys_D17;fmxobj;SynEdit_RXE3;cxTreeListRS17;dxPSdxFCLnkRS17;dxSkinGlassOceansRS17;dxFlowChartRS17;fmxdae;dxSkinsdxNavBarPainterRS17;DataSnapIndy10ServerTransport;dxDBXServerModeRS17;dxSkinCaramelRS17;$(DCC_UsePackage) DEBUG;$(DCC_Define) @@ -75,9 +74,9 @@ true - (None) + 3 + true 1033 - CompanyName=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductVersion=1.0.0.0;Comments=;ProgramID=com.embarcadero.$(MSBuildProjectName);FileDescription=$(MSBuildProjectName);ProductName=$(MSBuildProjectName) false @@ -90,18 +89,12 @@ MainSource - - -
MyWebModule
- dfm + +
WebModule1
TWebModule
- - - - Cfg_2 - Base - + + Base @@ -109,26 +102,65 @@ Cfg_1 Base + + Cfg_2 + Base + Delphi.Personality.12 - Console + + + False + False + 1 + 0 + 0 + 0 + False + False + False + False + False + 1040 + 1252 + + + + + 1.0.0.0 + + + + + + 1.0.0.0 + + + + + + + + + + - CustomAuthServer.dpr + FiltersSamples.dpr - Embarcadero C++Builder Office 2000 Servers Package - Embarcadero C++Builder Office XP Servers Package - Microsoft Office 2000 Sample Automation Server Wrapper Components - Microsoft Office XP Sample Automation Server Wrapper Components + Embarcadero C++Builder Office 2000 Servers Package + Embarcadero C++Builder Office XP Servers Package + Microsoft Office 2000 Sample Automation Server Wrapper Components + Microsoft Office XP Sample Automation Server Wrapper Components - - + + - CustomAuthServer.exe + FiltersSamples.exe true @@ -140,14 +172,14 @@ 0 - + classes - 1 + 64 classes - 1 + 64 @@ -268,6 +300,16 @@ 1 + + + res\drawable-xxxhdpi + 1 + + + res\drawable-xxxhdpi + 1 + + res\drawable-ldpi @@ -428,6 +470,10 @@ 1 .framework + + 1 + .framework + 0 @@ -441,6 +487,10 @@ 1 .dylib + + 1 + .dylib + 0 .dll;.bpl @@ -455,7 +505,7 @@ 1 .dylib - + 1 .dylib @@ -467,6 +517,10 @@ 1 .dylib + + 1 + .dylib + 0 .bpl @@ -485,7 +539,7 @@ 0 - + 0 @@ -494,512 +548,11 @@ 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 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset - 1 - - - ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 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 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset - 1 - - - ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset - 1 - - - - - 1 - - - 1 - - - 1 - - - - - ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset - 1 - - - ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 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 + + 0 @@ -1010,31 +563,6 @@ 1 - - - ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF - 1 - - - ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF - 1 - - - - - - - - - 1 - - - 1 - - - 1 - - @@ -1047,6 +575,10 @@ Contents\Resources 1 + + Contents\Resources + 1 + @@ -1063,7 +595,7 @@ 1 - + 1 @@ -1075,6 +607,9 @@ 1 + + 1 + 0 @@ -1093,6 +628,34 @@ 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + + + + 1 + + + 1 + + + 1 + + Assets @@ -1113,16 +676,217 @@ 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\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 + + - - + + + + + + + + + True diff --git a/samples/custom_filters/MiddlewareSample1.pas b/samples/custom_filters/MiddlewareSample1.pas new file mode 100644 index 00000000..4d999ff5 --- /dev/null +++ b/samples/custom_filters/MiddlewareSample1.pas @@ -0,0 +1,48 @@ +unit MiddlewareSample1; + +interface + +uses + MVCFramework, MVCFramework.Logger; + +type + TMVCSalutationControllerFilter = class(TCustomControllerFilter) + protected + procedure DoFilter(const Context: TWebContext; const Router: IMVCRouter); override; + end; + + TMVCRedirectAndroidToPlayStoreProtocolFilter = class(TCustomProtocolFilter) + protected + procedure DoFilter(Context: TWebContext); override; + end; + +implementation + +uses + System.SysUtils, MVCFramework.Commons; + +{ TMVCSalutationControllerFilter } + +procedure TMVCSalutationControllerFilter.DoFilter(const Context: TWebContext; + const Router: IMVCRouter); +begin + DoNext(Context, Router); + Context.Response.CustomHeaders.Values['X-PROUD-HEADER'] := + 'Proudly served by DelphiMVCFramework (https://github.com/danieleteti/delphimvcframework)'; +end; + +procedure TMVCRedirectAndroidToPlayStoreProtocolFilter.DoFilter(Context: TWebContext); +begin + Log(Context.Request.Headers['User-Agent']); + if Context.Request.Headers['User-Agent'].Contains('Android') then + begin + Context.Response.Location := 'http://play.google.com'; + Context.Response.StatusCode := HTTP_STATUS.TemporaryRedirect; // 307 - temporary redirect + end + else + begin + DoNext(Context); + end; +end; + +end. diff --git a/samples/middleware/WebModuleUnit1.dfm b/samples/custom_filters/WebModuleUnit1.dfm similarity index 84% rename from samples/middleware/WebModuleUnit1.dfm rename to samples/custom_filters/WebModuleUnit1.dfm index b43b8558..2c58d387 100644 --- a/samples/middleware/WebModuleUnit1.dfm +++ b/samples/custom_filters/WebModuleUnit1.dfm @@ -1,12 +1,11 @@ -object WebModule1: TWebModule1 - OldCreateOrder = False - OnCreate = WebModuleCreate - Actions = < - item - Default = True - Name = 'DefaultHandler' - PathInfo = '/' - end> - Height = 230 - Width = 415 -end +object WebModule1: TWebModule1 + OnCreate = WebModuleCreate + Actions = < + item + Default = True + Name = 'DefaultHandler' + PathInfo = '/' + end> + Height = 230 + Width = 415 +end diff --git a/samples/middleware/WebModuleUnit1.pas b/samples/custom_filters/WebModuleUnit1.pas similarity index 81% rename from samples/middleware/WebModuleUnit1.pas rename to samples/custom_filters/WebModuleUnit1.pas index 63f2e42c..3d22ddce 100644 --- a/samples/middleware/WebModuleUnit1.pas +++ b/samples/custom_filters/WebModuleUnit1.pas @@ -1,46 +1,46 @@ -unit WebModuleUnit1; - -interface - -uses System.SysUtils, - System.Classes, - Web.HTTPApp, - MVCFramework, - MVCFramework.Commons; - -type - TWebModule1 = class(TWebModule) - procedure WebModuleCreate(Sender: TObject); - - private - MVC: TMVCEngine; - - public - { Public declarations } - end; - -var - WebModuleClass: TComponentClass = TWebModule1; - -implementation - -{$R *.dfm} - - -uses AppControllerU, MiddlewareSample1; - -procedure TWebModule1.WebModuleCreate(Sender: TObject); -begin - MVC := TMVCEngine.Create(Self, - procedure(Config: TMVCConfig) - begin - Config[TMVCConfigKey.SessionTimeout] := '30'; - Config[TMVCConfigKey.DefaultContentType] := 'text/plain'; - end); - MVC - .AddController(TApp1MainController) - .AddMiddleware(TMVCSalutationMiddleware.Create) - .AddMiddleware(TMVCRedirectAndroidDeviceOnPlayStore.Create); -end; - -end. +unit WebModuleUnit1; + +interface + +uses System.SysUtils, + System.Classes, + Web.HTTPApp, + MVCFramework, + MVCFramework.Commons; + +type + TWebModule1 = class(TWebModule) + procedure WebModuleCreate(Sender: TObject); + + private + MVC: TMVCEngine; + + public + { Public declarations } + end; + +var + WebModuleClass: TComponentClass = TWebModule1; + +implementation + +{$R *.dfm} + + +uses AppControllerU, MiddlewareSample1; + +procedure TWebModule1.WebModuleCreate(Sender: TObject); +begin + MVC := TMVCEngine.Create(Self, + procedure(Config: TMVCConfig) + begin + Config[TMVCConfigKey.SessionTimeout] := '30'; + Config[TMVCConfigKey.DefaultContentType] := 'text/plain'; + end); + MVC + .AddController(TApp1MainController) + .UseFilter(TMVCSalutationControllerFilter.Create) + .UseFilter(TMVCRedirectAndroidToPlayStoreProtocolFilter.Create); +end; + +end. diff --git a/samples/jsonwriterrenders/WebModuleU.dfm b/samples/jsonwriterrenders/WebModuleU.dfm index 018d0670..02d66b97 100644 --- a/samples/jsonwriterrenders/WebModuleU.dfm +++ b/samples/jsonwriterrenders/WebModuleU.dfm @@ -1,5 +1,4 @@ object MyWebModule: TMyWebModule - OldCreateOrder = False OnCreate = WebModuleCreate OnDestroy = WebModuleDestroy Actions = <> diff --git a/samples/jsonwriterrenders/WebModuleU.pas b/samples/jsonwriterrenders/WebModuleU.pas index 640883d0..e6008d78 100644 --- a/samples/jsonwriterrenders/WebModuleU.pas +++ b/samples/jsonwriterrenders/WebModuleU.pas @@ -27,7 +27,7 @@ implementation uses MVCFramework.Commons, JSONSampleController, - MVCFramework.Middleware.StaticFiles; + MVCFramework.Filters.StaticFiles; procedure TMyWebModule.WebModuleCreate(Sender: TObject); begin @@ -50,7 +50,7 @@ begin Config[TMVCConfigKey.ExposeServerSignature] := 'true'; end); FMVC.AddController(TMyController); - FMVC.AddMiddleware(TMVCStaticFilesMiddleware.Create( + FMVC.UseFilter(TMVCStaticFilesProtocolFilter.Create( '/', { StaticFilesPath } ExtractFilePath(GetModuleName(HInstance)) + '\www', { DocumentRoot } 'index.html' {IndexDocument - Before it was named fallbackresource} diff --git a/samples/jsonwriterrenders/jsonwriterrenders.dpr b/samples/jsonwriterrenders/jsonwriterrenders.dpr index ec3f7a74..7bf6add2 100644 --- a/samples/jsonwriterrenders/jsonwriterrenders.dpr +++ b/samples/jsonwriterrenders/jsonwriterrenders.dpr @@ -3,6 +3,8 @@ program jsonwriterrenders; {$APPTYPE CONSOLE} uses + MVCFramework, + MVCFramework.Signal, System.SysUtils, Winapi.Windows, Winapi.ShellAPI, @@ -16,9 +18,6 @@ uses procedure RunServer(APort: Integer); var - LInputRecord: TInputRecord; - LEvent: DWord; - LHandle: THandle; LServer: TIdHTTPWebBrokerBridge; begin Writeln('** DMVCFramework Server **'); @@ -28,16 +27,9 @@ begin LServer.DefaultPort := APort; LServer.Active := True; ShellExecute(0, 'open', pChar('http://localhost:' + inttostr(APort)), nil, nil, SW_SHOWMAXIMIZED); - Writeln('Press ESC to stop the server'); - LHandle := GetStdHandle(STD_INPUT_HANDLE); - while True do - begin - Win32Check(ReadConsoleInput(LHandle, LInputRecord, 1, LEvent)); - if (LInputRecord.EventType = KEY_EVENT) and - LInputRecord.Event.KeyEvent.bKeyDown and - (LInputRecord.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE) then - break; - end; + Writeln('CTRL+C to stop the server'); + WaitForTerminationSignal; + EnterInShutdownState; finally LServer.Free; end; diff --git a/samples/jsonwriterrenders/jsonwriterrenders.dproj b/samples/jsonwriterrenders/jsonwriterrenders.dproj index 32c53715..2424229a 100644 --- a/samples/jsonwriterrenders/jsonwriterrenders.dproj +++ b/samples/jsonwriterrenders/jsonwriterrenders.dproj @@ -1,7 +1,7 @@  {7C5074B2-1E72-4389-9D91-79D38F8551E7} - 18.8 + 19.5 VCL jsonwriterrenders.dpr True @@ -93,13 +93,8 @@
MyWebModule
- dfm TWebModule
- - Cfg_2 - Base - Base @@ -107,6 +102,10 @@ Cfg_1 Base + + Cfg_2 + Base + Delphi.Personality.12 @@ -123,13 +122,8 @@ Microsoft Office XP Sample Automation Server Wrapper Components - - - - jsonwriterrenders.exe - true - - + + 1 @@ -138,14 +132,14 @@ 0 - + classes - 1 + 64 classes - 1 + 64 @@ -266,6 +260,16 @@ 1 + + + res\drawable-xxxhdpi + 1 + + + res\drawable-xxxhdpi + 1 + + res\drawable-ldpi @@ -426,6 +430,10 @@ 1 .framework + + 1 + .framework + 0 @@ -439,6 +447,10 @@ 1 .dylib + + 1 + .dylib + 0 .dll;.bpl @@ -453,7 +465,7 @@ 1 .dylib - + 1 .dylib @@ -465,6 +477,10 @@ 1 .dylib + + 1 + .dylib + 0 .bpl @@ -483,7 +499,7 @@ 0 - + 0 @@ -492,316 +508,11 @@ 0 - + 0 - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 - - - - - 1 - - - 1 - - - 1 + + 0 @@ -812,30 +523,6 @@ 1 - - - ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF - 1 - - - ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF - 1 - - - - - - - - 1 - - - 1 - - - 1 - - @@ -848,6 +535,10 @@ Contents\Resources 1 + + Contents\Resources + 1 + @@ -864,7 +555,7 @@ 1 - + 1 @@ -876,6 +567,9 @@ 1 + + 1 + 0 @@ -894,6 +588,34 @@ 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + + + + 1 + + + 1 + + + 1 + + Assets @@ -914,16 +636,218 @@ 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\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 + + - - + + + + + + + + + + True diff --git a/samples/middleware/MiddlewareSample1.pas b/samples/middleware/MiddlewareSample1.pas deleted file mode 100644 index 9f4a9255..00000000 --- a/samples/middleware/MiddlewareSample1.pas +++ /dev/null @@ -1,89 +0,0 @@ -unit MiddlewareSample1; - -interface - -uses - MVCFramework, MVCFramework.Logger; - -type - TMVCSalutationMiddleware = class(TInterfacedObject, IMVCMiddleware) - protected - procedure OnBeforeRouting(Context: TWebContext; var Handled: Boolean); - procedure OnBeforeControllerAction(Context: TWebContext; - const AControllerQualifiedClassName: string; const AActionNAme: string; var Handled: Boolean); - procedure OnAfterRouting(Context: TWebContext; const AHandled: Boolean); - procedure OnAfterControllerAction(Context: TWebContext; const AControllerQualifiedClassName: string; const AActionName: string; const AHandled: Boolean); - end; - - TMVCRedirectAndroidDeviceOnPlayStore = class(TInterfacedObject, IMVCMiddleware) - protected - procedure OnBeforeRouting(Context: TWebContext; var Handled: Boolean); - procedure OnBeforeControllerAction(Context: TWebContext; - const AControllerQualifiedClassName: string; const AActionNAme: string; var Handled: Boolean); - procedure OnAfterRouting(AContext: TWebContext; const AHandled: Boolean); - procedure OnAfterControllerAction(AContext: TWebContext; const AControllerQualifiedClassName: string; const AActionName: string; const AHandled: Boolean); - end; - -implementation - -uses - System.SysUtils, MVCFramework.Commons; - -{ TMVCSalutationMiddleware } - -procedure TMVCSalutationMiddleware.OnAfterControllerAction( - Context: TWebContext; const AControllerQualifiedClassName: string; - const AActionName: string; const AHandled: Boolean); -begin - Context.Response.CustomHeaders.Values['X-PROUD-HEADER'] := - 'Proudly served by DelphiMVCFramework (https://github.com/danieleteti/delphimvcframework)'; -end; - -procedure TMVCRedirectAndroidDeviceOnPlayStore.OnAfterControllerAction( - AContext: TWebContext; const AControllerQualifiedClassName: string; - const AActionName: string; const AHandled: Boolean); -begin - // do nothing -end; - -procedure TMVCRedirectAndroidDeviceOnPlayStore.OnAfterRouting(AContext: TWebContext; const AHandled: Boolean); -begin - // do nothing -end; - -procedure TMVCRedirectAndroidDeviceOnPlayStore.OnBeforeControllerAction( - Context: TWebContext; const AControllerQualifiedClassName, - AActionNAme: string; var Handled: Boolean); -begin - // do nothing -end; - -procedure TMVCRedirectAndroidDeviceOnPlayStore.OnBeforeRouting(Context: TWebContext; - var Handled: Boolean); -begin - Log(Context.Request.Headers['User-Agent']); - if Context.Request.Headers['User-Agent'].Contains('Android') then - begin - Context.Response.Location := 'http://play.google.com'; - Context.Response.StatusCode := HTTP_STATUS.TemporaryRedirect; // 307 - temporary redirect - Handled := True; - end; -end; - -procedure TMVCSalutationMiddleware.OnAfterRouting(Context: TWebContext; const AHandled: Boolean); -begin - // do nothing -end; - -procedure TMVCSalutationMiddleware.OnBeforeControllerAction(Context: TWebContext; - const AControllerQualifiedClassName, AActionNAme: string; var Handled: Boolean); -begin - // do nothing -end; - -procedure TMVCSalutationMiddleware.OnBeforeRouting(Context: TWebContext; var Handled: Boolean); -begin - // do nothing -end; - -end. diff --git a/samples/middleware/MiddlewareSamples.dproj b/samples/middleware/MiddlewareSamples.dproj deleted file mode 100644 index 71fd1f50..00000000 --- a/samples/middleware/MiddlewareSamples.dproj +++ /dev/null @@ -1,171 +0,0 @@ - - - {0388D146-2B8B-427B-AEDD-EFD5F51D3139} - 19.5 - VCL - MiddlewareSamples.dpr - True - Debug - Win32 - 1 - Console - - - true - - - true - Base - true - - - true - Base - true - - - true - Base - true - - - true - Cfg_1 - true - true - - - true - Base - true - - - $(BDS)\bin\delphi_PROJECTICNS.icns - MiddlewareSamples - ..\..\sources;..\..\lib\delphistompclient;..\..\lib\loggerpro;..\..\lib\dmustache;$(DCC_UnitSearchPath) - CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments= - None - 1040 - $(BDS)\bin\delphi_PROJECTICON.ico - System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) - .\$(Platform)\$(Config) - .\$(Platform)\$(Config) - false - false - false - false - false - - - Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) - 1033 - cxPivotGridChartRS17;JvMM;dxSkinSevenRS17;dxSkinBlueprintRS17;dxSkinHighContrastRS17;dxSkinOffice2007BlackRS17;dxCoreRS17;cxPageControldxBarPopupMenuRS17;dxSkinXmas2008BlueRS17;dxPSDBTeeChartRS17;JvCrypt;dxPSTeeChartRS17;dxSkinSummer2008RS17;dxPScxSchedulerLnkRS17;dxSkinBlueRS17;dxSkinDarkRoomRS17;DBXInterBaseDriver;DataSnapServer;DataSnapCommon;dxPScxTLLnkRS17;JvNet;JvDotNetCtrls;dxRibbonRS17;DbxCommonDriver;cxDataRS17;vclimg;dxSkinsdxBarPainterRS17;dxPSdxDBTVLnkRS17;dbxcds;DatasnapConnectorsFreePascal;NxDBGridDsgn_dxe3;JvXPCtrls;dxSkinMoneyTwinsRS17;vcldb;cxExportRS17;dxPSCoreRS17;dxBarExtItemsRS17;dxGDIPlusRS17;FMXfrx17;dxNavBarRS17;CustomIPTransport;cxLibraryRS17;cxGridRS17;dxSkinOffice2010BlackRS17;dsnap;IndyIPServer;IndyCore;dxSkinMcSkinRS17;CloudService;dxPScxCommonRS17;FmxTeeUI;frxDB17;AnyDAC_PhysDb2_D17;dxSkinsdxDLPainterRS17;dxSkiniMaginaryRS17;JvDB;JvRuntimeDesign;dxPScxVGridLnkRS17;JclDeveloperTools;dxSkinSevenClassicRS17;dxPScxExtCommonRS17;MyFrameTestPackage;dxPScxSSLnkRS17;NxGridRun_dxe3;dxSkinLilianRS17;fs17;dxPSdxLCLnkRS17;dxSkinOffice2010BlueRS17;NxCommonRun_dxe3;bindcompfmx;DataBindingsVCL170;dxSkinOffice2010SilverRS17;vcldbx;cxSchedulerGridRS17;dbrtl;bindcomp;inetdb;JvPluginSystem;dxBarRS17;DataBindings;DBXOdbcDriver;IcsCommonDXE3Run;JvCmp;dxBarDBNavRS17;dxSkinWhiteprintRS17;JvTimeFramework;xmlrtl;dxSkinsdxRibbonPainterRS17;ibxpress;dxDockingRS17;vclactnband;bindengine;soaprtl;FMXTee;dxADOServerModeRS17;bindcompvcl;dxBarExtDBItemsRS17;dxPSPrVwRibbonRS17;Jcl;vclie;dxSkinOffice2007PinkRS17;cxPageControlRS17;dxSkinscxPCPainterRS17;AnyDAC_PhysADS_D17;AnyDAC_PhysIB_D17;dxmdsRS17;dxSkinTheAsphaltWorldRS17;DBXInformixDriver;Intraweb;dxPsPrVwAdvRS17;NxInspectorRun_dxe3;dxSkinSilverRS17;dxdborRS17;dsnapcon;DBXFirebirdDriver;fsDB17;inet;dorm_runtime_xe3;JvPascalInterpreter;vclx;dxSkinStardustRS17;cxEditorsRS17;DBXSybaseASADriver;NxInspectorDsgn_dxe3;dbexpress;IndyIPClient;AnyDAC_PhysMySQL_D17;cxTreeListdxBarPopupMenuRS17;dxSkinVS2010RS17;NxGridDsgn_dxe3;dxThemeRS17;DBXSqliteDriver;dxPScxGridLnkRS17;fmx;JvDlgs;IndySystem;TeeDB;dxSkinValentineRS17;vclib;inetdbbde;DataSnapClient;dxSkinDevExpressStyleRS17;DataSnapProviderClient;DBXSybaseASEDriver;cxBarEditItemRS17;AnyDAC_PhysMSAcc_D17;dxServerModeRS17;cxPivotGridOLAPRS17;cxSchedulerRS17;MetropolisUILiveTile;AnyDAC_PhysSQLITE_D17;dxPSLnksRS17;dxSkinPumpkinRS17;dxPSdxDBOCLnkRS17;cxVerticalGridRS17;dxSkinSpringTimeRS17;vcldsnap;dxSkinDevExpressDarkStyleRS17;DBXDb2Driver;AnyDAC_ComI_D17;DBXOracleDriver;AnyDAC_PhysMSSQL_D17;JvCore;NxDBGridRun_dxe3;vclribbon;AnyDAC_Comp_D17;cxSpreadSheetRS17;dxSkinLiquidSkyRS17;AnyDAC_PhysODBC_D17;fmxase;vcl;dxSkinOffice2007SilverRS17;AnyDAC_PhysPg_D17;IndyIPCommon;DBXMSSQLDriver;CodeSiteExpressPkg;dxPSdxOCLnkRS17;dcldxSkinsCoreRS17;JvAppFrm;AnyDAC_PhysASA_D17;inetdbxpress;webdsnap;NxCollectionRun_dxe3;AnyDAC_PhysOracle_D17;dxSkinCoffeeRS17;JvDocking;adortl;dxSkinscxSchedulerPainterRS17;JvWizards;NxCollectionDsgn_dxe3;frx17;NxCommonDsgn_dxe3;dxtrmdRS17;dxPScxPCProdRS17;AnyDAC_GUIxForms_D17;JvBands;rtl;DbxClientDriver;AnyDAC_PhysTDBX_D17;dxTabbedMDIRS17;dxComnRS17;dxSkinSharpPlusRS17;dxSkinsCoreRS17;dxSkinLondonLiquidSkyRS17;dxdbtrRS17;Tee;JclContainers;NxAddonsRun_dxe3;CPortLibDXE;JvSystem;dxorgcRS17;svnui;dxSkinBlackRS17;JvControls;NxSheetRun_dxe3;IndyProtocols;DBXMySQLDriver;dxLayoutControlRS17;bindcompdbx;TeeUI;JvJans;JvPrintPreview;JvPageComps;JvStdCtrls;JvCustom;dxSkinOffice2007BlueRS17;dxPScxPivotGridLnkRS17;dxSpellCheckerRS17;vcltouch;dxSkinOffice2007GreenRS17;dxSkinSharpRS17;websnap;dxSkinFoggyRS17;dxTileControlRS17;VclSmp;FMXfrxDB17;dxSkinDarkSideRS17;cxPivotGridRS17;DataSnapConnectors;AnyDAC_Phys_D17;fmxobj;SynEdit_RXE3;JclVcl;cxTreeListRS17;dxPSdxFCLnkRS17;dxSkinGlassOceansRS17;frxe17;svn;dxFlowChartRS17;fmxdae;dxSkinsdxNavBarPainterRS17;bdertl;VirtualTreesR;DataSnapIndy10ServerTransport;dxDBXServerModeRS17;dxSkinCaramelRS17;$(DCC_UsePackage) - .\bin - - - cxPivotGridChartRS17;JvMM;dxSkinSevenRS17;dxSkinBlueprintRS17;dxSkinHighContrastRS17;dxSkinOffice2007BlackRS17;dxCoreRS17;cxPageControldxBarPopupMenuRS17;dxSkinXmas2008BlueRS17;dxPSDBTeeChartRS17;JvCrypt;dxPSTeeChartRS17;dxSkinSummer2008RS17;dxPScxSchedulerLnkRS17;dxSkinBlueRS17;dxSkinDarkRoomRS17;DBXInterBaseDriver;DataSnapServer;DataSnapCommon;dxPScxTLLnkRS17;JvNet;dxRibbonRS17;DbxCommonDriver;cxDataRS17;vclimg;dxSkinsdxBarPainterRS17;dxPSdxDBTVLnkRS17;dbxcds;DatasnapConnectorsFreePascal;NxDBGridDsgn_dxe3;dxSkinMoneyTwinsRS17;vcldb;cxExportRS17;dxPSCoreRS17;dxBarExtItemsRS17;dxGDIPlusRS17;dxNavBarRS17;CustomIPTransport;cxLibraryRS17;cxGridRS17;dxSkinOffice2010BlackRS17;dsnap;IndyIPServer;IndyCore;dxSkinMcSkinRS17;dxPScxCommonRS17;AnyDAC_PhysDb2_D17;dxSkinsdxDLPainterRS17;dxSkiniMaginaryRS17;JvDB;dxPScxVGridLnkRS17;dxSkinSevenClassicRS17;dxPScxExtCommonRS17;dxPScxSSLnkRS17;NxGridRun_dxe3;dxSkinLilianRS17;dxPSdxLCLnkRS17;dxSkinOffice2010BlueRS17;NxCommonRun_dxe3;bindcompfmx;dxSkinOffice2010SilverRS17;cxSchedulerGridRS17;dbrtl;bindcomp;inetdb;JvPluginSystem;dxBarRS17;DBXOdbcDriver;JvCmp;dxBarDBNavRS17;dxSkinWhiteprintRS17;JvTimeFramework;xmlrtl;dxSkinsdxRibbonPainterRS17;ibxpress;dxDockingRS17;vclactnband;bindengine;soaprtl;dxADOServerModeRS17;bindcompvcl;dxBarExtDBItemsRS17;dxPSPrVwRibbonRS17;vclie;dxSkinOffice2007PinkRS17;cxPageControlRS17;dxSkinscxPCPainterRS17;AnyDAC_PhysADS_D17;AnyDAC_PhysIB_D17;dxmdsRS17;dxSkinTheAsphaltWorldRS17;DBXInformixDriver;dxPsPrVwAdvRS17;NxInspectorRun_dxe3;dxSkinSilverRS17;dxdborRS17;dsnapcon;DBXFirebirdDriver;inet;JvPascalInterpreter;vclx;dxSkinStardustRS17;cxEditorsRS17;DBXSybaseASADriver;NxInspectorDsgn_dxe3;dbexpress;IndyIPClient;AnyDAC_PhysMySQL_D17;cxTreeListdxBarPopupMenuRS17;dxSkinVS2010RS17;NxGridDsgn_dxe3;dxThemeRS17;DBXSqliteDriver;dxPScxGridLnkRS17;fmx;JvDlgs;IndySystem;TeeDB;dxSkinValentineRS17;vclib;DataSnapClient;dxSkinDevExpressStyleRS17;DataSnapProviderClient;DBXSybaseASEDriver;cxBarEditItemRS17;AnyDAC_PhysMSAcc_D17;dxServerModeRS17;cxPivotGridOLAPRS17;cxSchedulerRS17;AnyDAC_PhysSQLITE_D17;dxPSLnksRS17;dxSkinPumpkinRS17;dxPSdxDBOCLnkRS17;cxVerticalGridRS17;dxSkinSpringTimeRS17;vcldsnap;dxSkinDevExpressDarkStyleRS17;DBXDb2Driver;AnyDAC_ComI_D17;DBXOracleDriver;AnyDAC_PhysMSSQL_D17;JvCore;NxDBGridRun_dxe3;AnyDAC_Comp_D17;cxSpreadSheetRS17;dxSkinLiquidSkyRS17;AnyDAC_PhysODBC_D17;fmxase;vcl;dxSkinOffice2007SilverRS17;AnyDAC_PhysPg_D17;IndyIPCommon;DBXMSSQLDriver;dxPSdxOCLnkRS17;dcldxSkinsCoreRS17;JvAppFrm;AnyDAC_PhysASA_D17;inetdbxpress;webdsnap;NxCollectionRun_dxe3;AnyDAC_PhysOracle_D17;dxSkinCoffeeRS17;adortl;dxSkinscxSchedulerPainterRS17;JvWizards;NxCollectionDsgn_dxe3;NxCommonDsgn_dxe3;dxtrmdRS17;dxPScxPCProdRS17;AnyDAC_GUIxForms_D17;JvBands;rtl;DbxClientDriver;AnyDAC_PhysTDBX_D17;dxTabbedMDIRS17;dxComnRS17;dxSkinSharpPlusRS17;dxSkinsCoreRS17;dxSkinLondonLiquidSkyRS17;dxdbtrRS17;Tee;NxAddonsRun_dxe3;JvSystem;dxorgcRS17;dxSkinBlackRS17;JvControls;NxSheetRun_dxe3;IndyProtocols;DBXMySQLDriver;dxLayoutControlRS17;bindcompdbx;TeeUI;JvJans;JvPrintPreview;JvPageComps;JvStdCtrls;JvCustom;dxSkinOffice2007BlueRS17;dxPScxPivotGridLnkRS17;dxSpellCheckerRS17;vcltouch;dxSkinOffice2007GreenRS17;dxSkinSharpRS17;websnap;dxSkinFoggyRS17;dxTileControlRS17;VclSmp;dxSkinDarkSideRS17;cxPivotGridRS17;DataSnapConnectors;AnyDAC_Phys_D17;fmxobj;SynEdit_RXE3;cxTreeListRS17;dxPSdxFCLnkRS17;dxSkinGlassOceansRS17;dxFlowChartRS17;fmxdae;dxSkinsdxNavBarPainterRS17;DataSnapIndy10ServerTransport;dxDBXServerModeRS17;dxSkinCaramelRS17;$(DCC_UsePackage) - - - DEBUG;$(DCC_Define) - true - false - true - true - true - - - 3 - true - 1033 - false - - - false - RELEASE;$(DCC_Define) - 0 - 0 - - - - MainSource - - -
WebModule1
- TWebModule -
- - - - Base - - - Cfg_1 - Base - - - Cfg_2 - Base - -
- - Delphi.Personality.12 - - - - - False - False - 1 - 0 - 0 - 0 - False - False - False - False - False - 1040 - 1252 - - - - - 1.0.0.0 - - - - - - 1.0.0.0 - - - - - - - - - - - - MiddlewareSamples.dpr - - - Embarcadero C++Builder Office 2000 Servers Package - Embarcadero C++Builder Office XP Servers Package - Microsoft Office 2000 Sample Automation Server Wrapper Components - Microsoft Office XP Sample Automation Server Wrapper Components - - - - - True - False - - - 12 - - - - -
diff --git a/sources/MVCFramework.Filters.Action.pas b/sources/MVCFramework.Filters.Action.pas index 97b6cba6..fa74374b 100644 --- a/sources/MVCFramework.Filters.Action.pas +++ b/sources/MVCFramework.Filters.Action.pas @@ -6,7 +6,7 @@ uses MVCFramework, MVCFramework.Router, MVCFramework.Commons, System.RTTI; type - TMVCActionControllerFilter = class(TControllerFilter) + TMVCActionControllerFilter = class(TCustomControllerFilter) private const ALLOWED_TYPED_ACTION_PARAMETERS_TYPES = 'Integer, Int64, Single, Double, Extended, Boolean, TDate, TTime, TDateTime, String and TGUID'; diff --git a/sources/MVCFramework.Filters.Authentication.RoleBasedAuthHandler.pas b/sources/MVCFramework.Filters.Authentication.RoleBasedAuthHandler.pas index 53f9d050..fb9e18ba 100644 --- a/sources/MVCFramework.Filters.Authentication.RoleBasedAuthHandler.pas +++ b/sources/MVCFramework.Filters.Authentication.RoleBasedAuthHandler.pas @@ -86,20 +86,6 @@ type destructor Destroy; override; end; -// TMVCRoleBasedAuthMiddleware = class(TMVCCustomAuthenticationMiddleware, IMVCMiddleware) -// private -// fAuthenticationHandler: IMVCRoleBasedAuthenticationHandler; -// procedure DoRoleBasedBeforeControllerAction(const AContext: TWebContext; -// const aHandler: IMVCRoleBasedAuthenticationHandler; const AControllerQualifiedClassName: string; -// const AActionName: string; var AHandled: Boolean); -// protected -// procedure OnBeforeControllerAction(AContext: TWebContext; const AControllerQualifiedClassName: string; -// const AActionName: string; var AHandled: Boolean); override; -// public -// constructor Create(const AAuthenticationHandler: IMVCAuthenticationHandler; -// const ALoginUrl: string = '/system/users/logged'); override; -// end; - implementation uses @@ -306,80 +292,4 @@ begin end; end; -{ TMVCRoleBasedAuthMiddleware } - -//constructor TMVCRoleBasedAuthMiddleware.Create(const AAuthenticationHandler: IMVCAuthenticationHandler; -// const ALoginUrl: string); -//begin -// inherited Create(AAuthenticationHandler, ALoginUrl); -// Supports(AAuthenticationHandler, IMVCRoleBasedAuthenticationHandler, fAuthenticationHandler); -//end; - -//procedure TMVCRoleBasedAuthMiddleware.DoRoleBasedBeforeControllerAction(const AContext: TWebContext; -// const aHandler: IMVCRoleBasedAuthenticationHandler; const AControllerQualifiedClassName: string; -// const AActionName: string; var AHandled: Boolean); -//var -// IsValid: Boolean; -// IsAuthorized: Boolean; -// AuthRequired: Boolean; -//begin -// // This procedure is a basic copy of the inherited OnBeforeControllerAction procedure. -// // Extention is by enabling the Authorization based on the context the call is being performed. -// aHandler.OnRequest(nil, AControllerQualifiedClassName, AActionName, AuthRequired); -// if not AuthRequired then -// begin -// AHandled := False; -// Exit; -// end; -// -// AContext.LoggedUser.LoadFromSession(AContext.Session); -// IsValid := AContext.LoggedUser.IsValid; -// if not IsValid then -// begin -// AContext.SessionStop(False); -// SendResponse(AContext, AHandled); -// Exit; -// end; -// -// IsAuthorized := False; -// -// // Modification here from: -// // FAuthenticationHandler.OnAuthorization(AContext.LoggedUser.Roles, AControllerQualifiedClassName, AActionName, IsAuthorized); -// // to: -// aHandler.OnAuthorization(AContext, AContext.LoggedUser.Roles, AControllerQualifiedClassName, AActionName, -// IsAuthorized); -// // Modification end -// -// if IsAuthorized then -// begin -// AHandled := False; -// end -// else -// begin -// if IsValid then -// begin -// SendResponse(AContext, AHandled, HTTP_STATUS.Forbidden) -// end -// else -// begin -// SendResponse(AContext, AHandled, HTTP_STATUS.Unauthorized); -// end; -// end; -//end; - -//procedure TMVCRoleBasedAuthMiddleware.OnBeforeControllerAction(AContext: TWebContext; -// const AControllerQualifiedClassName, AActionName: string; var AHandled: Boolean); -//begin -// if Assigned(fAuthenticationHandler) then -// begin -// DoRoleBasedBeforeControllerAction(AContext, fAuthenticationHandler, AControllerQualifiedClassName, -// AActionName, AHandled) -// end -// else -// begin -// inherited OnBeforeControllerAction(AContext, AControllerQualifiedClassName, AActionName, AHandled); -// end; -//end; - - end. diff --git a/sources/MVCFramework.Filters.Authentication.pas b/sources/MVCFramework.Filters.Authentication.pas index 46ccbb51..b2cf4e86 100644 --- a/sources/MVCFramework.Filters.Authentication.pas +++ b/sources/MVCFramework.Filters.Authentication.pas @@ -39,7 +39,7 @@ uses type - TMVCBasicAuthenticationControllerFilter = class(TControllerFilter) + TMVCBasicAuthenticationControllerFilter = class(TCustomControllerFilter) private FAuthenticationHandler: IMVCAuthenticationHandler; FRealm: string; @@ -52,43 +52,6 @@ type ); virtual; end; - TMVCCustomAuthenticationMiddleware = class(TInterfacedObject, IMVCMiddleware) - private - FAuthenticationHandler: IMVCAuthenticationHandler; - FLoginUrl: string; - protected - procedure OnBeforeRouting( - AContext: TWebContext; - var AHandled: Boolean - ); - - procedure OnBeforeControllerAction( - AContext: TWebContext; - const AControllerQualifiedClassName: string; - const AActionName: string; - var AHandled: Boolean - ); virtual; - - procedure OnAfterControllerAction( - AContext: TWebContext; - const AControllerQualifiedClassName: string; const AActionName: string; - const AHandled: Boolean); - - procedure OnAfterRouting( - AContext: TWebContext; - const AHandled: Boolean - ); - - procedure SendResponse(AContext: TWebContext; var AHandled: Boolean; AHttpStatus: Word = HTTP_STATUS.Unauthorized); - procedure DoLogin(AContext: TWebContext; var AHandled: Boolean); - procedure DoLogout(AContext: TWebContext; var AHandled: Boolean); - public - constructor Create( - const AAuthenticationHandler: IMVCAuthenticationHandler; - const ALoginUrl: string = '/system/users/logged' - ); virtual; - end; - implementation const @@ -252,331 +215,4 @@ begin end; end; -//procedure TMVCBasicAuthenticationControllerFilter.OnBeforeControllerAction( -// AContext: TWebContext; -// const AControllerQualifiedClassName, AActionName: string; -// var AHandled: Boolean); -// -// procedure SendWWWAuthenticate; -// begin -// AContext.LoggedUser.Clear; -// if AContext.Request.ClientAcceptHTML then -// begin -// AContext.Response.ContentType := TMVCMediaType.TEXT_HTML; -// AContext.Response.RawWebResponse.Content := -// Format(CONTENT_HTML_FORMAT, [CONTENT_401_NOT_AUTHORIZED, AContext.Config[TMVCConfigKey.ServerName]]); -// end -// else -// begin -// AContext.Response.ContentType := TMVCMediaType.TEXT_PLAIN; -// AContext.Response.RawWebResponse.Content := CONTENT_401_NOT_AUTHORIZED + sLineBreak + AContext.Config -// [TMVCConfigKey.ServerName]; -// end; -// AContext.Response.StatusCode := HTTP_STATUS.Unauthorized; -// AContext.Response.SetCustomHeader('WWW-Authenticate', 'Basic realm=' + QuotedStr(FRealm)); -// AContext.SessionStop(False); -// AHandled := True; -// end; -// -// procedure Send403Forbidden; -// begin -// AContext.LoggedUser.Clear; -// if AContext.Request.ClientAcceptHTML then -// begin -// AContext.Response.ContentType := TMVCMediaType.TEXT_HTML; -// AContext.Response.RawWebResponse.Content := -// Format(CONTENT_HTML_FORMAT, [CONTENT_403_FORBIDDEN, AContext.Config[TMVCConfigKey.ServerName]]); -// end -// else if AContext.Request.ContentMediaType.StartsWith(TMVCMediaType.APPLICATION_JSON) then -// begin -// AContext.Response.ContentType := TMVCMediaType.APPLICATION_JSON; -// AContext.Response.RawWebResponse.Content := -// '{"status":"error", "message":"' + CONTENT_403_FORBIDDEN.Replace('"', '\"') + '"}'; -// end -// else -// begin -// AContext.Response.ContentType := TMVCMediaType.TEXT_PLAIN; -// AContext.Response.RawWebResponse.Content := CONTENT_403_FORBIDDEN + sLineBreak + AContext.Config -// [TMVCConfigKey.ServerName]; -// end; -// AContext.Response.StatusCode := HTTP_STATUS.Forbidden; -// AContext.Response.ReasonString := AContext.Config[TMVCConfigKey.ServerName]; -// AHandled := True; -// end; -// -//var -// AuthRequired: Boolean; -// IsValid, IsAuthorized: Boolean; -// AuthHeader, Token: string; -// AuthPieces: TArray; -// RolesList: TList; -// SessionData: TSessionData; -// SessionPair: TPair; -//begin -// FAuthenticationHandler.OnRequest(AContext, AControllerQualifiedClassName, AActionName, AuthRequired); -// if not AuthRequired then -// begin -// AHandled := False; -// Exit; -// end; -// -// AContext.LoggedUser.LoadFromSession(AContext.Session); -// IsValid := AContext.LoggedUser.IsValid; -// if not IsValid then -// begin -// AuthHeader := AContext.Request.Headers['Authorization']; -// if AuthHeader.IsEmpty or (not AuthHeader.StartsWith('Basic ', True)) then -// begin -// SendWWWAuthenticate; -// Exit; -// end; -// Token := AuthHeader.Remove(0, 'Basic '.Length).Trim; -// AuthHeader := TMVCSerializerHelper.DecodeString(Token); -// AuthPieces := AuthHeader.Split([':']); -// if Length(AuthPieces) <> 2 then -// begin -// SendWWWAuthenticate; -// Exit; -// end; -// -// RolesList := TList.Create; -// try -// SessionData := TSessionData.Create; -// try -// FAuthenticationHandler.OnAuthentication(AContext, AuthPieces[0], AuthPieces[1], RolesList, IsValid, -// SessionData); -// if IsValid then -// begin -// AContext.LoggedUser.Roles.AddRange(RolesList); -// AContext.LoggedUser.UserName := AuthPieces[0]; -// AContext.LoggedUser.LoggedSince := Now; -// AContext.LoggedUser.Realm := FRealm; -// AContext.LoggedUser.SaveToSession(AContext.Session); -// for SessionPair in SessionData do -// AContext.Session[SessionPair.Key] := SessionPair.Value; -// end; -// finally -// SessionData.Free; -// end; -// finally -// RolesList.Free; -// end; -// end; -// -// IsAuthorized := False; -// if IsValid then -// FAuthenticationHandler.OnAuthorization(AContext, AContext.LoggedUser.Roles, AControllerQualifiedClassName, -// AActionName, IsAuthorized); -// -// if IsAuthorized then -// AHandled := False -// else -// begin -// if IsValid then -// Send403Forbidden -// else -// begin -// SendWWWAuthenticate; -// end; -// end; -//end; - -{ TMVCCustomAuthenticationMiddleware } - -constructor TMVCCustomAuthenticationMiddleware.Create( - const AAuthenticationHandler: IMVCAuthenticationHandler; - const ALoginUrl: string); -begin - inherited Create; - FAuthenticationHandler := AAuthenticationHandler; - FLoginUrl := ALoginUrl.ToLower; -end; - -procedure TMVCCustomAuthenticationMiddleware.DoLogin( - AContext: TWebContext; - var AHandled: Boolean); -var - Jo: TJSONObject; - UserName, Password: string; - RolesList: TList; - SessionPair: TPair; - SessionData: TSessionData; - IsValid: Boolean; -begin - AContext.SessionStop(False); - AContext.LoggedUser.Clear; - if not AContext.Request.ThereIsRequestBody then - begin - AHandled := True; - AContext.Response.StatusCode := HTTP_STATUS.BadRequest; - AContext.Response.ContentType := TMVCMediaType.APPLICATION_JSON; - AContext.Response.RawWebResponse.Content := - '{"status":"error", "message":"username and password are mandatory in the body request as json object"}'; - Exit; - end; - - Jo := TJSONObject.ParseJSONValue(AContext.Request.Body) as TJSONObject; - try - if not Assigned(Jo) then - begin - AHandled := True; - SendResponse(AContext, AHandled, HTTP_STATUS.BadRequest); - Exit; - end; - - UserName := EmptyStr; - if (Jo.Get('username') <> nil) then - UserName := Jo.Get('username').JsonValue.Value; - - Password := EmptyStr; - if (Jo.Get('password') <> nil) then - Password := Jo.Get('password').JsonValue.Value; - - if UserName.IsEmpty or Password.IsEmpty then - begin - AHandled := True; - SendResponse(AContext, AHandled); - Exit; - end; - - RolesList := TList.Create; - try - SessionData := TSessionData.Create; - try - IsValid := False; - FAuthenticationHandler.OnAuthentication(AContext, UserName, Password, RolesList, IsValid, SessionData); - if not IsValid then - begin - SendResponse(AContext, AHandled); - Exit; - end; - - AContext.LoggedUser.Roles.AddRange(RolesList); - AContext.LoggedUser.UserName := UserName; - AContext.LoggedUser.LoggedSince := Now; - AContext.LoggedUser.Realm := 'custom'; - AContext.LoggedUser.SaveToSession(AContext.Session); - - for SessionPair in SessionData do - AContext.Session[SessionPair.Key] := SessionPair.Value; - - AContext.Response.StatusCode := HTTP_STATUS.OK; - AContext.Response.CustomHeaders.Values['X-LOGOUT-URL'] := FLoginUrl; - AContext.Response.CustomHeaders.Values['X-LOGOUT-METHOD'] := 'DELETE'; - AContext.Response.ContentType := TMVCMediaType.APPLICATION_JSON; - AContext.Response.RawWebResponse.Content := '{"status":"OK"}'; - - AHandled := True; - finally - SessionData.Free; - end; - finally - RolesList.Free; - end; - finally - Jo.Free; - end; -end; - -procedure TMVCCustomAuthenticationMiddleware.DoLogout( - AContext: TWebContext; var AHandled: Boolean); -begin - AContext.SessionStop(False); - SendResponse(AContext, AHandled, HTTP_STATUS.OK); -end; - -procedure TMVCCustomAuthenticationMiddleware.OnAfterControllerAction( - AContext: TWebContext; - const AControllerQualifiedClassName: string; const AActionName: string; - const AHandled: Boolean); -begin - // Implement as needed -end; - -procedure TMVCCustomAuthenticationMiddleware.OnAfterRouting(AContext: TWebContext; const AHandled: Boolean); -begin - -end; - -procedure TMVCCustomAuthenticationMiddleware.OnBeforeControllerAction( - AContext: TWebContext; - const AControllerQualifiedClassName, AActionName: string; - var AHandled: Boolean); -var - IsValid: Boolean; - IsAuthorized: Boolean; - AuthRequired: Boolean; -begin - FAuthenticationHandler.OnRequest(AContext, AControllerQualifiedClassName, AActionName, AuthRequired); - if not AuthRequired then - begin - AHandled := False; - Exit; - end; - - AContext.LoggedUser.LoadFromSession(AContext.Session); - IsValid := AContext.LoggedUser.IsValid; - if not IsValid then - begin - AContext.SessionStop(False); - SendResponse(AContext, AHandled); - Exit; - end; - - IsAuthorized := False; - FAuthenticationHandler.OnAuthorization(AContext, AContext.LoggedUser.Roles, AControllerQualifiedClassName, - AActionName, IsAuthorized); - if IsAuthorized then - AHandled := False - else - begin - if IsValid then - SendResponse(AContext, AHandled, HTTP_STATUS.Forbidden) - else - SendResponse(AContext, AHandled, HTTP_STATUS.Unauthorized); - end; -end; - -procedure TMVCCustomAuthenticationMiddleware.OnBeforeRouting( - AContext: TWebContext; var AHandled: Boolean); -begin - if (AContext.Request.PathInfo.ToLower = FLoginUrl) then - begin - AHandled := False; - - if (AContext.Request.HTTPMethod = httpPOST) and - (AContext.Request.ContentType.StartsWith(TMVCMediaType.APPLICATION_JSON)) then - DoLogin(AContext, AHandled); - - if (AContext.Request.HTTPMethod = httpDELETE) then - DoLogout(AContext, AHandled); - end; -end; - -procedure TMVCCustomAuthenticationMiddleware.SendResponse( - AContext: TWebContext; var AHandled: Boolean; AHttpStatus: Word); -var - IsPositive: Boolean; - Msg: string; -begin - AContext.LoggedUser.Clear; - AContext.Response.CustomHeaders.Values['X-LOGIN-URL'] := FLoginUrl; - AContext.Response.CustomHeaders.Values['X-LOGIN-METHOD'] := 'POST'; - AContext.Response.StatusCode := AHttpStatus; - if AContext.Request.ClientAcceptHTML then - begin - AContext.Response.ContentType := TMVCMediaType.TEXT_HTML; - AContext.Response.RawWebResponse.Content := - Format(CONTENT_HTML_FORMAT, [IntToStr(AHttpStatus), AContext.Config[TMVCConfigKey.ServerName]]); - end - else - begin - IsPositive := (AHttpStatus div 100) = 2; - Msg := IfThen(IsPositive, 'OK', 'KO'); - AContext.Response.ContentType := TMVCMediaType.APPLICATION_JSON; - AContext.Response.RawWebResponse.Content := '{"status":"' + Msg + '", "message":"' + IntToStr(AHttpStatus) + '"}'; - end; - AHandled := True; -end; - end. diff --git a/sources/MVCFramework.Filters.Compression.pas b/sources/MVCFramework.Filters.Compression.pas index a59dd275..f1acc5c4 100644 --- a/sources/MVCFramework.Filters.Compression.pas +++ b/sources/MVCFramework.Filters.Compression.pas @@ -33,7 +33,7 @@ uses MVCFramework.Logger; type - TMVCCompressionProtocolFilter = class(TProtocolFilter) + TMVCCompressionProtocolFilter = class(TCustomProtocolFilter) private fCompressionThreshold: Integer; protected diff --git a/sources/MVCFramework.Filters.JWT.pas b/sources/MVCFramework.Filters.JWT.pas index 48c3381f..52820221 100644 --- a/sources/MVCFramework.Filters.JWT.pas +++ b/sources/MVCFramework.Filters.JWT.pas @@ -65,7 +65,7 @@ type TJWTClaimsSetup = reference to procedure(const JWT: TJWT); - TMVCJWTProtocolFilter = class(TProtocolFilter) + TMVCJWTProtocolFilter = class(TCustomProtocolFilter) private FAuthenticationHandler: IMVCAuthenticationHandler; FClaimsToChecks: TJWTCheckableClaims; @@ -88,7 +88,7 @@ type procedure OnAfterRegistration(Engine: TMVCEngine); override; type - TMVCJWTControllerFilter = class(TControllerFilter) + TMVCJWTControllerFilter = class(TCustomControllerFilter) protected FAuthorizationHeaderName: string; FAuthorizationAccessToken: string; @@ -124,7 +124,7 @@ type var AAccepted: Boolean); TMVCOnNewJWTToBlackList = reference to procedure(AContext: TWebContext; AJWTToken: String); - TMVCJWTBlackListProtocolFilter = class(TProtocolFilter) + TMVCJWTBlackListProtocolFilter = class(TCustomProtocolFilter) private fOnAcceptToken: TMVCOnAcceptTokenProc; fOnNewJWTToBlackList: TMVCOnNewJWTToBlackList; diff --git a/sources/MVCFramework.Filters.Router.pas b/sources/MVCFramework.Filters.Router.pas index d3db4c30..b3dd690a 100644 --- a/sources/MVCFramework.Filters.Router.pas +++ b/sources/MVCFramework.Filters.Router.pas @@ -42,7 +42,7 @@ type end; - TMVCRouterFilter = class(TProtocolFilter) + TMVCRouterFilter = class(TCustomProtocolFilter) private fEngine: TMVCEngine; fConfig: TMVCConfig; diff --git a/sources/MVCFramework.Filters.StaticFiles.pas b/sources/MVCFramework.Filters.StaticFiles.pas index e0e924f9..55d7a25b 100644 --- a/sources/MVCFramework.Filters.StaticFiles.pas +++ b/sources/MVCFramework.Filters.StaticFiles.pas @@ -58,7 +58,7 @@ type TMVCStaticFileRulesProc = reference to procedure(const Context: TWebContext; var PathInfo: String; var Handled: Boolean); TMVCStaticFileMediaTypesCustomizer = reference to procedure(const MediaTypes: TMVCStringDictionary); - TMVCStaticFilesProtocolFilter = class(TProtocolFilter) + TMVCStaticFilesProtocolFilter = class(TCustomProtocolFilter) private fSanityCheckOK: Boolean; fMediaTypes: TMVCStringDictionary; diff --git a/sources/MVCFramework.pas b/sources/MVCFramework.pas index 5b94966f..1c87726e 100644 --- a/sources/MVCFramework.pas +++ b/sources/MVCFramework.pas @@ -982,7 +982,7 @@ type function Build(const Engine: TMVCEngine): IControllerFilterChain; end; - TProtocolFilter = class abstract(TInterfacedObject, IProtocolFilter) + TCustomProtocolFilter = class abstract(TInterfacedObject, IProtocolFilter) private fNext: IProtocolFilter; protected @@ -1016,7 +1016,7 @@ type function Build(const Engine: TMVCEngine): IControllerFilterChain; end; - TControllerFilter = class abstract(TInterfacedObject, IControllerFilter) + TCustomControllerFilter = class abstract(TInterfacedObject, IControllerFilter) private fNext: IControllerFilter; fEngine: TMVCEngine; @@ -3904,7 +3904,7 @@ end; { TFilter } -procedure TProtocolFilter.DoNext(Context: TWebContext); +procedure TCustomProtocolFilter.DoNext(Context: TWebContext); begin if Assigned(fNext) then begin @@ -3912,12 +3912,12 @@ begin end; end; -procedure TProtocolFilter.OnAfterRegistration(Engine: TMVCEngine); +procedure TCustomProtocolFilter.OnAfterRegistration(Engine: TMVCEngine); begin //do nothing end; -procedure TProtocolFilter.SetNext(NextFilter: IProtocolFilter); +procedure TCustomProtocolFilter.SetNext(NextFilter: IProtocolFilter); begin fNext := NextFilter; end; @@ -3996,9 +3996,9 @@ begin Result := Self; end; -{ TControllerFilter } +{ TCustomControllerFilter } -procedure TControllerFilter.DoNext( +procedure TCustomControllerFilter.DoNext( Context: TWebContext; const Router: IMVCRouter); begin @@ -4008,17 +4008,17 @@ begin end; end; -function TControllerFilter.GetEngine: TMVCEngine; +function TCustomControllerFilter.GetEngine: TMVCEngine; begin Result := fEngine; end; -procedure TControllerFilter.SetEngine(const Engine: TMVCEngine); +procedure TCustomControllerFilter.SetEngine(const Engine: TMVCEngine); begin fEngine := Engine; end; -procedure TControllerFilter.SetNext(NextFilter: IControllerFilter); +procedure TCustomControllerFilter.SetNext(NextFilter: IControllerFilter); begin fNext := NextFilter; end; diff --git a/unittests/general/Several/LiveServerTestU.pas b/unittests/general/Several/LiveServerTestU.pas index 85de1478..1169cf19 100644 --- a/unittests/general/Several/LiveServerTestU.pas +++ b/unittests/general/Several/LiveServerTestU.pas @@ -179,16 +179,16 @@ type [Test] procedure TestBasicAuth05; // test authentication/authorization with CustomAuth - [Test] - procedure TestCustomAuthRequestWithoutLogin; - [Test] - procedure TestCustomAuthRequestsWithValidLogin; - [Test] - procedure TestCustomAuthRequestsWithValidLogin_HTML; - [Test] - procedure TestCustomAuthWrongRequestBodies; - [Test] - procedure TestCustomAuthLoginLogout; +// [Test] +// procedure TestCustomAuthRequestWithoutLogin; +// [Test] +// procedure TestCustomAuthRequestsWithValidLogin; +// [Test] +// procedure TestCustomAuthRequestsWithValidLogin_HTML; +// [Test] +// procedure TestCustomAuthWrongRequestBodies; +// [Test] +// procedure TestCustomAuthLoginLogout; // typed actions [Test] @@ -713,125 +713,125 @@ begin end; -procedure TServerTest.TestCustomAuthRequestWithoutLogin; -var - lRes: IMVCRESTResponse; -begin - lRes := RESTClient.Get('/privatecustom/role1'); - Assert.areEqual(HTTP_STATUS.Unauthorized, lRes.StatusCode); - Assert.areEqual('/system/users/logged', lRes.HeaderValue('X-LOGIN-URL')); - Assert.areEqual('POST', lRes.HeaderValue('X-LOGIN-METHOD')); +//procedure TServerTest.TestCustomAuthRequestWithoutLogin; +//var +// lRes: IMVCRESTResponse; +//begin +// lRes := RESTClient.Get('/privatecustom/role1'); +// Assert.areEqual(HTTP_STATUS.Unauthorized, lRes.StatusCode); +// Assert.areEqual('/system/users/logged', lRes.HeaderValue('X-LOGIN-URL')); +// Assert.areEqual('POST', lRes.HeaderValue('X-LOGIN-METHOD')); +// +// lRes := RESTClient.Get('/privatecustom/role2'); +// Assert.areEqual(HTTP_STATUS.Unauthorized, lRes.StatusCode); +// Assert.areEqual('/system/users/logged', lRes.HeaderValue('X-LOGIN-URL')); +// Assert.areEqual('POST', lRes.HeaderValue('X-LOGIN-METHOD')); +//end; - lRes := RESTClient.Get('/privatecustom/role2'); - Assert.areEqual(HTTP_STATUS.Unauthorized, lRes.StatusCode); - Assert.areEqual('/system/users/logged', lRes.HeaderValue('X-LOGIN-URL')); - Assert.areEqual('POST', lRes.HeaderValue('X-LOGIN-METHOD')); -end; +//procedure TServerTest.TestCustomAuthRequestsWithValidLogin; +//var +// lRes: IMVCRESTResponse; +// lJSON: System.JSON.TJSONObject; +// lCookieValue: string; +//begin +// lJSON := System.JSON.TJSONObject.Create; +// try +// lJSON.AddPair('username', 'user1'); +// lJSON.AddPair('password', 'user1'); +// lRes := RESTClient.Post('/system/users/logged', TSystemJSON.JSONValueToString(lJSON, false)); +// Assert.areEqual('application/json', lRes.ContentType); +// Assert.areEqual(HTTP_STATUS.OK, lRes.StatusCode); +// Assert.areEqual('/system/users/logged', lRes.HeaderValue('X-LOGOUT-URL')); +// Assert.areEqual('DELETE', lRes.HeaderValue('X-LOGOUT-METHOD')); +// Assert.areEqual('{"status":"OK"}', lRes.Content); +// lCookieValue := lRes.CookieByName(TMVCConstants.SESSION_TOKEN_NAME).Value; +// Assert.AreNotEqual('', lCookieValue, 'Session cookie not returned after login'); +// Assert.IsFalse(lCookieValue.Contains('invalid'), 'Returned an invalid session token'); +// +// lRes := RESTClient.Get('/privatecustom/role2'); +// Assert.areEqual(HTTP_STATUS.Forbidden, lRes.StatusCode, +// 'Authorization not respected for not allowed action'); +// +// lRes := RESTClient.Get('/privatecustom/role1'); +// Assert.areEqual(HTTP_STATUS.OK, lRes.StatusCode, +// 'Authorization not respected for allowed action'); +// finally +// lJSON.Free; +// end; +//end; -procedure TServerTest.TestCustomAuthRequestsWithValidLogin; -var - lRes: IMVCRESTResponse; - lJSON: System.JSON.TJSONObject; - lCookieValue: string; -begin - lJSON := System.JSON.TJSONObject.Create; - try - lJSON.AddPair('username', 'user1'); - lJSON.AddPair('password', 'user1'); - lRes := RESTClient.Post('/system/users/logged', TSystemJSON.JSONValueToString(lJSON, false)); - Assert.areEqual('application/json', lRes.ContentType); - Assert.areEqual(HTTP_STATUS.OK, lRes.StatusCode); - Assert.areEqual('/system/users/logged', lRes.HeaderValue('X-LOGOUT-URL')); - Assert.areEqual('DELETE', lRes.HeaderValue('X-LOGOUT-METHOD')); - Assert.areEqual('{"status":"OK"}', lRes.Content); - lCookieValue := lRes.CookieByName(TMVCConstants.SESSION_TOKEN_NAME).Value; - Assert.AreNotEqual('', lCookieValue, 'Session cookie not returned after login'); - Assert.IsFalse(lCookieValue.Contains('invalid'), 'Returned an invalid session token'); +//procedure TServerTest.TestCustomAuthRequestsWithValidLogin_HTML; +//var +// lRes: IMVCRESTResponse; +// lJSON: System.JSON.TJSONObject; +// lCookieValue: string; +// lContentType: string; +// lContentCharset: string; +//begin +// lJSON := System.JSON.TJSONObject.Create; +// try +// lJSON.AddPair('username', 'user1'); +// lJSON.AddPair('password', 'user1'); +// lRes := RESTClient.Accept('text/html').Post('/system/users/logged', +// TSystemJSON.JSONValueToString(lJSON, false)); +// SplitContentMediaTypeAndCharset(lRes.ContentType, lContentType, lContentCharset); +// Assert.areEqual(lContentType, TMVCMediaType.APPLICATION_JSON); +// Assert.areEqual(HTTP_STATUS.OK, lRes.StatusCode); +// Assert.areEqual('/system/users/logged', lRes.HeaderValue('X-LOGOUT-URL')); +// Assert.areEqual('DELETE', lRes.HeaderValue('X-LOGOUT-METHOD')); +// Assert.areEqual('{"status":"OK"}', lRes.Content); +// lCookieValue := lRes.CookieByName(TMVCConstants.SESSION_TOKEN_NAME).Value; +// Assert.AreNotEqual('', lCookieValue, 'Session cookie not returned after login'); +// Assert.IsFalse(lCookieValue.Contains('invalid'), 'Returned an invalid session token'); +// +// lRes := RESTClient.Get('/privatecustom/role2'); +// Assert.areEqual(HTTP_STATUS.Forbidden, lRes.StatusCode, +// 'Authorization not respected for not allowed action'); +// +// lRes := RESTClient.Get('/privatecustom/role1'); +// Assert.areEqual(HTTP_STATUS.OK, lRes.StatusCode, +// 'Authorization not respected for allowed action'); +// finally +// lJSON.Free; +// end; +//end; - lRes := RESTClient.Get('/privatecustom/role2'); - Assert.areEqual(HTTP_STATUS.Forbidden, lRes.StatusCode, - 'Authorization not respected for not allowed action'); - - lRes := RESTClient.Get('/privatecustom/role1'); - Assert.areEqual(HTTP_STATUS.OK, lRes.StatusCode, - 'Authorization not respected for allowed action'); - finally - lJSON.Free; - end; -end; - -procedure TServerTest.TestCustomAuthRequestsWithValidLogin_HTML; -var - lRes: IMVCRESTResponse; - lJSON: System.JSON.TJSONObject; - lCookieValue: string; - lContentType: string; - lContentCharset: string; -begin - lJSON := System.JSON.TJSONObject.Create; - try - lJSON.AddPair('username', 'user1'); - lJSON.AddPair('password', 'user1'); - lRes := RESTClient.Accept('text/html').Post('/system/users/logged', - TSystemJSON.JSONValueToString(lJSON, false)); - SplitContentMediaTypeAndCharset(lRes.ContentType, lContentType, lContentCharset); - Assert.areEqual(lContentType, TMVCMediaType.APPLICATION_JSON); - Assert.areEqual(HTTP_STATUS.OK, lRes.StatusCode); - Assert.areEqual('/system/users/logged', lRes.HeaderValue('X-LOGOUT-URL')); - Assert.areEqual('DELETE', lRes.HeaderValue('X-LOGOUT-METHOD')); - Assert.areEqual('{"status":"OK"}', lRes.Content); - lCookieValue := lRes.CookieByName(TMVCConstants.SESSION_TOKEN_NAME).Value; - Assert.AreNotEqual('', lCookieValue, 'Session cookie not returned after login'); - Assert.IsFalse(lCookieValue.Contains('invalid'), 'Returned an invalid session token'); - - lRes := RESTClient.Get('/privatecustom/role2'); - Assert.areEqual(HTTP_STATUS.Forbidden, lRes.StatusCode, - 'Authorization not respected for not allowed action'); - - lRes := RESTClient.Get('/privatecustom/role1'); - Assert.areEqual(HTTP_STATUS.OK, lRes.StatusCode, - 'Authorization not respected for allowed action'); - finally - lJSON.Free; - end; -end; - -procedure TServerTest.TestCustomAuthWrongRequestBodies; -var - lRes: IMVCRESTResponse; - lJSON: System.JSON.TJSONObject; -begin - lJSON := System.JSON.TJSONObject.Create; - try - // no request body - lRes := RESTClient.AddBody('', TMVCMediaType.APPLICATION_JSON).Post('/system/users/logged'); - Assert.areEqual(HTTP_STATUS.BadRequest, lRes.StatusCode, - 'Empty request body doesn''t return HTTP 400 Bad Request'); - - // wrong request body 1 - lRes := RESTClient.Post('/system/users/logged', TSystemJSON.JSONValueToString(lJSON, false)); - Assert.areEqual(HTTP_STATUS.Unauthorized, lRes.StatusCode, - 'Invalid json doesn''t return HTTP 401 Unauthorized'); - - // wrong request body 2 - lJSON.AddPair('username', ''); - lJSON.AddPair('password', ''); - lRes := RESTClient.Post('/system/users/logged', TSystemJSON.JSONValueToString(lJSON, false)); - Assert.areEqual(HTTP_STATUS.Unauthorized, lRes.StatusCode, - 'Empty username and password doesn''t return HTTP 401 Unauthorized'); - - // wrong username and password 3 - lJSON.RemovePair('username').Free; - lJSON.RemovePair('password').Free; - lJSON.AddPair('username', 'notvaliduser'); - lJSON.AddPair('password', 'notvalidpassword'); - lRes := RESTClient.Post('/system/users/logged', TSystemJSON.JSONValueToString(lJSON, false)); - Assert.areEqual(HTTP_STATUS.Unauthorized, lRes.StatusCode, - 'Wrong username and password doesn''t return HTTP 401 Unauthorized'); - finally - lJSON.Free; - end; -end; +//procedure TServerTest.TestCustomAuthWrongRequestBodies; +//var +// lRes: IMVCRESTResponse; +// lJSON: System.JSON.TJSONObject; +//begin +// lJSON := System.JSON.TJSONObject.Create; +// try +// // no request body +// lRes := RESTClient.AddBody('', TMVCMediaType.APPLICATION_JSON).Post('/system/users/logged'); +// Assert.areEqual(HTTP_STATUS.BadRequest, lRes.StatusCode, +// 'Empty request body doesn''t return HTTP 400 Bad Request'); +// +// // wrong request body 1 +// lRes := RESTClient.Post('/system/users/logged', TSystemJSON.JSONValueToString(lJSON, false)); +// Assert.areEqual(HTTP_STATUS.Unauthorized, lRes.StatusCode, +// 'Invalid json doesn''t return HTTP 401 Unauthorized'); +// +// // wrong request body 2 +// lJSON.AddPair('username', ''); +// lJSON.AddPair('password', ''); +// lRes := RESTClient.Post('/system/users/logged', TSystemJSON.JSONValueToString(lJSON, false)); +// Assert.areEqual(HTTP_STATUS.Unauthorized, lRes.StatusCode, +// 'Empty username and password doesn''t return HTTP 401 Unauthorized'); +// +// // wrong username and password 3 +// lJSON.RemovePair('username').Free; +// lJSON.RemovePair('password').Free; +// lJSON.AddPair('username', 'notvaliduser'); +// lJSON.AddPair('password', 'notvalidpassword'); +// lRes := RESTClient.Post('/system/users/logged', TSystemJSON.JSONValueToString(lJSON, false)); +// Assert.areEqual(HTTP_STATUS.Unauthorized, lRes.StatusCode, +// 'Wrong username and password doesn''t return HTTP 401 Unauthorized'); +// finally +// lJSON.Free; +// end; +//end; procedure TServerTest.TestCustomerEcho; var @@ -995,38 +995,38 @@ begin end; end; -procedure TServerTest.TestCustomAuthLoginLogout; -var - lRes: IMVCRESTResponse; - lJSON: System.JSON.TJSONObject; - lLogoutUrl: string; - lPass: boolean; - lCookie: TCookie; -begin - lJSON := System.JSON.TJSONObject.Create; - try - lJSON.AddPair('username', 'user1'); - lJSON.AddPair('password', 'user1'); - lRes := RESTClient.Post('/system/users/logged', TSystemJSON.JSONValueToString(lJSON, false)); - - Assert.areEqual(HTTP_STATUS.OK, lRes.StatusCode); - lLogoutUrl := lRes.HeaderValue('X-LOGOUT-URL'); - - lRes := RESTClient.Delete(lLogoutUrl); - lPass := false; - for lCookie in lRes.Cookies do - begin - if lCookie.Value.Contains('invalid') then - begin - lPass := true; - Break; - end; - end; - Assert.isTrue(lPass, 'No session cookie cleanup in the response'); - finally - lJSON.Free; - end; -end; +//procedure TServerTest.TestCustomAuthLoginLogout; +//var +// lRes: IMVCRESTResponse; +// lJSON: System.JSON.TJSONObject; +// lLogoutUrl: string; +// lPass: boolean; +// lCookie: TCookie; +//begin +// lJSON := System.JSON.TJSONObject.Create; +// try +// lJSON.AddPair('username', 'user1'); +// lJSON.AddPair('password', 'user1'); +// lRes := RESTClient.Post('/system/users/logged', TSystemJSON.JSONValueToString(lJSON, false)); +// +// Assert.areEqual(HTTP_STATUS.OK, lRes.StatusCode); +// lLogoutUrl := lRes.HeaderValue('X-LOGOUT-URL'); +// +// lRes := RESTClient.Delete(lLogoutUrl); +// lPass := false; +// for lCookie in lRes.Cookies do +// begin +// if lCookie.Value.Contains('invalid') then +// begin +// lPass := true; +// Break; +// end; +// end; +// Assert.isTrue(lPass, 'No session cookie cleanup in the response'); +// finally +// lJSON.Free; +// end; +//end; procedure TServerTest.TestEchoWithAllVerbs; var diff --git a/unittests/general/TestServer/SpeedProtocolFilterU.pas b/unittests/general/TestServer/SpeedProtocolFilterU.pas index 76b64ddc..6d36f93a 100644 --- a/unittests/general/TestServer/SpeedProtocolFilterU.pas +++ b/unittests/general/TestServer/SpeedProtocolFilterU.pas @@ -30,7 +30,7 @@ uses MVCFramework; type - TSpeedProtocolFilter = class(TProtocolFilter) + TSpeedProtocolFilter = class(TCustomProtocolFilter) protected procedure DoFilter(Context: TWebContext); override; end; diff --git a/unittests/general/TestServer/WebModuleUnit.pas b/unittests/general/TestServer/WebModuleUnit.pas index 0c347431..4c2f72a8 100644 --- a/unittests/general/TestServer/WebModuleUnit.pas +++ b/unittests/general/TestServer/WebModuleUnit.pas @@ -133,7 +133,6 @@ begin end) .UseFilter(TMVCBasicAuthenticationControllerFilter.Create(TBasicAuthHandler.Create)) .UseFilter(TSpeedProtocolFilter.Create) -// .UseFilter(TMVCCustomAuthenticationMiddleware.Create(TCustomAuthHandler.Create, '/system/users/logged')) .UseFilter(TMVCStaticFilesProtocolFilter.Create('/static', 'www', 'index.html', False)) .UseFilter(TMVCStaticFilesProtocolFilter.Create('/spa', 'www', 'index.html', True)) .UseFilter(TMVCCompressionProtocolFilter.Create);