Class SURL
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://[email protected]/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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Indicates, that we have no authentication to access the URL. -
Method Summary
Modifier and TypeMethodDescriptionstatic SURL
Create a secure URL from a String.static SURL
Create a secure URL from ajava.net.URL
object.byte[]
getBytes()
Reads from an endpoint (with configured credentials and proxy) the response as blob.byte[]
getBytesOnPost
(Proxy proxy, SecurityAuthentication authentication, String data, Map<String, Object> headers) Post to an endpoint with a given authentication and proxy the response as blob.boolean
Informs, if SecurityCredentials are configured for this connection.boolean
isUrlOk()
Check SecurityProfile to see if this URL can be opened.toString()
-
Field Details
-
WITHOUT_AUTHENTICATION
Indicates, that we have no authentication to access the URL.- See Also:
-
-
Method Details
-
create
Create a secure URL from a String.The url must be http or https. Return null in case of error or if
url
is null- Parameters:
url
- plain url starting by http:// or https//- Returns:
- the secure URL or null
-
create
Create a secure URL from ajava.net.URL
object.It takes into account credentials.
- Parameters:
url
-- Returns:
- the secure URL
- Throws:
MalformedURLException
- ifurl
is nullURISyntaxException
-
readRasterImageFromURL
-
isUrlOk
public boolean isUrlOk()Check SecurityProfile to see if this URL can be opened. -
toString
-
getBytes
public byte[] getBytes()Reads from an endpoint (with configured credentials and proxy) the response as blob.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
- Returns:
- data loaded data from endpoint
-
getBytesOnPost
public byte[] getBytesOnPost(Proxy proxy, SecurityAuthentication authentication, String data, Map<String, Object> headers) Post to an endpoint with a given authentication and proxy the response as blob.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.
- Parameters:
authentication
- authentication object data. Caller is responsible to erase credentialsproxy
- proxy configurationdata
- content to postheaders
- headers, if needed- Returns:
- loaded data from endpoint
-
openStream
-
isAuthorizationConfigured
public boolean isAuthorizationConfigured()Informs, if SecurityCredentials are configured for this connection.- Returns:
- true, if credentials will be used for a connection
-