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-
-
Ustvarite razred, ki razširi Authenticator. Poimenujmo ga customAuth. - Preglasite metodo getPasswordAuthentication(). Ta metoda vsebuje več metod za pridobivanje podrobnosti entitete, ki zahteva avtentikacijo. Vse te metode bodo podrobneje obravnavane kasneje.
- Novo ustvarjeni podrazred nastavite kot privzeti avtentifikator, ki bo uporabljen, ko strežnik http zahteva avtentikacijo z metodo setDefault(Authenticator a) razreda Authenticator.
-
-
Druga preobremenjena metoda, ki jo je mogoče uporabiti v primerih, ko je mogoče uporabiti ime gostitelja, če inetaddress ni na voljo.
-
Š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.
-
-
-
-
-
-
-
-
-
-
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
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.
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() : vrne ime gostitelja mesta, ki zahteva preverjanje pristnosti.
Syntax : protected final String getRequestingHost()
getRequestingSite() : vrne vhodni naslov mesta, ki zahteva avtentikacijo.
Syntax : protected final InetAddress getRequestingSite()
getRequestingPort() : vrne vrata povezave.
Syntax : protected final int getRequestingPort()
getRequestingProtocol() : vrne protokol, ki zahteva povezavo.
Syntax : protected final String getRequestingProtocol()
getRequestingPrompt() : vrne sporočilo, ki ga zahteva prosilec.
Syntax : protected final String getRequestingPrompt()
getRequestingScheme() : vrne shemo zahtevanega mesta.
Syntax : protected final String getRequestingScheme()
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()
getRequestingURL() : vrne url prosilca.
Syntax : protected final URL getRequestingURL()
getRequestorType() : vrne, če je zahtevnik proxy ali strežnik.
Syntax : protected Authenticator.RequestorType getRequestorType()
Top Članki
Kategorija
Zanimivi Članki
-