使用Troleauth类,一种类似注视的代码进行授权,也是最简单和方便的方式,实现如下:
unit ServerMethodsUnit1; interface uses System.SysUtils, System.Classes, System.Json, Datasnap.DSServer, Datasnap.DSAuth, DataSnap.DSProviderDataModuleAdapter; type TServerMethods1 = class(TDSServerModule) private { Private declarations } public { Public declarations } [TRoleAuth('AdminGroup','GuestGroup')] function EchoString(Value: string): string; [TRoleAuth('GuestGroup','AdminGroup')] function ReverseString(Value: string): string; end; implementation {$R *.dfm} uses System.StrUtils; function TServerMethods1.EchoString(Value: string): string; begin Result := Value; end; function TServerMethods1.ReverseString(Value: string): string; begin Result := System.StrUtils.ReverseString(Value); end; end.
编译环境:Delphi XE7
加入DataSnap高级交流群439992010,即可下载本DEMO