Razred Java.net.Authenticator v Javi

Razred Authenticator se uporablja v primerih, ko je za obisk nekega URL-ja potrebna avtentikacija. Ko je znano, da je potrebna avtentikacija, uporabnika pozove k njej ali uporabi neko trdo kodirano uporabniško ime in geslo. 
Za uporabo tega razreda sledite naslednjim korakom- 
 


  1. Ustvarite razred, ki razširi Authenticator. Poimenujmo ga customAuth.
  2. Preglasite metodo getPasswordAuthentication(). Ta metoda vsebuje več metod za pridobivanje podrobnosti entitete, ki zahteva avtentikacijo. Vse te metode bodo podrobneje obravnavane kasneje.
  3. Novo ustvarjeni podrazred nastavite kot privzeti avtentifikator, ki bo uporabljen, ko strežnik http zahteva avtentikacijo z metodo setDefault(Authenticator a) razreda Authenticator.
      setDefault(Authenticator a): Nastavi avtentifikator, ki bo uporabljen, ko strežnik HTTP zahteva avtentikacijo. 
       
  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() : Od avtentifikatorja, registriranega v sistemu, zahteva geslo. Vrne uporabniško ime/geslo ali nič, če ni najden.
     
  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. Druga preobremenjena metoda, ki jo je mogoče uporabiti v primerih, ko je mogoče uporabiti ime gostitelja, če inetaddress ni na voljo. 
     
  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. Še ena preobremenjena metoda, ki jo je mogoče uporabiti, če je znan samo URL mesta, ki zahteva preverjanje pristnosti, ne pa inetadress in ime gostitelja. 
     
  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() : vrne ime gostitelja mesta, ki zahteva preverjanje pristnosti. 
     
  Syntax : protected final String getRequestingHost()   

  1.  
  2. getRequestingSite() : vrne vhodni naslov mesta, ki zahteva avtentikacijo. 
     
  Syntax : protected final InetAddress getRequestingSite()   

  1.  
  2. getRequestingPort() : vrne vrata povezave. 
     
  Syntax : protected final int getRequestingPort()   

  1.  
  2. getRequestingProtocol() : vrne protokol, ki zahteva povezavo. 
     
  Syntax : protected final String getRequestingProtocol()   

  1.  
  2. getRequestingPrompt() : vrne sporočilo, ki ga zahteva prosilec. 
     
  Syntax : protected final String getRequestingPrompt()   

  1.  
  2. getRequestingScheme() : vrne shemo zahtevanega mesta. 
     
  Syntax : protected final String getRequestingScheme()   

  1.  
  2. getPasswordAuthentication() : ta metoda se pokliče, ko je zahtevano preverjanje pristnosti gesla. Vsi podrazredi morajo preglasiti to metodo, saj privzeta metoda vedno vrne nič. 
     
  Syntax : protected PasswordAuthentication getPasswordAuthentication()   

  1.  
  2. getRequestingURL() : vrne url prosilca. 
     
  Syntax : protected final URL getRequestingURL()   

  1.  
  2. getRequestorType() : vrne, če je zahtevnik proxy ali strežnik. 
     
  Syntax : protected Authenticator.RequestorType getRequestorType()   

  1.  
Ustvari kviz