Kerberos 和 Negotiate 身份验证

支持方

TsgcWebSocketServer

TsgcWebSocketHTTPServer

TsgcWebSocketProxyServer

TsgcWebSocketServer_HTTPAPI

*需要 sgcWebSockets Enterprise Edition。在其他版本中,启动启用了 Negotiate 的服务器会引发异常 "Negotiate authentication requires sgcWebSockets Enterprise"。

概述

Negotiate 是 Windows 集成身份验证所采用的 HTTP 身份验证方案。客户端通过 Kerberos(SPNEGO)证明其身份,在 Windows 上则可回退到 NTLM,因此已经登录域的用户无需输入密码即可连接。处于 Intranet 区域的浏览器、curl --negotiate 以及使用默认凭据的 .NET 客户端都可以应答该质询。

平台

属性和事件

示例

下面的服务器只接受两个主体。事件按主体名称限制访问。


uses
  sgcWebSocket, sgcWebSocket_Classes;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    oServer: TsgcWebSocketHTTPServer;
    procedure OnNegotiateAuthenticationEvent(Connection: TsgcWSConnection;
      const aPrincipal: String; var Authenticated: Boolean);
  end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  oServer := TsgcWebSocketHTTPServer.Create(Self);
  oServer.Port := 8080;
  oServer.Authentication.Enabled := True;
  oServer.Authentication.Negotiate.Enabled := True;
  oServer.Authentication.Negotiate.ServicePrincipal :=
    'HTTP/host.example.com@EXAMPLE.COM';
  oServer.OnNegotiateAuthentication := OnNegotiateAuthenticationEvent;
  oServer.Active := True;
end;

procedure TForm1.OnNegotiateAuthenticationEvent(Connection: TsgcWSConnection;
  const aPrincipal: String; var Authenticated: Boolean);
begin
  Authenticated := SameText(aPrincipal, 'EXAMPLE\alice') or
    SameText(aPrincipal, 'EXAMPLE\bob');
end;

在 Linux 上,请将 Authentication.Negotiate.Keytab 设置为 keytab 的路径,例如 /etc/sgc/http.keytab,并在事件中使用 Kerberos 主体,例如 alice@EXAMPLE.COM。

交换过程如何工作

使用 curl 测试

curl --negotiate -u : http://host.example.com:8080/

设置说明