TDSAuthenticationManager的用法

TDSAuthenticationManager的用法

xe开始有了TDSAuthenticationManager,这个主要用来做用户认证,用法也很简单

服务器端


1.TDSAuthenticationManager有两个主要的事件

在这个事件里面,看看检测连上来的用户名,密码是否合法,valid如果置为false,这就为非法连接了,DSServer会立刻抛出异常后close连接。

procedure TServerContainer1.DSAuthenticationManager1UserAuthenticate(
Sender: TObject; const Protocol, Context, User, Password: string;
var valid: Boolean; UserRoles: TStrings);
begin
{ TODO : Validate the client user and password.
If role-based authorization is needed, add role names to the UserRoles parameter }
if (User=authParams.user) and (Password=authParams.password) then
valid := True
else valid := False;
end;

在这个事件里面,判断已经连接上来的用户,对ServerMethod的调用是否合法,注视里也写了,默认是如何检测是否合法的。
procedure TServerContainer1.DSAuthenticationManager1UserAuthorize(   Sender: TObject; EventObject: TDSAuthorizeEventObject;   var valid: Boolean);
begin 
{ TODO : Authorize a user to execute a method.     Use values from EventObject such as UserName, UserRoles, AuthorizedRoles and
DeniedRoles.     Use DSAuthenticationManager1.Roles to define Authorized and Denied roles     for particular server methods. } 
//valid := True;
end;

客户端:

with SQLConnection1 do
begin
Connected := False;
ConnectionName := 'DataSnapCONNECTION';
Params.Clear;
DriverName := 'DataSnap';
Params.Add('DriverName=DataSnap');
Params.Add('CommunicationProtocol=tcp/ip');
Params.Add('HostName=' + appInfo.appSvrIp);
Params.Add('port=' + IntToStr(appInfo.appSvrPort));
Params.Add('DSAuthenticationUser=' + appInfo.appSvrUser);
Params.Add('DSAuthenticationPassword=' + appInfo.appSvrPassword);
end;
end;

posted @   delphi中间件  阅读(3147)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示