Java.net.Authenticator klase Java valodā

Autentifikatora klase tiek izmantota gadījumos, kad ir nepieciešama autentifikācija, lai apmeklētu kādu URL. Kad ir zināms, ka ir nepieciešama autentifikācija, tas pieprasa lietotājam to pašu vai izmanto kādu cieti kodētu lietotājvārdu un paroli. 
Lai izmantotu šo klasi, jāveic šādas darbības: 
 


  1. Izveidojiet klasi, kas paplašina Autentifikatoru. Nosauksim to customAuth.
  2. Ignorēt metodi getPasswordAuthentication(). Šī metode ietver vairākas metodes, kā iegūt informāciju par entītiju, kas pieprasa autentifikāciju. Visas šīs metodes tiks sīkāk aplūkotas vēlāk.
  3. Iestatiet jaunizveidoto apakšklasi kā noklusējuma autentifikatoru, kas jāizmanto, kad http serveris pieprasa autentifikāciju ar Authenticator klases metodi setDefault(Authenticator a).
      setDefault(Autentifikators a) : Iestata autentifikatoru, kas jāizmanto, ja HTTP serverim ir nepieciešama autentifikācija. 
       
  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() : Sistēmā reģistrētajam autentifikatoram pieprasa paroli. Atgriež lietotājvārdu/paroli vai nulli, ja tas nav atrasts.
     
  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. Vēl viena pārslogota metode, ko var izmantot situācijās, kad var izmantot resursdatora nosaukumu, ja inetadrese nav pieejama. 
     
  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. Vēl viena pārslogota metode, ko var izmantot, ja ir zināms tikai tās vietnes URL, kas pieprasa autentifikāciju, nevis inetadrese un resursdatora nosaukums. 
     
  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() : atgriež tās vietnes resursdatora nosaukumu, kas pieprasa autentifikāciju. 
     
  Syntax : protected final String getRequestingHost()   

  1.  
  2. getRequestingSite() : atgriež tās vietnes inetadresi, kas pieprasa autentifikāciju. 
     
  Syntax : protected final InetAddress getRequestingSite()   

  1.  
  2. getRequestingPort() : atgriež savienojuma portu. 
     
  Syntax : protected final int getRequestingPort()   

  1.  
  2. getRequestingProtocol() : atgriež protokolu, kas pieprasa savienojumu. 
     
  Syntax : protected final String getRequestingProtocol()   

  1.  
  2. getRequestingPrompt() : atgriež pieprasījumu pēc pieprasījuma. 
     
  Syntax : protected final String getRequestingPrompt()   

  1.  
  2. getRequestingScheme() : atgriež pieprasītājas vietnes shēmu. 
     
  Syntax : protected final String getRequestingScheme()   

  1.  
  2. getPasswordAuthentication() : šī metode tiek izsaukta, ja ir nepieciešama paroles autentifikācija. Visām apakšklasēm ir jāignorē šī metode, jo noklusējuma metode vienmēr atgriež nulli. 
     
  Syntax : protected PasswordAuthentication getPasswordAuthentication()   

  1.  
  2. getRequestingURL() : atgriež pieprasītāja URL. 
     
  Syntax : protected final URL getRequestingURL()   

  1.  
  2. getRequestorType() : atgriež, ja pieprasītājs ir starpniekserveris vai serveris. 
     
  Syntax : protected Authenticator.RequestorType getRequestorType()   

  1.  
Izveidojiet viktorīnu