类 BasicAuthenticator

java.lang.Object
com.sun.net.httpserver.Authenticator
com.sun.net.httpserver.BasicAuthenticator

public abstract class BasicAuthenticator extends Authenticator
BasicAuthenticator 提供 HTTP 基本身份验证的实现。它是一个抽象类,必须扩展以提供 checkCredentials(String,String) 的实现,调用它来验证每个传入请求。
  • 字段详细信息

    • realm

      protected final String  realm
      HTTP 基本身份验证字段。
  • 构造方法详细信息

    • BasicAuthenticator

      public BasicAuthenticator(String  realm)
      为给定的 HTTP 领域创建一个 BasicAuthenticator。使用平台的 default character set 解码基本身份验证凭据(用户名和密码)。
      API 注意:
      realm 参数的值将嵌入到带引号的字符串中。
      参数:
      realm - HTTP 基本认证领域
      抛出:
      NullPointerException - 如果领域是 null
      IllegalArgumentException - 如果 realm 是空字符串或未正确引用,如 RFC 7230 第 3.2 节 中指定的那样。请注意,任何用于引用的 \ 字符本身都必须在源代码中引用。
    • BasicAuthenticator

      public BasicAuthenticator(String  realm, Charset  charset)
      为给定的 HTTP 领域创建一个 BasicAuthenticator 并使用给定的 Charset 解码基本身份验证凭据(用户名和密码)。
      API 注意:
      UTF-8 是推荐的字符集,因为它的用法已传达给客户端,因此更有可能被客户端使用。

      realm 参数的值将嵌入到带引号的字符串中。

      参数:
      realm - HTTP 基本认证领域
      charset - Charset 解码来自客户端的传入凭据
      抛出:
      NullPointerException - 如果领域或字符集是 null
      IllegalArgumentException - 如果 realm 是空字符串或未正确引用,如 RFC 7230 第 3.2 节 中指定的那样。请注意,任何用于引用的 \ 字符本身都必须在源代码中引用。
  • 方法详情

    • getRealm

      public String  getRealm()
      返回创建 BasicAuthenticator 的领域。
      返回:
      验证者的字段字符串
    • authenticate

      public Authenticator.Result  authenticate(HttpExchange  t)
      从类复制的描述:Authenticator
      调用以验证每个传入请求。实现必须根据需要返回 Authenticator.Failure Authenticator.Success Authenticator.Retry 对象:
      • Failure 表示身份验证已完成,但由于凭据无效而失败。
      • Success表示认证成功,可以通过调用Authenticator.Success.getPrincipal() 获取代表用户的Principal对象。
      • Retry 表示需要另一个 HTTP exchange。需要发送回客户端的任何响应标头都在给定的 HttpExchange 中设置。必须在 Retry 对象中提供要返回的响应代码。 Retry 可能会出现多次。
      指定者:
      authenticate 在类 Authenticator
      参数:
      t - 调用 authenticate 的 HttpExchange
      返回:
      结果
    • checkCredentials

      public abstract boolean checkCredentials(String  username, String  password)
      调用每个传入请求以在此身份验证器字段的上下文中验证给定的名称和密码。任何凭据缓存都必须通过此方法的实现来完成。
      参数:
      username - 请求中的用户名
      password - 来自请求的密码
      返回:
      true 如果凭据有效,false 否则