Třída Java.net.Authenticator v Javě
Třída Authenticator se používá v případech, kdy je k návštěvě nějaké adresy URL vyžadována autentizace. Jakmile je známo, že je vyžadováno ověření, požádá uživatele o totéž nebo použije pevně zakódované uživatelské jméno a heslo.
Chcete-li použít tuto třídu, postupujte podle následujících kroků:
-
Vytvořte třídu, která rozšiřuje Authenticator. Pojmenujme to customAuth. - Přepište metodu getPasswordAuthentication(). Tato metoda obsahuje několik metod pro získání podrobností o entitě žádající o ověření. Všechny tyto metody jsou podrobně diskutovány později.
- Nastavte nově vytvořenou podtřídu jako výchozí autentizátor, který se má použít, když http server požádá o autentizaci pomocí metody setDefault(Authenticator a) třídy Authenticator.
-
-
Další přetížená metoda, kterou lze použít v situacích, kdy lze použít název hostitele, pokud není k dispozici inetaddress.
-
Další přetížená metoda, kterou lze použít, pokud je známa pouze adresa URL webu požadujícího autentizaci a nikoli inetaadresa a název hostitele.
-
-
-
-
-
-
-
-
-
-
setDefault(Authenticator a) : Nastaví ověřovací modul, který se má použít, když server HTTP vyžaduje ověření.
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žádá ověřovatele registrovaného v systému o heslo. Vrátí uživatelské jméno/heslo nebo null, pokud nebylo nalezeno.
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() : vrací název hostitele webu požadujícího ověření.
Syntax : protected final String getRequestingHost()
getRequestingSite() : vrací inetaadresu webu požadujícího ověření.
Syntax : protected final InetAddress getRequestingSite()
getRequestingPort() : vrací port připojení.
Syntax : protected final int getRequestingPort()
getRequestingProtocol() : vrátí protokol požadující připojení.
Syntax : protected final String getRequestingProtocol()
getRequestingPrompt() : vrátí zprávu vyžádanou žadatelem.
Syntax : protected final String getRequestingPrompt()
getRequestingScheme() : vrátí schéma žádajícího webu.
Syntax : protected final String getRequestingScheme()
getPasswordAuthentication() : tato metoda se volá, když je vyžadováno ověření heslem. Všechny podtřídy musí tuto metodu přepsat, protože výchozí metoda vždy vrací hodnotu null.
Syntax : protected PasswordAuthentication getPasswordAuthentication()
getRequestingURL() : vrátí adresu URL žadatele.
Syntax : protected final URL getRequestingURL()
getRequestorType() : vrátí, pokud je žadatelem proxy nebo server.
Syntax : protected Authenticator.RequestorType getRequestorType()
Mohlo By Se Vám Líbit
Nejlepší Články
Kategorie
Zajímavé Články
-