zoukankan      html  css  js  c++  java
  • datasnap 授权验证DSAuthenticationManager方法应用

    服务端


    1.服务端只需要增加DSAuthenticationManager1并且把dshttpservice的AuthenticationManager属性设置为DSAuthenticationManager1即可。

    2.在DSAuthenticationManager1的OnUserAuthenticate方法中进行用户名密码验证操作具体示例代码如下:

    procedure TfrmServerContainer.DSAuthenticationManager1UserAuthenticate(
      Sender: TObject; const Protocol, Context, User, Password: string;
      var valid: Boolean; UserRoles: TStrings);
    begin
      if (User ='admin') and (Password ='pwd123') then
      begin
        valid := True;
      end
      else
        valid := False;
    end;

    3.也可以在dshttpservice中设置DSAuthUser及DSAuthPassword进行验证限制,并在DSAuthenticationManager1的roles中增加用户组对方法的访问,只需在OnUserAuthenticate中把用户加到相应的用户组即可。

    代码如下:UserRoles.Add(AdminGroup‘); //加入到AdminGroup组别

    客户端


    1.可以设置SQLConnection的DSAuthUser和DSAuthPassword就行了

    2.如果是用普通http协议的话,例如idhttp控件,则客户端代码如下:

    procedure TForm15.Button2Click(Sender: TObject);
    var
      url, params, Text: string;
      code: Integer;
      http: TIDHttp;
    begin
      http:= TIDHttp.Create(nil);
      http.Request.BasicAuthentication := True;
      http.request.password := '密码';
      params := Edit1.Text;
    
      url:= 'http://192.168.10.182:8081/datasnap/rest/TSM/EchoString/';
      try
        text := http.Get(URL+TIdURI.ParamsEnCode(params));
        Edit2.Text := Text;
      except
        on E: Exception do
        begin
    
        end;
      end;
    end;
  • 相关阅读:
    ASP.NET WebAPI Get和Post 传参总结
    关于EF第一次加载慢或过一段时间不访问时再次访问加载慢问题的总结
    jqthumb.js缩略图插件-让缩略图正常显示而不变形
    解决kindeditor编辑器中使用百度地图时不能拖动坐标的问题
    Jzoj3591 数据
    Jzoj3590 珠链
    Jzoj3590 珠链
    C++蜂鸣器歌曲1
    C++蜂鸣器歌曲1
    Jzoj2309 辽哥游戏
  • 原文地址:https://www.cnblogs.com/hejoy91/p/5941334.html
Copyright © 2011-2022 走看看