logo

Java.net.Authenticator klasa u Javi

Klasa autentifikatora koristi se u onim slučajevima kada je za posjet nekom URL-u potrebna provjera autentičnosti. Nakon što je poznato da je provjera autentičnosti potrebna, od korisnika se traži ista ili koristi neko tvrdo kodirano korisničko ime i lozinku. 
Za korištenje ove klase slijedite sljedeće korake- 
 


  1. Napravite klasu koja proširuje Autentifikator. Nazovimo ga customAuth.
  2. Nadjačajte metodu getPasswordAuthentication(). Ova metoda sadrži nekoliko metoda za dobivanje pojedinosti entiteta koji zahtijeva autentifikaciju. O svim tim metodama kasnije se detaljnije govori.
  3. Postavite novostvorenu potklasu kao zadani autentifikator koji će se koristiti kada http poslužitelj zatraži autentifikaciju metodom setDefault(Authenticator a) klase Autentifikator.
      setDefault(Autentifikator a):Postavlja autentifikator koji će se koristiti kada HTTP poslužitelj zahtijeva provjeru autentičnosti. 
       
  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() :Traži lozinku od autentifikatora registriranog u sustavu. Vraća korisničko ime/lozinku ili null ako nije pronađeno.
     
  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. Još jedna preopterećena metoda koja se može koristiti u situacijama u kojima se može koristiti hostname ako inetaddress nije dostupan. 
     
  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. Još jedna preopterećena metoda koja se može koristiti ako je poznat samo URL stranice koja zahtijeva autentifikaciju, a ne inetadress i hostname. 
     
  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(): vraća naziv hosta stranice koja zahtijeva autentifikaciju. 
     
  Syntax : protected final String getRequestingHost()  

  1.  
  2. getRequestingSite(): vraća inetaddress stranice koja zahtijeva autentifikaciju. 
     
  Syntax : protected final InetAddress getRequestingSite()  

  1.  
  2. getRequestingPort(): vraća port veze. 
     
  Syntax : protected final int getRequestingPort()  

  1.  
  2. getRequestingProtocol(): vraća protokol koji zahtijeva vezu. 
     
  Syntax : protected final String getRequestingProtocol()  

  1.  
  2. getRequestingPrompt(): vraća poruku koju traži podnositelj zahtjeva. 
     
  Syntax : protected final String getRequestingPrompt()  

  1.  
  2. getRequestingScheme(): vraća shemu stranice koja zahtijeva. 
     
  Syntax : protected final String getRequestingScheme()  

  1.  
  2. getPasswordAuthentication(): ova se metoda poziva kada je potrebna provjera autentičnosti lozinke. Sve podklase moraju nadjačati ovu metodu jer zadana metoda uvijek vraća null. 
     
  Syntax : protected PasswordAuthentication getPasswordAuthentication()  

  1.  
  2. getRequestingURL(): vraća url podnositelja zahtjeva. 
     
  Syntax : protected final URL getRequestingURL()  

  1.  
  2. getRequestorType(): vraća ako je podnositelj zahtjeva proxy ili poslužitelj. 
     
  Syntax : protected Authenticator.RequestorType getRequestorType()  

  1.  
Napravi kviz