Trieda Java.net.Authenticator v jazyku Java
Trieda Authenticator sa používa v prípadoch, keď je na návštevu nejakej adresy URL potrebná autentifikácia. Akonáhle je známe, že sa vyžaduje overenie, požiada používateľa o to isté alebo použije nejaké pevne zakódované používateľské meno a heslo.
Ak chcete použiť túto triedu, postupujte podľa nasledujúcich krokov:
-
Vytvorte triedu, ktorá rozšíri Authenticator. Nazvime to customAuth. - Prepíšte metódu getPasswordAuthentication(). Táto metóda obsahuje niekoľko metód na získanie podrobností o entite žiadajúcej o autentifikáciu. Všetky tieto metódy sú podrobne diskutované neskôr.
- Nastavte novovytvorenú podtriedu ako predvolený autentifikátor, ktorý sa má použiť, keď http server požaduje autentifikáciu pomocou metódy setDefault(Authenticator a) triedy Authenticator.
-
-
Ďalšia preťažená metóda, ktorú možno použiť v situáciách, keď je možné použiť názov hostiteľa, ak nie je k dispozícii inetaddress.
-
Ďalšia preťažená metóda, ktorú je možné použiť, ak je známa iba adresa URL stránky požadujúcej autentifikáciu a nie inetaadresa a názov hostiteľa.
-
-
-
-
-
-
-
-
-
-
setDefault(Authenticator a) : Nastaví autentifikátor, ktorý sa má použiť, keď HTTP server vyžaduje autentifikáciu.
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() : Požiada autentifikátora registrovaného v systéme o heslo. Ak sa nenájde, vráti používateľské meno/heslo alebo hodnotu null.
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() : vráti názov hostiteľa stránky požadujúcej overenie.
Syntax : protected final String getRequestingHost()
getRequestingSite() : vráti inetaadresu stránky požadujúcej overenie.
Syntax : protected final InetAddress getRequestingSite()
getRequestingPort() : vráti port pripojenia.
Syntax : protected final int getRequestingPort()
getRequestingProtocol() : vráti protokol požadujúci pripojenie.
Syntax : protected final String getRequestingProtocol()
getRequestingPrompt() : vráti správu vyžiadanú žiadateľom.
Syntax : protected final String getRequestingPrompt()
getRequestingScheme() : vráti schému žiadajúcej stránky.
Syntax : protected final String getRequestingScheme()
getPasswordAuthentication() : táto metóda sa volá, keď sa vyžaduje overenie hesla. Všetky podtriedy musia túto metódu prepísať, pretože predvolená metóda vždy vráti hodnotu null.
Syntax : protected PasswordAuthentication getPasswordAuthentication()
getRequestingURL() : vráti adresu URL žiadateľa.
Syntax : protected final URL getRequestingURL()
getRequestorType() : vráti, ak je žiadateľom proxy alebo server.
Syntax : protected Authenticator.RequestorType getRequestorType()
Mohlo By Sa Vám Páčiť
Najlepšie Články
Kategórie
Zaujímavé Články
-