API java : Authenticator


java.net
Class Authenticator

java.lang.Object
  extended by java.net.Authenticator

public abstract class Authenticator
extends Object

The class Authenticator represents an object that knows how to obtain authentication for a network connection. Usually, it will do this by prompting the user for information.

Applications use this class by overriding getPasswordAuthentication() in a sub-class. This method will typically use the various getXXX() accessor methods to get information about the entity requesting authentication. It must then acquire a username and password either by interacting with the user or through some other non-interactive means. The credentials are then returned as a PasswordAuthentication return value.

An instance of this concrete sub-class is then registered with the system by calling setDefault(Authenticator). When authentication is required, the system will invoke one of the requestPasswordAuthentication() methods which in turn will call the getPasswordAuthentication() method of the registered object.

All methods that request authentication have a default implementation that fails.

Since:
1.2
See Also:
setDefault(java.net.Authenticator), getPasswordAuthentication()

Nested Class Summary
static class Authenticator.RequestorType
          The type of the entity requesting authentication.
 
Constructor Summary
Authenticator()
           
 
Method Summary
protected  PasswordAuthentication getPasswordAuthentication()
          Called when password authorization is needed.
protected  String getRequestingHost()
          Gets the hostname of the site or proxy requesting authentication, or null if not available.
protected  int getRequestingPort()
          Gets the port number for the requested connection.
protected  String getRequestingPrompt()
          Gets the prompt string given by the requestor.
protected  String getRequestingProtocol()
          Give the protocol that's requesting the connection.
protected  String getRequestingScheme()
          Gets the scheme of the requestor (the HTTP scheme for an HTTP firewall, for example).
protected  InetAddress getRequestingSite()
          Gets the InetAddress of the site requesting authorization, or null if not available.
protected  URL getRequestingURL()
          Returns the URL that resulted in this request for authentication.
protected  Authenticator.RequestorType getRequestorType()
          Returns whether the requestor is a Proxy or a Server.
static PasswordAuthentication requestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String scheme)
          Ask the authenticator that has been registered with the system for a password.
static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme)
          Ask the authenticator that has been registered with the system for a password.
static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)
          Ask the authenticator that has been registered with the system for a password.
static void setDefault(Authenticator a)
          Sets the authenticator that will be used by the networking code when a proxy or an HTTP server asks for authentication.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Authenticator

public Authenticator()
Method Detail

setDefault

public static void setDefault(Authenticator a)
Sets the authenticator that will be used by the networking code when a proxy or an HTTP server asks for authentication.

First, if there is a security manager, its checkPermission method is called with a NetPermission("setDefaultAuthenticator") permission. This may result in a java.lang.SecurityException.

Parameters:
a - The authenticator to be set. If a is null then any previously set authenticator is removed.
Throws:
SecurityException - if a security manager exists and its checkPermission method doesn't allow setting the default authenticator.
See Also:
SecurityManager.checkPermission(java.security.Permission), NetPermission

requestPasswordAuthentication

public static PasswordAuthentication requestPasswordAuthentication(InetAddress addr,
                                                                   int port,
                                                                   String protocol,
                                                                   String prompt,
                                                                   String scheme)
Ask the authenticator that has been registered with the system for a password.

First, if there is a security manager, its checkPermission method is called with a NetPermission("requestPasswordAuthentication") permission. This may result in a java.lang.SecurityException.

Parameters:
addr - The InetAddress of the site requesting authorization, or null if not known.
port - the port for the requested connection
protocol - The protocol that's requesting the connection (getRequestingProtocol())
prompt - A prompt string for the user
scheme - The authentication scheme
Returns:
The username/password, or null if one can't be gotten.
Throws:
SecurityException - if a security manager exists and its checkPermission method doesn't allow the password authentication request.
See Also:
SecurityManager.checkPermission(java.security.Permission), NetPermission

requestPasswordAuthentication

public static PasswordAuthentication requestPasswordAuthentication(String host,
                                                                   InetAddress addr,
                                                                   int port,
                                                                   String protocol,
                                                                   String prompt,
                                                                   String scheme)
Ask the authenticator that has been registered with the system for a password. This is the preferred method for requesting a password because the hostname can be provided in cases where the InetAddress is not available.

First, if there is a security manager, its checkPermission method is called with a NetPermission("requestPasswordAuthentication") permission. This may result in a java.lang.SecurityException.

Parameters:
host - The hostname of the site requesting authentication.
addr - The InetAddress of the site requesting authentication, or null if not known.
port - the port for the requested connection.
protocol - The protocol that's requesting the connection (getRequestingProtocol())
prompt - A prompt string for the user which identifies the authentication realm.
scheme - The authentication scheme
Returns:
The username/password, or null if one can't be gotten.
Throws:
SecurityException - if a security manager exists and its checkPermission method doesn't allow the password authentication request.
Since:
1.4
See Also:
SecurityManager.checkPermission(java.security.Permission), NetPermission

requestPasswordAuthentication

public static PasswordAuthentication requestPasswordAuthentication(String host,
                                                                   InetAddress addr,
                                                                   int port,
                                                                   String protocol,
                                                                   String prompt,
                                                                   String scheme,
                                                                   URL url,
                                                                   Authenticator.RequestorType reqType)
Ask the authenticator that has been registered with the system for a password.

First, if there is a security manager, its checkPermission method is called with a NetPermission("requestPasswordAuthentication") permission. This may result in a java.lang.SecurityException.

Parameters:
host - The hostname of the site requesting authentication.
addr - The InetAddress of the site requesting authorization, or null if not known.
port - the port for the requested connection
protocol - The protocol that's requesting the connection (getRequestingProtocol())
prompt - A prompt string for the user
scheme - The authentication scheme
url - The requesting URL that caused the authentication
reqType - The type (server or proxy) of the entity requesting authentication.
Returns:
The username/password, or null if one can't be gotten.
Throws:
SecurityException - if a security manager exists and its checkPermission method doesn't allow the password authentication request.
Since:
1.5
See Also:
SecurityManager.checkPermission(java.security.Permission), NetPermission

getRequestingHost

protected final String getRequestingHost()
Gets the hostname of the site or proxy requesting authentication, or null if not available.

Returns:
the hostname of the connection requiring authentication, or null if it's not available.
Since:
1.4

getRequestingSite

protected final InetAddress getRequestingSite()
Gets the InetAddress of the site requesting authorization, or null if not available.

Returns:
the InetAddress of the site requesting authorization, or null if it's not available.

getRequestingPort

protected final int getRequestingPort()
Gets the port number for the requested connection.

Returns:
an int indicating the port for the requested connection.

getRequestingProtocol

protected final String getRequestingProtocol()
Give the protocol that's requesting the connection. Often this will be based on a URL, but in a future JDK it could be, for example, "SOCKS" for a password-protected SOCKS5 firewall.

Returns:
the protcol, optionally followed by "/version", where version is a version number.
See Also:
URL.getProtocol()

getRequestingPrompt

protected final String getRequestingPrompt()
Gets the prompt string given by the requestor.

Returns:
the prompt string given by the requestor (realm for http requests)

getRequestingScheme

protected final String getRequestingScheme()
Gets the scheme of the requestor (the HTTP scheme for an HTTP firewall, for example).

Returns:
the scheme of the requestor

getPasswordAuthentication

protected PasswordAuthentication getPasswordAuthentication()
Called when password authorization is needed. Subclasses should override the default implementation, which returns null.

Returns:
The PasswordAuthentication collected from the user, or null if none is provided.

getRequestingURL

protected URL getRequestingURL()
Returns the URL that resulted in this request for authentication.

Returns:
the requesting URL
Since:
1.5

getRequestorType

protected Authenticator.RequestorType getRequestorType()
Returns whether the requestor is a Proxy or a Server.

Returns:
the authentication type of the requestor
Since:
1.5

Ces informations proviennent du site de http://java.sun.com

Remarques

Contenu

Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :

Quels sont les motivations de cette démarche?

Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.

Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.

Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.

Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.

Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

6 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-1337
Document créé le 30/08/06 03:11, dernière modification le Vendredi 17 Juin 2011, 12:12
Source du document imprimé : http:///www.gaudry.be/java-api-rf-java/net/Authenticator.html
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
15838 documents
455 astuces.
550 niouzes.
3107 definitions.
447 membres.
8121 messages.

Document genere en :
0,60 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Si vous ne pouvez pas bien le faire, au moins, faites en sorte qu'il paraisse bien.

Bill Gates
 
l'infobrol
Nous sommes le Vendredi 26 Mai 2017, 09:15, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)