mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45: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;
|
||||
|
||||
/// <summary>
|
||||
/// Basis Interface for DMVC Middleware.
|
||||
/// </summary>
|
||||
IMVCMiddleware = interface
|
||||
['{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);
|
||||
/// <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;
|
||||
const AControllerQualifiedClassName: string; const AActionNAme: string;
|
||||
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;
|
||||
const AActionNAme: string; const Handled: boolean);
|
||||
end;
|
||||
|
@ -30,11 +30,13 @@ type
|
||||
TSampleAuth = class(TInterfacedObject, IMVCAuthenticationHandler)
|
||||
|
||||
public
|
||||
procedure OnRequest(const ControllerQualifiedClassName: string; const ActionName: string;
|
||||
var AuthenticationRequired: Boolean);
|
||||
procedure OnRequest(const ControllerQualifiedClassName: string;
|
||||
const ActionName: string; var AuthenticationRequired: Boolean);
|
||||
procedure OnAuthentication(const UserName: string; const Password: string;
|
||||
UserRoles: System.Generics.Collections.TList<System.string>; var IsValid: Boolean);
|
||||
procedure OnAuthorization(UserRoles: System.Generics.Collections.TList<System.string>;
|
||||
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;
|
||||
var IsAuthorized: Boolean);
|
||||
end;
|
||||
@ -46,19 +48,23 @@ begin
|
||||
begin
|
||||
Config[TMVCConfigKey.Messaging] := 'true';
|
||||
end);
|
||||
MVCEngine.AddController(TTestServerController).AddController(TTestPrivateServerController)
|
||||
MVCEngine.AddController(TTestServerController)
|
||||
.AddController(TTestPrivateServerController)
|
||||
.AddController(TTestServerControllerExceptionAfterCreate)
|
||||
.AddController(TTestServerControllerExceptionBeforeDestroy)
|
||||
.AddMiddleware(TMVCSpeedMiddleware.Create)
|
||||
.AddMiddleware(TMVCBasicAuthenticationMiddleware.Create(TSampleAuth.Create));
|
||||
.AddMiddleware(TMVCBasicAuthenticationMiddleware.Create
|
||||
(TSampleAuth.Create));
|
||||
|
||||
// MVCEngine.Config[TMVCConfigKey.Messaging] := 'false';
|
||||
end;
|
||||
|
||||
{ TSampleAuth }
|
||||
|
||||
procedure TSampleAuth.OnAuthentication(const UserName, Password: string;
|
||||
UserRoles: System.Generics.Collections.TList<System.string>; var IsValid: Boolean);
|
||||
procedure TSampleAuth.OnAuthentication(const UserName: string;
|
||||
const Password: string;
|
||||
UserRoles: System.Generics.Collections.TList<System.string>;
|
||||
var IsValid: Boolean; const SessionData: TDictionary<String, String>);
|
||||
begin
|
||||
UserRoles.Clear;
|
||||
IsValid := UserName = Password;
|
||||
@ -77,8 +83,10 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSampleAuth.OnAuthorization(UserRoles: System.Generics.Collections.TList<System.string>;
|
||||
const ControllerQualifiedClassName, ActionName: string; var IsAuthorized: Boolean);
|
||||
procedure TSampleAuth.OnAuthorization(UserRoles
|
||||
: System.Generics.Collections.TList<System.string>;
|
||||
const ControllerQualifiedClassName, ActionName: string;
|
||||
var IsAuthorized: Boolean);
|
||||
begin
|
||||
IsAuthorized := False;
|
||||
if ActionName = 'OnlyRole1' then
|
||||
@ -88,10 +96,11 @@ begin
|
||||
IsAuthorized := UserRoles.Contains('role2');
|
||||
end;
|
||||
|
||||
procedure TSampleAuth.OnRequest(const ControllerQualifiedClassName, ActionName: string;
|
||||
var AuthenticationRequired: Boolean);
|
||||
procedure TSampleAuth.OnRequest(const ControllerQualifiedClassName,
|
||||
ActionName: string; var AuthenticationRequired: Boolean);
|
||||
begin
|
||||
AuthenticationRequired := ControllerQualifiedClassName.EndsWith('TTestPrivateServerController');
|
||||
AuthenticationRequired := ControllerQualifiedClassName.EndsWith
|
||||
('TTestPrivateServerController');
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user