public class Credentials
extends java.lang.Object
Credentials
. Before submitted to a HTTP
backend service, the securtiy restrictions set for the
Credentials
will be validated to ensure it's only used within
the requested context. Credentials
are used in the shared
Session
and will be added to AbstractRestOperation
s if all of
the following restrictions (if set) apply:
You can add multiple realms, hostnames and protocols. If no restriction is
set, the Credentials
might apply to all URLs.
Constructor and Description |
---|
Credentials(java.lang.String username,
java.lang.String password)
Creates new
Credentials with the given username and password
without any restrictions initially set up. |
Modifier and Type | Method and Description |
---|---|
void |
addHostname(java.lang.String hostname)
Adds a new hostname as additional security restriction.
|
void |
addProtocol(java.lang.String protocol)
Adds a protocol as additional security restriction.
|
void |
addRealm(java.lang.String realm)
Adds a realm as additional security restriction.
|
java.util.Vector |
getHostnames()
Returns all hostnames added as restrictions to this
Credentials . |
java.lang.String |
getPassword()
Returns the password stored in the
Credentials . |
java.util.Vector |
getProtocols()
Returns all protocols added as restrictions to this
Credentials . |
java.util.Vector |
getRealms()
Returns all realms added as restrictions to this
Credentials
. |
java.lang.String |
getUsername()
Returns the username stored in the
Credentials . |
boolean |
matchesURL(java.lang.String url)
Checks if a given URL matches the hostnames and protocols set as
restrictions using
addHostname(String) and
addProtocol(String) . |
boolean |
matchesURL(java.lang.String url,
java.lang.String realm)
Checks if the given URL and realm match the hostnames, protocols and
realms set as restrictions using
addHostname(String) ,
addProtocol(String) and addRealm(String) . |
public Credentials(java.lang.String username, java.lang.String password)
Credentials
with the given username and password
without any restrictions initially set up.username
- the username to be usedpassword
- the password to be usedpublic java.lang.String getUsername()
Credentials
.public java.lang.String getPassword()
Credentials
.public void addRealm(java.lang.String realm)
Credentials
should only be returned to a server asking for
the given HTTP realm.realm
- the new realm to be added to the list of realmspublic void addHostname(java.lang.String hostname)
Credentials
should only be returned to a
server with the given hostname.
If an URL is provided as argument, the hostname will be parsed automatically by removing the protocol as well as path informations. It is therefore save to pass URLs to this method.
To verify mathcing hostnames use matchesURL(String)
.
hostname
- the new hostname to be added to the list of hostnamespublic void addProtocol(java.lang.String protocol)
Credentials
should only be returned to a
server using the given protocol.protocol
- the new protocol to be added to the list of protocolspublic boolean matchesURL(java.lang.String url)
addHostname(String)
and
addProtocol(String)
.url
- the URL to checktrue
if it matches the hostnames and protocols,
false
if not.public boolean matchesURL(java.lang.String url, java.lang.String realm)
addHostname(String)
,
addProtocol(String)
and addRealm(String)
.url
- the URL to checkrealm
- the realm to checktrue
if it matches hostnames, protocols and realms
false
if not.public java.util.Vector getRealms()
Credentials
.null
if no
realms are setpublic java.util.Vector getHostnames()
Credentials
.null
if no
hostnames are setpublic java.util.Vector getProtocols()
Credentials
.null
if no
protocols are set