You are here

function acquia_search_authenticator in Acquia Connector 7.2

Same name and namespace in other branches
  1. 7.3 acquia_search/acquia_search.module \acquia_search_authenticator()
  2. 7 acquia_search/acquia_search.module \acquia_search_authenticator()

Creates an authenticator based on a data string and HMAC-SHA1.

2 calls to acquia_search_authenticator()
AcquiaSearchUnitTestCase::testHMACCookie in acquia_search/tests/acquia_search.test
Tests HMAC generation.
acquia_search_auth_cookie in acquia_search/acquia_search.module
Modify a solr base url and construct a hmac authenticator cookie.

File

acquia_search/acquia_search.module, line 749
Integration between Acquia Drupal and Acquia's hosted solr search service.

Code

function acquia_search_authenticator($string, $nonce, $derived_key = NULL, $env_id = NULL, $time = NULL) {
  if (empty($derived_key)) {
    $derived_key = _acquia_search_derived_key($env_id);
  }
  if (empty($derived_key)) {

    // Expired or invalid subscription - don't continue.
    return '';
  }
  else {

    // @see http://stackoverflow.com/questions/2524680/check-whether-the-string-is-a-unix-timestamp
    if (!(is_numeric($time) && (int) $time == $time)) {

      // Use time() instead of REQUEST_TIME so that long-running operations like
      // `drush solr-index` continually have fresh request times. Use of
      // REQUEST_TIME will cause Acquia Search to respond with a 403 Forbidden
      // after the acquia_solr_time value is older than 15 minutes.
      $time = time();
    }
    return 'acquia_solr_time=' . $time . '; acquia_solr_nonce=' . $nonce . '; acquia_solr_hmac=' . hash_hmac('sha1', $time . $nonce . $string, $derived_key) . ';';
  }
}