Klasa Java.net.Authenticator w Javie
Klasa Authenticator jest używana w przypadkach, gdy wymagane jest uwierzytelnienie, aby odwiedzić jakiś adres URL. Gdy wiadomo, że wymagane jest uwierzytelnienie, użytkownik monituje o to samo lub używa zakodowanej na stałe nazwy użytkownika i hasła.
Aby skorzystać z tej klasy, należy wykonać następujące kroki:
-
Utwórz klasę, która rozszerza moduł uwierzytelniający. Nazwijmy to niestandardoweAuth. - Zastąp metodę getPasswordAuthentication(). Ta metoda zawiera kilka metod uzyskania szczegółów podmiotu żądającego uwierzytelnienia. Wszystkie te metody zostaną szczegółowo omówione w dalszej części.
- Ustaw nowo utworzoną podklasę jako domyślny moduł uwierzytelniający, który będzie używany, gdy serwer http poprosi o uwierzytelnienie za pomocą metody setDefault(Authenticator a) klasy Authenticator.
-
-
Kolejna przeciążona metoda, której można użyć w sytuacjach, gdy można użyć nazwy hosta, jeśli adres ineta jest niedostępny.
-
Kolejna przeciążona metoda, której można użyć, jeśli znany jest tylko adres URL witryny żądającej uwierzytelnienia, a nie adres i nazwa hosta.
-
-
-
-
-
-
-
-
-
-
setDefault(Authenticator a): Ustawia moduł uwierzytelniający, który będzie używany, gdy serwer HTTP wymaga uwierzytelnienia.
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() : Prosi osobę uwierzytelniającą zarejestrowaną w systemie o podanie hasła. Zwraca nazwę użytkownika/hasło lub wartość null, jeśli nie została znaleziona.
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() : zwraca nazwę hosta witryny żądającej uwierzytelnienia.
Syntax : protected final String getRequestingHost()
getRequestingSite() : zwraca adres wejściowy witryny żądającej uwierzytelnienia.
Syntax : protected final InetAddress getRequestingSite()
getRequestingPort() : zwraca port połączenia.
Syntax : protected final int getRequestingPort()
getRequestingProtocol() : zwraca protokół żądający połączenia.
Syntax : protected final String getRequestingProtocol()
getRequestingPrompt() : zwraca komunikat monitowany przez requestera.
Syntax : protected final String getRequestingPrompt()
getRequestingScheme() : zwraca schemat strony żądającej.
Syntax : protected final String getRequestingScheme()
getPasswordAuthentication() : ta metoda jest wywoływana, gdy wymagane jest uwierzytelnienie hasłem. Wszystkie podklasy muszą zastąpić tę metodę, ponieważ metoda domyślna zawsze zwraca wartość null.
Syntax : protected PasswordAuthentication getPasswordAuthentication()
getRequestingURL() : zwraca adres URL osoby żądającej.
Syntax : protected final URL getRequestingURL()
getRequestorType() : zwraca, jeśli obiekt żądający jest serwerem proxy lub serwerem.
Syntax : protected Authenticator.RequestorType getRequestorType()
Może Ci Się Spodobać
Najpopularniejsze Artykuły
Kategoria
-