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;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/archive/2012/02/23/2365829.html