mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 15:55:54 +01:00
Introduced XmlDoc on IMVCMiddleware
Updated unit test for new middleware interface
This commit is contained in:
parent
e68dcafe9b
commit
25b064fec2
@ -426,12 +426,34 @@ type
|
|||||||
|
|
||||||
TMVCControllerClass = class of TMVCController;
|
TMVCControllerClass = class of TMVCController;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Basis Interface for DMVC Middleware.
|
||||||
|
/// </summary>
|
||||||
IMVCMiddleware = interface
|
IMVCMiddleware = interface
|
||||||
['{3278183A-124A-4214-AB4E-94CA4C22450D}']
|
['{3278183A-124A-4214-AB4E-94CA4C22450D}']
|
||||||
|
/// <summary>
|
||||||
|
/// Procedure is called before the MVCEngine routes the request to a specific controller/method.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Context">Webcontext which contains the complete request and response of the actual call.</param>
|
||||||
|
/// <param name="Handled">If set to True the Request would finished. Response must be set by the implementor. Default value is False.</param>
|
||||||
procedure OnBeforeRouting(Context: TWebContext; var Handled: boolean);
|
procedure OnBeforeRouting(Context: TWebContext; var Handled: boolean);
|
||||||
|
/// <summary>
|
||||||
|
/// Procedure is called before the specific controller method is called.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Context">Webcontext which contains the complete request and response of the actual call.</param>
|
||||||
|
/// <param name="AControllerQualifiedClassName">Qualified classname of the matching controller.</param>
|
||||||
|
/// <param name="AActionNAme">Method name of the matching controller method.</param>
|
||||||
|
/// <param name="Handled">If set to True the Request would finished. Response must be set by the implementor. Default value is False.</param>
|
||||||
procedure OnBeforeControllerAction(Context: TWebContext;
|
procedure OnBeforeControllerAction(Context: TWebContext;
|
||||||
const AControllerQualifiedClassName: string; const AActionNAme: string;
|
const AControllerQualifiedClassName: string; const AActionNAme: string;
|
||||||
var Handled: boolean);
|
var Handled: boolean);
|
||||||
|
/// <summary>
|
||||||
|
/// Procedure is called after the specific controller method was called.
|
||||||
|
/// It is still possible to cancel or to completly modifiy the request.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Context">Webcontext which contains the complete request and response of the actual call.</param>
|
||||||
|
/// <param name="AActionNAme">Method name of the matching controller method.</param>
|
||||||
|
/// <param name="Handled">If set to True the Request would finished. Response must be set by the implementor. Default value is False.</param>
|
||||||
procedure OnAfterControllerAction(Context: TWebContext;
|
procedure OnAfterControllerAction(Context: TWebContext;
|
||||||
const AActionNAme: string; const Handled: boolean);
|
const AActionNAme: string; const Handled: boolean);
|
||||||
end;
|
end;
|
||||||
|
@ -30,11 +30,13 @@ type
|
|||||||
TSampleAuth = class(TInterfacedObject, IMVCAuthenticationHandler)
|
TSampleAuth = class(TInterfacedObject, IMVCAuthenticationHandler)
|
||||||
|
|
||||||
public
|
public
|
||||||
procedure OnRequest(const ControllerQualifiedClassName: string; const ActionName: string;
|
procedure OnRequest(const ControllerQualifiedClassName: string;
|
||||||
var AuthenticationRequired: Boolean);
|
const ActionName: string; var AuthenticationRequired: Boolean);
|
||||||
procedure OnAuthentication(const UserName: string; const Password: string;
|
procedure OnAuthentication(const UserName: string; const Password: string;
|
||||||
UserRoles: System.Generics.Collections.TList<System.string>; var IsValid: Boolean);
|
UserRoles: System.Generics.Collections.TList<System.string>;
|
||||||
procedure OnAuthorization(UserRoles: System.Generics.Collections.TList<System.string>;
|
var IsValid: Boolean; const SessionData: TDictionary<String, String>);
|
||||||
|
procedure OnAuthorization(UserRoles
|
||||||
|
: System.Generics.Collections.TList<System.string>;
|
||||||
const ControllerQualifiedClassName: string; const ActionName: string;
|
const ControllerQualifiedClassName: string; const ActionName: string;
|
||||||
var IsAuthorized: Boolean);
|
var IsAuthorized: Boolean);
|
||||||
end;
|
end;
|
||||||
@ -46,19 +48,23 @@ begin
|
|||||||
begin
|
begin
|
||||||
Config[TMVCConfigKey.Messaging] := 'true';
|
Config[TMVCConfigKey.Messaging] := 'true';
|
||||||
end);
|
end);
|
||||||
MVCEngine.AddController(TTestServerController).AddController(TTestPrivateServerController)
|
MVCEngine.AddController(TTestServerController)
|
||||||
|
.AddController(TTestPrivateServerController)
|
||||||
.AddController(TTestServerControllerExceptionAfterCreate)
|
.AddController(TTestServerControllerExceptionAfterCreate)
|
||||||
.AddController(TTestServerControllerExceptionBeforeDestroy)
|
.AddController(TTestServerControllerExceptionBeforeDestroy)
|
||||||
.AddMiddleware(TMVCSpeedMiddleware.Create)
|
.AddMiddleware(TMVCSpeedMiddleware.Create)
|
||||||
.AddMiddleware(TMVCBasicAuthenticationMiddleware.Create(TSampleAuth.Create));
|
.AddMiddleware(TMVCBasicAuthenticationMiddleware.Create
|
||||||
|
(TSampleAuth.Create));
|
||||||
|
|
||||||
// MVCEngine.Config[TMVCConfigKey.Messaging] := 'false';
|
// MVCEngine.Config[TMVCConfigKey.Messaging] := 'false';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TSampleAuth }
|
{ TSampleAuth }
|
||||||
|
|
||||||
procedure TSampleAuth.OnAuthentication(const UserName, Password: string;
|
procedure TSampleAuth.OnAuthentication(const UserName: string;
|
||||||
UserRoles: System.Generics.Collections.TList<System.string>; var IsValid: Boolean);
|
const Password: string;
|
||||||
|
UserRoles: System.Generics.Collections.TList<System.string>;
|
||||||
|
var IsValid: Boolean; const SessionData: TDictionary<String, String>);
|
||||||
begin
|
begin
|
||||||
UserRoles.Clear;
|
UserRoles.Clear;
|
||||||
IsValid := UserName = Password;
|
IsValid := UserName = Password;
|
||||||
@ -77,8 +83,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSampleAuth.OnAuthorization(UserRoles: System.Generics.Collections.TList<System.string>;
|
procedure TSampleAuth.OnAuthorization(UserRoles
|
||||||
const ControllerQualifiedClassName, ActionName: string; var IsAuthorized: Boolean);
|
: System.Generics.Collections.TList<System.string>;
|
||||||
|
const ControllerQualifiedClassName, ActionName: string;
|
||||||
|
var IsAuthorized: Boolean);
|
||||||
begin
|
begin
|
||||||
IsAuthorized := False;
|
IsAuthorized := False;
|
||||||
if ActionName = 'OnlyRole1' then
|
if ActionName = 'OnlyRole1' then
|
||||||
@ -88,10 +96,11 @@ begin
|
|||||||
IsAuthorized := UserRoles.Contains('role2');
|
IsAuthorized := UserRoles.Contains('role2');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSampleAuth.OnRequest(const ControllerQualifiedClassName, ActionName: string;
|
procedure TSampleAuth.OnRequest(const ControllerQualifiedClassName,
|
||||||
var AuthenticationRequired: Boolean);
|
ActionName: string; var AuthenticationRequired: Boolean);
|
||||||
begin
|
begin
|
||||||
AuthenticationRequired := ControllerQualifiedClassName.EndsWith('TTestPrivateServerController');
|
AuthenticationRequired := ControllerQualifiedClassName.EndsWith
|
||||||
|
('TTestPrivateServerController');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user