天天看點

使用TRoleAuth類對DataSnap服務端的接口授權

使用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

轉載于:https://www.cnblogs.com/Kim53622744/p/4403596.html