public class SURL
extends java.lang.Object
This class should be used instead of java.net.URL.
This class does some control access and manages access-tokens via URL. If a URL contains a access-token, similar to a user prefix, SURL loads the authorization config for this user-token and passes the credentials to the host.
Example:
SURL url = SURL.create ("https://jenkins-access@jenkins.mycompany.com/api/json")The
jenkins-access
will checked against the Security context access
token configuration. If a configuration exists for this token name, the token
will be removed from the URL and the credentials will be added to the
headers. If the token is not found, the URL remains as it is and no separate
authentication will be performed.
TODO: Some methods should be moved to a HttpClient implementation, because
SURL is not the valid class to manage it.
TODO: BAD_HOSTS implementation should be reviewed and moved to HttpClient
implementation with a circuit-breaker.
TODO: Token expiration with refresh should be implemented in future.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
WITHOUT_AUTHENTICATION
Indicates, that we have no authentication to access the URL.
|
Modifier and Type | Method and Description |
---|---|
static SURL |
create(java.lang.String url)
Create a secure URL from a String.
|
static SURL |
create(java.net.URL url)
Create a secure URL from a
java.net.URL object. |
byte[] |
getBytes()
Reads from an endpoint (with configured credentials and proxy) the response
as blob.
|
byte[] |
getBytesOnPost(java.net.Proxy proxy,
SecurityAuthentication authentication,
java.lang.String data,
java.util.Map<java.lang.String,java.lang.Object> headers)
Post to an endpoint with a given authentication and proxy the response as
blob.
|
boolean |
isAuthorizationConfigured()
Informs, if SecurityCredentials are configured for this connection.
|
boolean |
isUrlOk()
Check SecurityProfile to see if this URL can be opened.
|
java.io.InputStream |
openStream() |
java.awt.image.BufferedImage |
readRasterImageFromURL() |
java.lang.String |
toString() |
public static final java.lang.String WITHOUT_AUTHENTICATION
public static SURL create(java.lang.String url)
The url must be http or https. Return null in case of error or if
url
is null
url
- plain url starting by http:// or https//public static SURL create(java.net.URL url) throws java.net.MalformedURLException, java.net.URISyntaxException
java.net.URL
object.
It takes into account credentials.
url
- java.net.MalformedURLException
- if url
is nulljava.net.URISyntaxException
public java.awt.image.BufferedImage readRasterImageFromURL()
public boolean isUrlOk()
public java.lang.String toString()
toString
in class java.lang.Object
public byte[] getBytes()
This method allows access to an endpoint, with a configured SecurityCredentials object. The credentials will load on the fly and authentication fetched from an authentication-manager. Caching of tokens is not supported.
authors: Alain Corbiere, Aljoscha Rittner
public byte[] getBytesOnPost(java.net.Proxy proxy, SecurityAuthentication authentication, java.lang.String data, java.util.Map<java.lang.String,java.lang.Object> headers)
This method allows a parametrized access to an endpoint, without a configured SecurityCredentials object. This is useful to access internally identity providers (IDP), or authorization servers (to request access tokens).
This method don't use the "bad-host" functionality, because the access to infrastructure services should not be obfuscated by some internal management.
Please don't use this method directly from DSL scripts.
authentication
- authentication object data. Caller is responsible to
erase credentialsproxy
- proxy configurationdata
- content to postheaders
- headers, if neededpublic java.io.InputStream openStream()
public boolean isAuthorizationConfigured()