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-
-
Napravite klasu koja proširuje Autentifikator. Nazovimo ga customAuth. - 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.
- Postavite novostvorenu potklasu kao zadani autentifikator koji će se koristiti kada http poslužitelj zatraži autentifikaciju metodom setDefault(Authenticator a) klase Autentifikator.
-
-
Još jedna preopterećena metoda koja se može koristiti u situacijama u kojima se može koristiti hostname ako inetaddress nije dostupan.
-
Još jedna preopterećena metoda koja se može koristiti ako je poznat samo URL stranice koja zahtijeva autentifikaciju, a ne inetadress i hostname.
-
-
-
-
-
-
-
-
-
-
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
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.
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.
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.
getRequestingHost() : vraća naziv hosta stranice koja zahtijeva autentifikaciju.
Syntax : protected final String getRequestingHost()
getRequestingSite() : vraća inetaddress stranice koja zahtijeva autentifikaciju.
Syntax : protected final InetAddress getRequestingSite()
getRequestingPort() : vraća port veze.
Syntax : protected final int getRequestingPort()
getRequestingProtocol() : vraća protokol koji zahtijeva vezu.
Syntax : protected final String getRequestingProtocol()
getRequestingPrompt() : vraća poruku koju traži podnositelj zahtjeva.
Syntax : protected final String getRequestingPrompt()
getRequestingScheme() : vraća shemu stranice koja zahtijeva.
Syntax : protected final String getRequestingScheme()
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()
getRequestingURL() : vraća url podnositelja zahtjeva.
Syntax : protected final URL getRequestingURL()
getRequestorType() : vraća ako je podnositelj zahtjeva proxy ili poslužitelj.
Syntax : protected Authenticator.RequestorType getRequestorType()
-