Class TrustedHttpClientImpl
java.lang.Object
org.opencastproject.kernel.security.TrustedHttpClientImpl
- All Implemented Interfaces:
HttpConnectionMXBean,TrustedHttpClient
public class TrustedHttpClientImpl
extends Object
implements TrustedHttpClient, HttpConnectionMXBean
An http client that executes secure (though not necessarily encrypted) http requests.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringHeader name used to request a new nonce from a server a request is sent to.static final intThe default time until a connection attempt failsstatic final intThe default number of times to attempt a request after it has failed due to a nonce expiring.static final intThe default amount of time to wait after a nonce timeout.static final intDefault maximum amount of time in a random range between 0 and this value to add to the base time.static final intThe default time between packets that causes a connection to failprotected static final longThe default time before a piece of signed content expires. 1 Minute.static final StringThe configuration property specifying the digest authentication passwordstatic final StringThe configuration property specifying the digest authentication userprotected static final StringThe configuration property specifying the duration a signed url will remain valid for.static final StringThe configuration property specifying the minimum amount of time in seconds wait before retrying a request after a nonce timeout.static final StringThe configuration property specifying the number of times to retry after the nonce timesouts on a request.static final StringThe configuration property specifying the maximum for a random amount of time in seconds above the base time to wait.protected OrganizationDirectoryServiceThe organization directory serviceprotected StringThe configured password to send as part of the digest authenticated requestprotected Map<org.apache.http.HttpResponse, org.apache.http.impl.client.CloseableHttpClient> The map of open responses to their http clients, which need to be closed after we are finished with the responseprotected SecurityServiceThe security serviceprotected UrlSigningServiceThe url signing serviceprotected StringThe configured username to send as part of the digest authenticated request -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate(org.osgi.service.component.ComponentContext cc) voidclose(org.apache.http.HttpResponse response) Closes this response.voidorg.apache.http.HttpResponseexecute(org.apache.http.client.methods.HttpUriRequest httpUriRequest) Executes an HttpRequest using a secure, but not necessarily encrypted, http connection.org.apache.http.HttpResponseexecute(org.apache.http.client.methods.HttpUriRequest httpUriRequest, int connectionTimeout, int socketTimeout) Executes an HttpRequest using a secure, but not necessarily encrypted, http connection, waiting for the specified timeouts.intintGets the number of open http connectionsprotected String[]getRealmAndNonce(org.apache.http.client.methods.HttpRequestBase request) Perform a request, and extract the realm and nonce valuesintintprotected org.apache.http.client.methods.HttpUriRequestgetSignedUrl(org.apache.http.client.methods.HttpUriRequest httpUriRequest) If the request is a GET, sign the URL and return a newHttpUriRequestthat is signed.org.apache.http.impl.client.HttpClientBuildermakeHttpClientBuilder(int connectionTimeout, int socketTimeout) Creates a new HttpClientBuilder to use for making requests.voidsetOrganizationDirectoryService(OrganizationDirectoryService organizationDirectoryService) Sets the organization directory service.voidsetSecurityService(SecurityService securityService) Sets the security service.voidsetServiceRegistry(ServiceRegistry serviceRegistry) Sets the service registry.voidsetUrlSigningService(UrlSigningService urlSigningService) Sets the url signing service.voidunsetServiceRegistry(ServiceRegistry serviceRegistry) Unsets the service registry.
-
Field Details
-
AUTHORIZATION_HEADER_NAME
Header name used to request a new nonce from a server a request is sent to.- See Also:
-
DIGEST_AUTH_USER_KEY
The configuration property specifying the digest authentication user- See Also:
-
DIGEST_AUTH_PASS_KEY
The configuration property specifying the digest authentication password- See Also:
-
NONCE_TIMEOUT_RETRY_KEY
The configuration property specifying the number of times to retry after the nonce timesouts on a request.- See Also:
-
INTERNAL_URL_SIGNING_DURATION_KEY
The configuration property specifying the duration a signed url will remain valid for.- See Also:
-
NONCE_TIMEOUT_RETRY_BASE_TIME_KEY
The configuration property specifying the minimum amount of time in seconds wait before retrying a request after a nonce timeout.- See Also:
-
NONCE_TIMEOUT_RETRY_MAXIMUM_VARIABLE_TIME_KEY
The configuration property specifying the maximum for a random amount of time in seconds above the base time to wait.- See Also:
-
DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_CONNECTION_TIMEOUTThe default time until a connection attempt fails- See Also:
-
DEFAULT_SOCKET_TIMEOUT
public static final int DEFAULT_SOCKET_TIMEOUTThe default time between packets that causes a connection to fail- See Also:
-
DEFAULT_NONCE_TIMEOUT_RETRIES
public static final int DEFAULT_NONCE_TIMEOUT_RETRIESThe default number of times to attempt a request after it has failed due to a nonce expiring.- See Also:
-
DEFAULT_RETRY_BASE_TIME
public static final int DEFAULT_RETRY_BASE_TIMEThe default amount of time to wait after a nonce timeout.- See Also:
-
DEFAULT_RETRY_MAXIMUM_VARIABLE_TIME
public static final int DEFAULT_RETRY_MAXIMUM_VARIABLE_TIMEDefault maximum amount of time in a random range between 0 and this value to add to the base time.- See Also:
-
DEFAULT_URL_SIGNING_EXPIRES_DURATION
protected static final long DEFAULT_URL_SIGNING_EXPIRES_DURATIONThe default time before a piece of signed content expires. 1 Minute. These are internal calls to another server, if we can't make the request in under a minute something has gone horribly wrong.- See Also:
-
user
The configured username to send as part of the digest authenticated request -
pass
The configured password to send as part of the digest authenticated request -
responseMap
protected Map<org.apache.http.HttpResponse,org.apache.http.impl.client.CloseableHttpClient> responseMapThe map of open responses to their http clients, which need to be closed after we are finished with the response -
securityService
The security service -
organizationDirectoryService
The organization directory service -
urlSigningService
The url signing service
-
-
Constructor Details
-
TrustedHttpClientImpl
public TrustedHttpClientImpl() -
TrustedHttpClientImpl
-
-
Method Details
-
activate
public void activate(org.osgi.service.component.ComponentContext cc) -
setServiceRegistry
Sets the service registry.- Parameters:
serviceRegistry- the serviceRegistry to set
-
unsetServiceRegistry
Unsets the service registry.- Parameters:
serviceRegistry- the serviceRegistry to unset (unused, but needed for OSGI)
-
setSecurityService
Sets the security service.- Parameters:
securityService- the security service
-
setOrganizationDirectoryService
public void setOrganizationDirectoryService(OrganizationDirectoryService organizationDirectoryService) Sets the organization directory service.- Parameters:
organizationDirectoryService- the organization directory service
-
setUrlSigningService
Sets the url signing service.- Parameters:
urlSigningService- The signing service to sign urls with.
-
deactivate
public void deactivate() -
makeHttpClientBuilder
public org.apache.http.impl.client.HttpClientBuilder makeHttpClientBuilder(int connectionTimeout, int socketTimeout) Creates a new HttpClientBuilder to use for making requests. -
execute
public org.apache.http.HttpResponse execute(org.apache.http.client.methods.HttpUriRequest httpUriRequest) throws TrustedHttpClientException Executes an HttpRequest using a secure, but not necessarily encrypted, http connection.- Specified by:
executein interfaceTrustedHttpClient- Parameters:
httpUriRequest- The http request- Returns:
- the http response returned by the server
- Throws:
TrustedHttpClientException- See Also:
-
execute
public org.apache.http.HttpResponse execute(org.apache.http.client.methods.HttpUriRequest httpUriRequest, int connectionTimeout, int socketTimeout) throws TrustedHttpClientException Description copied from interface:TrustedHttpClientExecutes an HttpRequest using a secure, but not necessarily encrypted, http connection, waiting for the specified timeouts.- Specified by:
executein interfaceTrustedHttpClient- Parameters:
httpUriRequest- The http requestconnectionTimeout- the wait time in milliseconds at which a connection attempt will throwsocketTimeout- the maximum time in milliseconds allowed between packets before this method will throw- Returns:
- the http response returned by the server
- Throws:
TrustedHttpClientException
-
getSignedUrl
protected org.apache.http.client.methods.HttpUriRequest getSignedUrl(org.apache.http.client.methods.HttpUriRequest httpUriRequest) throws TrustedHttpClientException If the request is a GET, sign the URL and return a newHttpUriRequestthat is signed.- Parameters:
httpUriRequest- The possible URI to sign.- Returns:
- HttpUriRequest if the request is a GET and is configured to be signed.
- Throws:
TrustedHttpClientException- Thrown if there is a problem signing the URL.
-
close
Closes this response. The caller must call close() once finished reading the response.- Specified by:
closein interfaceTrustedHttpClient- Parameters:
response- The response to close- Throws:
IOException- See Also:
-
getRealmAndNonce
protected String[] getRealmAndNonce(org.apache.http.client.methods.HttpRequestBase request) throws TrustedHttpClientException Perform a request, and extract the realm and nonce values- Parameters:
request- The request to execute in order to obtain the realm and nonce- Returns:
- A String[] containing the {realm, nonce}
- Throws:
TrustedHttpClientException
-
getOpenConnections
public int getOpenConnections()Description copied from interface:HttpConnectionMXBeanGets the number of open http connections- Specified by:
getOpenConnectionsin interfaceHttpConnectionMXBean
-
getNonceTimeoutRetries
public int getNonceTimeoutRetries()- Returns:
- Returns the number of times the TrustedHttpClient will retry a request if nonce timeouts are occuring.
-
getRetryBaseDelay
public int getRetryBaseDelay()- Returns:
- The minimum amount of time to wait in seconds after a nonce timeout before retrying.
-
getRetryMaximumVariableTime
public int getRetryMaximumVariableTime()- Returns:
- The maximum amount of time to wait in seconds after a nonce timeout in addition to the base delay.
-