2021-02-04 14:11:33 +01:00
|
|
|
|
// ***************************************************************************
|
2016-06-22 17:49:16 +02:00
|
|
|
|
//
|
|
|
|
|
// Delphi MVC Framework
|
|
|
|
|
//
|
2021-02-04 14:11:33 +01:00
|
|
|
|
// Copyright (c) 2010-2021 Daniele Teti and the DMVCFramework Team
|
2016-06-22 17:49:16 +02:00
|
|
|
|
//
|
|
|
|
|
// https://github.com/danieleteti/delphimvcframework
|
|
|
|
|
//
|
2021-02-03 13:21:01 +01:00
|
|
|
|
// Collaborators with this file: Ezequiel Juliano Müller (ezequieljuliano@gmail.com)
|
2017-03-23 18:51:25 +01:00
|
|
|
|
//
|
2016-06-22 17:49:16 +02:00
|
|
|
|
// ***************************************************************************
|
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
//
|
|
|
|
|
// ***************************************************************************
|
2016-06-16 22:18:18 +02:00
|
|
|
|
|
2016-06-16 22:13:35 +02:00
|
|
|
|
unit MVCFramework.Server.Impl;
|
|
|
|
|
|
2017-03-23 18:51:25 +01:00
|
|
|
|
{$I dmvcframework.inc}
|
|
|
|
|
|
2016-06-16 22:13:35 +02:00
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
System.SysUtils,
|
|
|
|
|
System.Classes,
|
|
|
|
|
System.Generics.Collections,
|
2021-02-04 14:11:33 +01:00
|
|
|
|
IdHTTPWebBrokerBridge,
|
|
|
|
|
IdSSLOpenSSL,
|
|
|
|
|
IdSSL,
|
|
|
|
|
IdContext,
|
|
|
|
|
MVCFramework.Server,
|
|
|
|
|
MVCFramework;
|
2016-06-16 22:13:35 +02:00
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
TMVCListenerProperties = class(TInterfacedObject, IMVCListenerProperties)
|
|
|
|
|
private
|
|
|
|
|
FName: string;
|
|
|
|
|
FPort: Integer;
|
|
|
|
|
FMaxConnections: Integer;
|
|
|
|
|
FWebModuleClass: TComponentClass;
|
2019-12-19 10:39:13 +01:00
|
|
|
|
FSSLCertFile: String;
|
|
|
|
|
FSSLRootCertFile: String;
|
|
|
|
|
FSSLKeyFile: String;
|
|
|
|
|
FSSLPassword: String;
|
2016-06-16 22:13:35 +02:00
|
|
|
|
protected
|
|
|
|
|
function GetName: string;
|
|
|
|
|
function SetName(const AValue: string): IMVCListenerProperties;
|
|
|
|
|
|
|
|
|
|
function GetPort: Integer;
|
|
|
|
|
function SetPort(AValue: Integer): IMVCListenerProperties;
|
|
|
|
|
|
|
|
|
|
function GetMaxConnections: Integer;
|
|
|
|
|
function SetMaxConnections(AValue: Integer): IMVCListenerProperties;
|
|
|
|
|
|
|
|
|
|
function GetWebModuleClass: TComponentClass;
|
|
|
|
|
function SetWebModuleClass(AValue: TComponentClass): IMVCListenerProperties;
|
2019-12-19 10:39:13 +01:00
|
|
|
|
|
|
|
|
|
function GetSSLOptions(out SSLCertFile, SSLRootCertFile, SSLKeyFile, SSLPassword: String): Boolean;
|
|
|
|
|
function SetSSLOptions(const SSLCertFile, SSLRootCertFile, SSLKeyFile, SSLPassword: String): IMVCListenerProperties;
|
2016-06-16 22:13:35 +02:00
|
|
|
|
public
|
|
|
|
|
constructor Create;
|
|
|
|
|
class function New: IMVCListenerProperties; static;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TMVCListener = class(TInterfacedObject, IMVCListener)
|
|
|
|
|
private
|
|
|
|
|
FBridge: TIdHTTPWebBrokerBridge;
|
2019-12-19 10:39:13 +01:00
|
|
|
|
FBridgeSSLHandler: TIdServerIOHandlerSSLOpenSSL;
|
|
|
|
|
FBridgeSSLPassword: String;
|
2019-06-06 06:54:15 +02:00
|
|
|
|
procedure OnParseAuthentication(AContext: TIdContext; const AAuthType,
|
|
|
|
|
AAuthData: String; var VUsername, VPassword: String;
|
|
|
|
|
var VHandled: Boolean);
|
2019-12-19 10:39:13 +01:00
|
|
|
|
procedure OnGetSSLPassword(var APassword: string);
|
2021-02-03 13:19:05 +01:00
|
|
|
|
procedure QuerySSLPort(APort: Word; var VUseSSL: boolean);
|
2016-06-16 22:13:35 +02:00
|
|
|
|
protected
|
|
|
|
|
function GetActive: Boolean;
|
|
|
|
|
|
|
|
|
|
procedure Start;
|
|
|
|
|
procedure Stop;
|
|
|
|
|
public
|
|
|
|
|
constructor Create(AProperties: IMVCListenerProperties);
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TMVCListenersContext = class(TInterfacedObject, IMVCListenersContext)
|
|
|
|
|
private
|
|
|
|
|
FListeners: TDictionary<string, IMVCListener>;
|
|
|
|
|
protected
|
|
|
|
|
function Add(const AName: string; AListener: IMVCListener): IMVCListenersContext; overload;
|
|
|
|
|
function Add(AProperties: IMVCListenerProperties): IMVCListenersContext; overload;
|
|
|
|
|
function Remove(const AListenerName: string): IMVCListenersContext;
|
|
|
|
|
|
|
|
|
|
procedure StartAll;
|
|
|
|
|
procedure StopAll;
|
|
|
|
|
|
|
|
|
|
function FindByName(const AListenerName: string): IMVCListener;
|
|
|
|
|
|
|
|
|
|
procedure ForEach(AProc: TProc<string, IMVCListener>);
|
|
|
|
|
function Count: Integer;
|
|
|
|
|
public
|
|
|
|
|
constructor Create;
|
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
TMVCDefaultAuthenticationHandler = class(TInterfacedObject, IMVCDefaultAuthenticationHandler)
|
|
|
|
|
private
|
|
|
|
|
FRequestDelegate: TMVCRequestDelegate;
|
|
|
|
|
FAuthenticationDelegate: TMVCAuthenticationDelegate;
|
|
|
|
|
FAuthorizationDelegate: TMVCAuthorizationDelegate;
|
|
|
|
|
protected
|
2018-12-09 23:03:06 +01:00
|
|
|
|
procedure OnRequest(
|
|
|
|
|
const AContext: TWebContext;
|
|
|
|
|
const AControllerQualifiedClassName, AActionName: string;
|
2016-09-06 10:30:52 +02:00
|
|
|
|
var AAuthenticationRequired: Boolean);
|
2016-06-16 22:13:35 +02:00
|
|
|
|
|
2017-03-23 18:51:25 +01:00
|
|
|
|
procedure OnAuthentication(
|
2018-12-09 23:03:06 +01:00
|
|
|
|
const AContext: TWebContext;
|
2017-03-23 18:51:25 +01:00
|
|
|
|
const AUserName, APassword: string;
|
|
|
|
|
AUserRoles: TList<string>;
|
2016-09-06 10:30:52 +02:00
|
|
|
|
var IsValid: Boolean;
|
|
|
|
|
const ASessionData: TDictionary<string, string>);
|
2016-06-16 22:13:35 +02:00
|
|
|
|
|
2017-03-23 18:51:25 +01:00
|
|
|
|
procedure OnAuthorization(
|
2018-12-09 23:03:06 +01:00
|
|
|
|
const AContext: TWebContext;
|
2017-03-23 18:51:25 +01:00
|
|
|
|
AUserRoles: TList<string>;
|
|
|
|
|
const AControllerQualifiedClassName: string;
|
|
|
|
|
const AActionName: string;
|
2016-06-16 22:13:35 +02:00
|
|
|
|
var IsAuthorized: Boolean);
|
|
|
|
|
public
|
|
|
|
|
class function New: IMVCDefaultAuthenticationHandler; static;
|
|
|
|
|
|
|
|
|
|
function SetOnRequest(AMethod: TMVCRequestDelegate): IMVCDefaultAuthenticationHandler;
|
2017-03-23 18:51:25 +01:00
|
|
|
|
function SetOnAuthentication(AMethod: TMVCAuthenticationDelegate): IMVCDefaultAuthenticationHandler;
|
|
|
|
|
function SetOnAuthorization(AMethod: TMVCAuthorizationDelegate): IMVCDefaultAuthenticationHandler;
|
2016-06-16 22:13:35 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
{ TMVCListenerProperties }
|
|
|
|
|
|
|
|
|
|
constructor TMVCListenerProperties.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited Create;
|
|
|
|
|
FName := '';
|
|
|
|
|
FPort := 8080;
|
|
|
|
|
FMaxConnections := 1024;
|
|
|
|
|
FWebModuleClass := nil;
|
2019-12-19 10:39:13 +01:00
|
|
|
|
FSSLCertFile := '';
|
|
|
|
|
FSSLRootCertFile := '';
|
|
|
|
|
FSSLKeyFile := '';
|
|
|
|
|
FSSLPassword := '';
|
2016-06-16 22:13:35 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMVCListenerProperties.GetMaxConnections: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := FMaxConnections;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMVCListenerProperties.GetName: string;
|
|
|
|
|
begin
|
|
|
|
|
Result := FName;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMVCListenerProperties.GetPort: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := FPort;
|
|
|
|
|
end;
|
|
|
|
|
|
2019-12-19 10:39:13 +01:00
|
|
|
|
function TMVCListenerProperties.GetSSLOptions(out SSLCertFile, SSLRootCertFile,
|
|
|
|
|
SSLKeyFile, SSLPassword: String): Boolean;
|
|
|
|
|
begin
|
|
|
|
|
SSLCertFile := FSSLCertFile;
|
|
|
|
|
SSLRootCertFile := FSSLRootCertFile;
|
|
|
|
|
SSLKeyFile := FSSLKeyFile;
|
|
|
|
|
SSLPassword := FSSLPassword;
|
|
|
|
|
Result := not (FSSLCertFile.IsEmpty and FSSLKeyFile.IsEmpty);
|
|
|
|
|
end;
|
|
|
|
|
|
2016-06-16 22:13:35 +02:00
|
|
|
|
function TMVCListenerProperties.GetWebModuleClass: TComponentClass;
|
|
|
|
|
begin
|
|
|
|
|
Result := FWebModuleClass;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
class function TMVCListenerProperties.New: IMVCListenerProperties;
|
|
|
|
|
begin
|
|
|
|
|
Result := TMVCListenerProperties.Create;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMVCListenerProperties.SetMaxConnections(AValue: Integer): IMVCListenerProperties;
|
|
|
|
|
begin
|
|
|
|
|
FMaxConnections := AValue;
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMVCListenerProperties.SetName(const AValue: string): IMVCListenerProperties;
|
|
|
|
|
begin
|
|
|
|
|
FName := AValue;
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMVCListenerProperties.SetPort(AValue: Integer): IMVCListenerProperties;
|
|
|
|
|
begin
|
|
|
|
|
FPort := AValue;
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
2019-12-19 10:39:13 +01:00
|
|
|
|
function TMVCListenerProperties.SetSSLOptions(const SSLCertFile,
|
|
|
|
|
SSLRootCertFile, SSLKeyFile, SSLPassword: String): IMVCListenerProperties;
|
|
|
|
|
begin
|
|
|
|
|
FSSLCertFile := SSLCertFile;
|
|
|
|
|
FSSLRootCertFile := SSLRootCertFile;
|
|
|
|
|
FSSLKeyFile := SSLKeyFile;
|
|
|
|
|
FSSLPassword := SSLPassword;
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
2016-06-16 22:13:35 +02:00
|
|
|
|
function TMVCListenerProperties.SetWebModuleClass(AValue: TComponentClass): IMVCListenerProperties;
|
|
|
|
|
begin
|
|
|
|
|
FWebModuleClass := AValue;
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TMVCListener }
|
|
|
|
|
|
|
|
|
|
constructor TMVCListener.Create(AProperties: IMVCListenerProperties);
|
2019-12-19 10:39:13 +01:00
|
|
|
|
var
|
|
|
|
|
lSSLCertFile: String;
|
|
|
|
|
lSSLRootCertFile: String;
|
|
|
|
|
lSSLKeyFile: String;
|
2016-06-16 22:13:35 +02:00
|
|
|
|
begin
|
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
|
|
if not Assigned(AProperties) then
|
|
|
|
|
raise EMVCServerException.Create('Listener properties was not informed.');
|
|
|
|
|
|
|
|
|
|
if AProperties.GetName.IsEmpty then
|
|
|
|
|
raise EMVCServerException.Create('Listener name was not informed.');
|
|
|
|
|
|
|
|
|
|
FBridge := TIdHTTPWebBrokerBridge.Create(nil);
|
|
|
|
|
FBridge.DefaultPort := AProperties.GetPort;
|
|
|
|
|
FBridge.MaxConnections := AProperties.GetMaxConnections;
|
2019-06-06 06:54:15 +02:00
|
|
|
|
FBridge.OnParseAuthentication := OnParseAuthentication;
|
2016-06-16 22:13:35 +02:00
|
|
|
|
FBridge.RegisterWebModuleClass(AProperties.GetWebModuleClass);
|
2019-12-19 10:39:13 +01:00
|
|
|
|
|
|
|
|
|
if AProperties.GetSSLOptions(lSSLCertFile,lSSLRootCertFile,lSSLKeyFile,FBridgeSSLPassword) then
|
|
|
|
|
begin
|
|
|
|
|
//notice for client implementations
|
|
|
|
|
//OpenSSL currently don't support perfect forward security by default
|
|
|
|
|
FBridgeSSLHandler := TIdServerIOHandlerSSLOpenSSL.Create(FBridge);
|
|
|
|
|
FBridgeSSLHandler.SSLOptions.Method := sslvTLSv1_2;
|
|
|
|
|
FBridgeSSLHandler.SSLOptions.SSLVersions := [sslvSSLv23, sslvSSLv3, sslvTLSv1,sslvTLSv1_1,sslvTLSv1_2];
|
|
|
|
|
FBridgeSSLHandler.SSLOptions.Mode := sslmServer;
|
|
|
|
|
FBridgeSSLHandler.SSLOptions.CertFile := lSSLCertFile;
|
|
|
|
|
FBridgeSSLHandler.SSLOptions.RootCertFile := lSSLRootCertFile; //should be empty, currently broken in 10.3.3
|
|
|
|
|
FBridgeSSLHandler.SSLOptions.KeyFile := lSSLKeyFile;
|
|
|
|
|
FBridgeSSLHandler.OnGetPassword := OnGetSSLPassword;
|
|
|
|
|
FBridge.IOHandler := FBridgeSSLHandler;
|
2021-02-03 13:19:05 +01:00
|
|
|
|
{$IF CompilerVersion >= 33}
|
|
|
|
|
FBridge.OnQuerySSLPort := QuerySSLPort;
|
|
|
|
|
{$ENDIF}
|
2019-12-19 10:39:13 +01:00
|
|
|
|
end;
|
2016-06-16 22:13:35 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TMVCListener.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
if Assigned(FBridge) then
|
|
|
|
|
FBridge.Free;
|
|
|
|
|
inherited Destroy;
|
|
|
|
|
end;
|
|
|
|
|
|
2019-12-19 10:39:13 +01:00
|
|
|
|
procedure TMVCListener.OnGetSSLPassword(var APassword: string);
|
|
|
|
|
begin
|
|
|
|
|
APassword := FBridgeSSLPassword;
|
|
|
|
|
end;
|
|
|
|
|
|
2019-06-06 06:54:15 +02:00
|
|
|
|
procedure TMVCListener.OnParseAuthentication(AContext: TIdContext; const AAuthType, AAuthData: String; var VUsername, VPassword: String; var VHandled: Boolean);
|
|
|
|
|
begin
|
|
|
|
|
vhandled := True;
|
|
|
|
|
end;
|
|
|
|
|
|
2021-02-03 13:19:05 +01:00
|
|
|
|
procedure TMVCListener.QuerySSLPort(APort: Word; var VUseSSL: boolean);
|
|
|
|
|
begin
|
|
|
|
|
VUseSSL := true;
|
|
|
|
|
end;
|
|
|
|
|
|
2016-06-16 22:13:35 +02:00
|
|
|
|
function TMVCListener.GetActive: Boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := FBridge.Active;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMVCListener.Start;
|
|
|
|
|
begin
|
|
|
|
|
FBridge.Active := True;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMVCListener.Stop;
|
|
|
|
|
begin
|
|
|
|
|
FBridge.Active := False;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TMVCListenersContext }
|
|
|
|
|
|
2016-09-06 10:30:52 +02:00
|
|
|
|
function TMVCListenersContext.Add(const AName: string; AListener: IMVCListener)
|
|
|
|
|
: IMVCListenersContext;
|
2016-06-16 22:13:35 +02:00
|
|
|
|
begin
|
|
|
|
|
FListeners.AddOrSetValue(AName, AListener);
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMVCListenersContext.Add(AProperties: IMVCListenerProperties): IMVCListenersContext;
|
|
|
|
|
var
|
|
|
|
|
Listener: IMVCListener;
|
|
|
|
|
begin
|
|
|
|
|
Listener := TMVCListener.Create(AProperties);
|
|
|
|
|
Result := Add(AProperties.GetName, Listener);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMVCListenersContext.Count: Integer;
|
|
|
|
|
begin
|
|
|
|
|
Result := FListeners.Count;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
constructor TMVCListenersContext.Create;
|
|
|
|
|
begin
|
|
|
|
|
inherited Create;
|
|
|
|
|
FListeners := TDictionary<string, IMVCListener>.Create;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
destructor TMVCListenersContext.Destroy;
|
|
|
|
|
begin
|
|
|
|
|
StopAll;
|
|
|
|
|
FListeners.Free;
|
|
|
|
|
inherited Destroy;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMVCListenersContext.FindByName(const AListenerName: string): IMVCListener;
|
|
|
|
|
begin
|
|
|
|
|
Result := FListeners.Items[AListenerName];
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMVCListenersContext.ForEach(AProc: TProc<string, IMVCListener>);
|
|
|
|
|
var
|
|
|
|
|
Pair: TPair<string, IMVCListener>;
|
|
|
|
|
begin
|
|
|
|
|
for Pair in FListeners do
|
|
|
|
|
AProc(Pair.Key, Pair.Value);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TMVCListenersContext.Remove(const AListenerName: string): IMVCListenersContext;
|
|
|
|
|
begin
|
|
|
|
|
if (FListeners.ContainsKey(AListenerName)) then
|
|
|
|
|
FListeners.Remove(AListenerName)
|
|
|
|
|
else
|
|
|
|
|
raise EMVCServerException.Create('Listener ' + AListenerName + ' not found.');
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMVCListenersContext.StartAll;
|
|
|
|
|
begin
|
|
|
|
|
ForEach(
|
|
|
|
|
procedure(AName: string; AListener: IMVCListener)
|
|
|
|
|
begin
|
|
|
|
|
AListener.Start;
|
|
|
|
|
end
|
|
|
|
|
);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TMVCListenersContext.StopAll;
|
|
|
|
|
begin
|
|
|
|
|
ForEach(
|
|
|
|
|
procedure(AName: string; AListener: IMVCListener)
|
|
|
|
|
begin
|
|
|
|
|
AListener.Stop;
|
|
|
|
|
end
|
|
|
|
|
);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
{ TMVCDefaultAuthenticationHandler }
|
|
|
|
|
|
|
|
|
|
class function TMVCDefaultAuthenticationHandler.New: IMVCDefaultAuthenticationHandler;
|
|
|
|
|
begin
|
|
|
|
|
Result := TMVCDefaultAuthenticationHandler.Create;
|
|
|
|
|
end;
|
|
|
|
|
|
2018-12-09 23:03:06 +01:00
|
|
|
|
procedure TMVCDefaultAuthenticationHandler.OnAuthentication(
|
|
|
|
|
const AContext: TWebContext;
|
|
|
|
|
const AUserName, APassword: string;
|
|
|
|
|
AUserRoles: TList<string>;
|
|
|
|
|
var IsValid: Boolean;
|
|
|
|
|
const ASessionData: TDictionary<string, string>);
|
2016-06-16 22:13:35 +02:00
|
|
|
|
begin
|
|
|
|
|
IsValid := True;
|
|
|
|
|
if Assigned(FAuthenticationDelegate) then
|
|
|
|
|
FAuthenticationDelegate(AUserName, APassword, AUserRoles, IsValid, ASessionData);
|
|
|
|
|
end;
|
|
|
|
|
|
2018-12-09 23:03:06 +01:00
|
|
|
|
procedure TMVCDefaultAuthenticationHandler.OnAuthorization(
|
|
|
|
|
const AContext: TWebContext;
|
|
|
|
|
AUserRoles: TList<string>;
|
|
|
|
|
const AControllerQualifiedClassName: string;
|
|
|
|
|
const AActionName: string;
|
|
|
|
|
var IsAuthorized: Boolean);
|
2016-06-16 22:13:35 +02:00
|
|
|
|
begin
|
|
|
|
|
IsAuthorized := True;
|
|
|
|
|
if Assigned(FAuthorizationDelegate) then
|
|
|
|
|
FAuthorizationDelegate(AUserRoles, AControllerQualifiedClassName, AActionName, IsAuthorized);
|
|
|
|
|
end;
|
|
|
|
|
|
2018-12-09 23:03:06 +01:00
|
|
|
|
procedure TMVCDefaultAuthenticationHandler.OnRequest(const AContext: TWebContext; const AControllerQualifiedClassName, AActionName: string;
|
|
|
|
|
var AAuthenticationRequired: Boolean);
|
2016-06-16 22:13:35 +02:00
|
|
|
|
begin
|
|
|
|
|
AAuthenticationRequired := True;
|
|
|
|
|
if Assigned(FRequestDelegate) then
|
|
|
|
|
FRequestDelegate(AControllerQualifiedClassName, AActionName, AAuthenticationRequired);
|
|
|
|
|
end;
|
|
|
|
|
|
2016-09-06 10:30:52 +02:00
|
|
|
|
function TMVCDefaultAuthenticationHandler.SetOnAuthentication(AMethod: TMVCAuthenticationDelegate)
|
|
|
|
|
: IMVCDefaultAuthenticationHandler;
|
2016-06-16 22:13:35 +02:00
|
|
|
|
begin
|
|
|
|
|
FAuthenticationDelegate := AMethod;
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
2016-09-06 10:30:52 +02:00
|
|
|
|
function TMVCDefaultAuthenticationHandler.SetOnAuthorization(AMethod: TMVCAuthorizationDelegate)
|
|
|
|
|
: IMVCDefaultAuthenticationHandler;
|
2016-06-16 22:13:35 +02:00
|
|
|
|
begin
|
|
|
|
|
FAuthorizationDelegate := AMethod;
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
2016-09-06 10:30:52 +02:00
|
|
|
|
function TMVCDefaultAuthenticationHandler.SetOnRequest(AMethod: TMVCRequestDelegate)
|
|
|
|
|
: IMVCDefaultAuthenticationHandler;
|
2016-06-16 22:13:35 +02:00
|
|
|
|
begin
|
|
|
|
|
FRequestDelegate := AMethod;
|
|
|
|
|
Result := Self;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end.
|