Package com.globalmentor.net
Class AbstractClient
- java.lang.Object
-
- com.globalmentor.net.AbstractClient
-
-
Constructor Summary
Constructors Constructor Description AbstractClient()
Default constructor with no authenticator.AbstractClient(Authenticable authenticator)
Authenticator constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Authenticable
getAuthenticator()
protected AbstractClient
getDefaultInstance()
char[]
getPassword(java.net.URI rootURI, java.lang.String realm, java.lang.String username)
Retrieves the password stored for a given user in a given realm of a given root URI.java.net.PasswordAuthentication
getPasswordAuthentication(java.net.URI uri, java.lang.String prompt)
Determines password information in relation to a given URI and description.java.util.Set<java.lang.String>
getRealms(java.net.URI rootURI)
Retrieves the realms stored for a given root URI.java.lang.String
getUsername()
java.util.Set<java.lang.String>
getUsernames(java.net.URI rootURI, java.lang.String realm)
Retrieves any users for which authentication information is stored for a given realm of a given root URI.boolean
isLogged()
void
putPassword(java.net.URI rootURI, java.lang.String realm, java.lang.String username, char[] password)
Caches the password for a given user in a given realm of a given root URI.void
removePassword(java.net.URI rootURI, java.lang.String realm, java.lang.String username)
Removes the password stored for a given user in a given realm of a given root URI.void
setAuthenticator(Authenticable authenticable)
Sets the authenticator object used to retrieve client authentication.void
setLogged(boolean logged)
Sets whether this client logs its communication.void
setUsername(java.lang.String username)
Restricts this client to particular user.
-
-
-
Constructor Detail
-
AbstractClient
public AbstractClient()
Default constructor with no authenticator.
-
AbstractClient
public AbstractClient(Authenticable authenticator)
Authenticator constructor.- Parameters:
authenticator
- The authenticator to use for this client, ornull
if the default authenticator should be used if available.
-
-
Method Detail
-
isLogged
public boolean isLogged()
-
setLogged
public void setLogged(boolean logged)
Sets whether this client logs its communication.
-
getDefaultInstance
protected AbstractClient getDefaultInstance()
- Returns:
- The default instance of this class, or
null
if there is no default instance.
-
setAuthenticator
public void setAuthenticator(Authenticable authenticable)
Sets the authenticator object used to retrieve client authentication.- Parameters:
authenticable
- The object to retrieve authentication information regarding a client.
-
getAuthenticator
protected Authenticable getAuthenticator()
- Returns:
- The authenticator associated with this client or, if there is no authenticator defined, the authenticator associated with the default instance of the client.
-
getUsername
public java.lang.String getUsername()
- Returns:
- The ID of the user to which this client is restricted, or
null
if this client is not restricted to a single user.
-
setUsername
public void setUsername(java.lang.String username)
Restricts this client to particular user.- Parameters:
username
- The ID of the user to which this client is restricted, ornull
if this client should not restricted to a single user.
-
getRealms
public java.util.Set<java.lang.String> getRealms(java.net.URI rootURI)
Retrieves the realms stored for a given root URI.- Parameters:
rootURI
- The root URI of the domain governing the realms and user passwords.- Returns:
- A read-only set of reallms of the given root URI.
-
getUsernames
public java.util.Set<java.lang.String> getUsernames(java.net.URI rootURI, java.lang.String realm)
Retrieves any users for which authentication information is stored for a given realm of a given root URI.- Parameters:
rootURI
- The root URI of the domain governing the realms and user passwords.realm
- The realm of protection.- Returns:
- A read-only set of usernames for which authentication information is stored in this for the given realm of the given root URI.
-
getPassword
public char[] getPassword(java.net.URI rootURI, java.lang.String realm, java.lang.String username)
Retrieves the password stored for a given user in a given realm of a given root URI.- Parameters:
rootURI
- The root URI of the domain governing the realms and user passwords.realm
- The realm of protection.username
- The user for which a password is stored.- Returns:
- The password of the given user, or
null
if no password is present for the given root URI, realm, and user.
-
putPassword
public void putPassword(java.net.URI rootURI, java.lang.String realm, java.lang.String username, char[] password)
Caches the password for a given user in a given realm of a given root URI.- Parameters:
rootURI
- The root URI of the domain governing the realms and user passwords.realm
- The realm of protection.username
- The user for which a password is stored.password
- The password of the given user.
-
removePassword
public void removePassword(java.net.URI rootURI, java.lang.String realm, java.lang.String username)
Removes the password stored for a given user in a given realm of a given root URI.- Parameters:
rootURI
- The root URI of the domain governing the realms and user passwords.realm
- The realm of protection.username
- The user for which a password is stored.
-
getPasswordAuthentication
public java.net.PasswordAuthentication getPasswordAuthentication(java.net.URI uri, java.lang.String prompt)
Determines password information in relation to a given URI and description.- Parameters:
uri
- The URI for which authentication is requested.prompt
- A description of the authentication.- Returns:
- The password authentication collected from the user, or
null
if none is provided.
-
-