Class TrustedHttpClientImpl
java.lang.Object
org.opencastproject.kernel.security.TrustedHttpClientImpl
- All Implemented Interfaces:
HttpConnectionMXBean,org.opencastproject.security.api.TrustedHttpClient
public class TrustedHttpClientImpl
extends Object
implements org.opencastproject.security.api.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 org.opencastproject.security.api.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 org.opencastproject.security.api.SecurityServiceThe security serviceprotected org.opencastproject.security.urlsigning.service.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) voidorg.apache.http.HttpResponseexecute(org.apache.http.client.methods.HttpUriRequest httpUriRequest) org.apache.http.HttpResponseexecute(org.apache.http.client.methods.HttpUriRequest httpUriRequest, int connectionTimeout, int socketTimeout) 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(org.opencastproject.security.api.OrganizationDirectoryService organizationDirectoryService) Sets the organization directory service.voidsetSecurityService(org.opencastproject.security.api.SecurityService securityService) Sets the security service.voidsetServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry serviceRegistry) Sets the service registry.voidsetUrlSigningService(org.opencastproject.security.urlsigning.service.UrlSigningService urlSigningService) Sets the url signing service.voidunsetServiceRegistry(org.opencastproject.serviceregistry.api.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
protected org.opencastproject.security.api.SecurityService securityServiceThe security service -
organizationDirectoryService
protected org.opencastproject.security.api.OrganizationDirectoryService organizationDirectoryServiceThe organization directory service -
urlSigningService
protected org.opencastproject.security.urlsigning.service.UrlSigningService urlSigningServiceThe url signing service
-
-
Constructor Details
-
TrustedHttpClientImpl
public TrustedHttpClientImpl() -
TrustedHttpClientImpl
-
-
Method Details
-
activate
public void activate(org.osgi.service.component.ComponentContext cc) -
setServiceRegistry
public void setServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry serviceRegistry) Sets the service registry.- Parameters:
serviceRegistry- the serviceRegistry to set
-
unsetServiceRegistry
public void unsetServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry serviceRegistry) Unsets the service registry.- Parameters:
serviceRegistry- the serviceRegistry to unset (unused, but needed for OSGI)
-
setSecurityService
public void setSecurityService(org.opencastproject.security.api.SecurityService securityService) Sets the security service.- Parameters:
securityService- the security service
-
setOrganizationDirectoryService
public void setOrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService organizationDirectoryService) Sets the organization directory service.- Parameters:
organizationDirectoryService- the organization directory service
-
setUrlSigningService
public void setUrlSigningService(org.opencastproject.security.urlsigning.service.UrlSigningService urlSigningService) 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 org.opencastproject.security.api.TrustedHttpClientException - Specified by:
executein interfaceorg.opencastproject.security.api.TrustedHttpClient- Throws:
org.opencastproject.security.api.TrustedHttpClientException- See Also:
-
execute
public org.apache.http.HttpResponse execute(org.apache.http.client.methods.HttpUriRequest httpUriRequest, int connectionTimeout, int socketTimeout) throws org.opencastproject.security.api.TrustedHttpClientException - Specified by:
executein interfaceorg.opencastproject.security.api.TrustedHttpClient- Throws:
org.opencastproject.security.api.TrustedHttpClientException
-
getSignedUrl
protected org.apache.http.client.methods.HttpUriRequest getSignedUrl(org.apache.http.client.methods.HttpUriRequest httpUriRequest) throws org.opencastproject.security.api.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:
org.opencastproject.security.api.TrustedHttpClientException- Thrown if there is a problem signing the URL.
-
close
- Specified by:
closein interfaceorg.opencastproject.security.api.TrustedHttpClient- Throws:
IOException- See Also:
-
getRealmAndNonce
protected String[] getRealmAndNonce(org.apache.http.client.methods.HttpRequestBase request) throws org.opencastproject.security.api.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:
org.opencastproject.security.api.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.
-