Клас Java.net.Authenticator в Java

Клас автентифікатора використовується в тих випадках, коли для відвідування певної URL-адреси потрібна автентифікація. Коли стає відомо, що потрібна автентифікація, користувач запитує її або використовує жорстко закодовані ім’я користувача та пароль. 
Щоб використовувати цей клас, виконайте наступні кроки: 
 


  1. Створіть клас, який розширює Authenticator. Назвемо його customAuth.
  2. Перевизначте метод getPasswordAuthentication(). Цей метод містить кілька методів для отримання деталей сутності, яка запитує автентифікацію. Усі ці методи детально обговорюються пізніше.
  3. Встановіть щойно створений підклас як автентифікатор за замовчуванням, який буде використовуватися, коли http-сервер запитує автентифікацію за допомогою методу setDefault(Authenticator a) класу Authenticator.
      setDefault(Authenticator a): Встановлює автентифікатор, який буде використовуватися, коли сервер HTTP вимагає автентифікації. 
       
  Syntax :   public static void setDefault(Authenticator a) throws SecurityException   Parameter :   a : authenticator to be set as default   Throws :   SecurityException : if security manager doesn't allow setting default authenticator 

  1.  
  2. requestPasswordAuthentication() : Запитує пароль у зареєстрованого в системі автентифікатора. Повертає ім'я користувача/пароль або null, якщо не знайдено.
     
  Syntax :    public static PasswordAuthentication requestPasswordAuthentication( InetAddress addr int port String protocol String prompt String scheme)   Parameter :   addr : Inet address of the site asking for authentication port : port of requesting site protocol : protocol used for connection prompt : message for the user scheme : authentication scheme   Throws :   SecurityException : if security manager doesn't allow setting password authentication. 

  1. Ще один перевантажений метод, який можна використовувати в ситуаціях, коли можна використовувати ім’я хоста, якщо inetaddress недоступний. 
     
  Syntax :    public static PasswordAuthentication requestPasswordAuthentication( String host InetAddress addr int port String protocol String prompt String scheme)   Parameter :   host : hostname of the site asking for authentication addr : Inet address of the site asking for authentication port : port of requesting site protocol : protocol used for connection prompt : message for the user scheme : authentication scheme   Throws :   SecurityException : if security manager doesn't allow setting password authentication. 

  1. Інший перевантажений метод, який можна використовувати, якщо відома лише URL-адреса сайту, який запитує автентифікацію, а не inetaddress і ім’я хоста. 
     
  Syntax :    public static PasswordAuthentication requestPasswordAuthentication( String host InetAddress addr int port String protocol String prompt URL url String scheme)   Parameter :   host : hostname of the site asking for authentication addr : Inet address of the site asking for authentication port : port of requesting site protocol : protocol used for connection prompt : message for the user url : URL of the site requesting authentication scheme : authentication scheme   Throws :   SecurityException : if security manager doesn't allow setting password authentication. 

  1.  
  2. getRequestingHost() : повертає ім’я хоста сайту, який запитує автентифікацію. 
     
  Syntax : protected final String getRequestingHost()   

  1.  
  2. getRequestingSite() : повертає inetaddress сайту, який запитує автентифікацію. 
     
  Syntax : protected final InetAddress getRequestingSite()   

  1.  
  2. getRequestingPort() : повертає порт підключення. 
     
  Syntax : protected final int getRequestingPort()   

  1.  
  2. getRequestingProtocol() : повертає протокол, який запитує з’єднання. 
     
  Syntax : protected final String getRequestingProtocol()   

  1.  
  2. getRequestingPrompt() : повертає повідомлення, запропоноване запитувачем. 
     
  Syntax : protected final String getRequestingPrompt()   

  1.  
  2. getRequestingScheme() : повертає схему сайту запиту. 
     
  Syntax : protected final String getRequestingScheme()   

  1.  
  2. getPasswordAuthentication() : цей метод викликається, коли потрібна автентифікація за паролем. Усі підкласи повинні перевизначати цей метод, оскільки метод за замовчуванням завжди повертає значення null. 
     
  Syntax : protected PasswordAuthentication getPasswordAuthentication()   

  1.  
  2. getRequestingURL() : повертає URL запитувача. 
     
  Syntax : protected final URL getRequestingURL()   

  1.  
  2. getRequestorType() : повертає, якщо запитувач є проксі або сервером. 
     
  Syntax : protected Authenticator.RequestorType getRequestorType()   

  1.  
Створіть вікторину