Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Merge branch 'release/1.17.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Retterer committed Oct 20, 2016
2 parents 7b0da3d + 1b77b02 commit f6c025e
Show file tree
Hide file tree
Showing 47 changed files with 3,009 additions and 971 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ stormpath-sdk-php Changelog
===========================


Version 1.17.0
--------------

Released on October 20, 2016

- Added MFA
- Converted HTTP requests to using psr-7
- General Updates and bug fixes

Version 1.16.0
--------------

Expand Down
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,20 @@
},
"require": {
"php": ">=5.5",
"guzzle/guzzle": "3.9.*",
"firebase/php-jwt": "2.2.*",
"phpseclib/phpseclib": "0.3.*|~1.0|~2.0",
"cache/taggable-cache": "0.4.*",
"cache/redis-adapter": "0.4.*",
"cache/memcached-adapter": "0.3.*",
"cache/array-adapter": "0.4.*",
"cache/void-adapter": "0.3.*"
"cache/void-adapter": "0.3.*",
"guzzlehttp/psr7": "^1.3",
"psr/http-message": "^1.0",
"php-http/httplug": "^1.0",
"php-http/discovery": "^1.0",
"php-http/curl-client": "^1.0",
"php-http/message": "^1.3",
"php-http/client-common": "^1.2"
},
"require-dev": {
"phpunit/phpunit": "4.*",
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<testsuites>
<testsuite name="Stormpath SDK Test Suite">
<directory suffix="Test.php">./tests</directory>
<exclude>./tests/Mfa/Physical</exclude>
</testsuite>
</testsuites>

Expand Down
48 changes: 40 additions & 8 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,23 @@
* limitations under the License.
*/

use Cache\Taggable\TaggablePSR6PoolAdapter;
use Http\Client\HttpClient;
use Http\Message\MessageFactory;
use Http\Message\UriFactory;
use Stormpath\Cache\CacheManager;
use Stormpath\Cache\PSR6CacheManagerInterface;
use Stormpath\Cache\CachePSR6Adapter;
use Stormpath\Cache\PSR6CacheManagerInterface;
use Stormpath\DataStore\DefaultDataStore;
use Stormpath\Exceptions\Cache\InvalidCacheManagerException;
use Stormpath\Exceptions\Cache\InvalidLegacyCacheManagerException;
use Stormpath\Http\Authc\RequestSigner;
use Stormpath\Http\HttpClientRequestExecutor;
use Stormpath\Http\Authc\SAuthc1Authentication;
use Stormpath\Http\Authc\StormpathBasicAuthentication;
use Stormpath\Resource\Resource;
use Stormpath\Stormpath;
use Stormpath\Util\Magic;
use Cache\Taggable\TaggablePSR6PoolAdapter;
use Stormpath\Http\Authc\SAuthc1RequestSigner;
use Stormpath\Http\Authc\BasicRequestSigner;

function toObject($properties)
{
Expand Down Expand Up @@ -111,14 +116,12 @@ class Client extends Magic
* @param $baseUrl optional parameter for specifying the base URL when not using the default one
* (https://api.stormpath.com/v1).
*/
public function __construct(ApiKey $apiKey, $cacheManager, $cacheManagerOptions, $baseUrl = null, RequestSigner $requestSigner = null)
public function __construct(ApiKey $apiKey, $cacheManager, $cacheManagerOptions, $baseUrl = null, RequestSigner $requestSigner = null, $authenticationScheme = Stormpath::SAUTHC1_AUTHENTICATION_SCHEME, HttpClient $httpClient = null, MessageFactory $messageFactory = null, UriFactory $uriFactory = null)
{
parent::__construct();
self::$cacheManager = $cacheManager;
self::$cacheManagerOptions = $cacheManagerOptions;

$requestExecutor = new HttpClientRequestExecutor($requestSigner);

if (is_string($cacheManager)) { // Legacy cache manager
$legacyCache = new $cacheManager($cacheManagerOptions);

Expand All @@ -137,7 +140,28 @@ public function __construct(ApiKey $apiKey, $cacheManager, $cacheManagerOptions,
}

$this->cachePool = TaggablePSR6PoolAdapter::makeTaggable($cache);
$this->dataStore = new DefaultDataStore($requestExecutor, $apiKey, $this->cachePool, $baseUrl);

if (!$requestSigner) {
if ($authenticationScheme === Stormpath::SAUTHC1_AUTHENTICATION_SCHEME) {
$auth = new SAuthc1Authentication($apiKey);
} elseif ($authenticationScheme === Stormpath::BASIC_AUTHENTICATION_SCHEME) {
$auth = new StormpathBasicAuthentication($apiKey);
} else {
throw new InvalidArgumentException("Unknown authentication scheme \"" . $authenticationScheme . "\"");
}
} else {
if ($requestSigner instanceOf SAuthc1RequestSigner) {
$auth = new SAuthc1Authentication($apiKey);
} elseif ($requestSigner instanceOf BasicRequestSigner) {
$auth = new StormpathBasicAuthentication($apiKey);
} else {
throw new InvalidArgumentException("Unknown RequestSigner \"" . get_class($requestSigner) . "\" passed. Instead of passing a request signer, pass the \$authenticationScheme parameter.");
}
}

$this->dataStore = new DefaultDataStore($apiKey, $auth, $this->cachePool, $httpClient, $messageFactory, $uriFactory, $baseUrl);


}

public static function get($href, $className, $path = null, array $options = array())
Expand Down Expand Up @@ -220,6 +244,14 @@ public function getCachePool()
public static function tearDown()
{
static::$instance = NULL;
static::$apiKeyFileLocation;
static::$apiKeyProperties;
static::$apiKeyIdPropertyName = "apiKey.id";
static::$apiKeySecretPropertyName = "apiKey.secret";
static::$baseUrl;
static::$cacheManager = 'Array';
static::$cacheManagerOptions = array();
static::$authenticationScheme = Stormpath::SAUTHC1_AUTHENTICATION_SCHEME;
}


Expand Down
85 changes: 32 additions & 53 deletions src/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@
use Stormpath\Cache\ArrayCacheManager;
use Stormpath\Cache\MemcachedCacheManager;
use Stormpath\Cache\NullCacheManager;
use Stormpath\Cache\RedisCacheManager;
use Stormpath\Cache\PSR6CacheManagerInterface;
use Stormpath\Cache\Exceptions\InvalidCacheManagerException;
use Stormpath\Http\Authc\SAuthc1RequestSigner;
use Stormpath\Cache\RedisCacheManager;
use Stormpath\Http\DefaultRequest;
use Stormpath\Http\HttpClientRequestExecutor;
use Stormpath\Http\Request;
use Stormpath\Util\Magic;
use Stormpath\Util\Spyc;
use Stormpath\Util\YAMLUtil;

/**
* A <a href="http://en.wikipedia.org/wiki/Builder_pattern">Builder design pattern</a> implementation used to
Expand Down Expand Up @@ -57,7 +53,7 @@ class ClientBuilder extends Magic
private $apiKeySecretPropertyName = "apiKey.secret";
private $apiKeyProperties;
private $apiKeyFileLocation;
private $cacheManager = NULL;
private $cacheManager = null;
private $cacheManagerOptions = array();
private $baseURL;
private $authenticationScheme = Stormpath::SAUTHC1_AUTHENTICATION_SCHEME;
Expand Down Expand Up @@ -216,7 +212,7 @@ public function setApiKeyProperties($apiKeyProperties)

public function setCacheManager($cacheManager)
{
if ($cacheManager instanceOf PSR6CacheManagerInterface) {
if ($cacheManager instanceof PSR6CacheManagerInterface) {
$this->cacheManager = $cacheManager;
} else {
switch ($cacheManager) {
Expand All @@ -240,10 +236,10 @@ public function setCacheManager($cacheManager)
return $this;
}

public function setCacheManagerOptions(Array $cacheManagerOptions = array())
public function setCacheManagerOptions(array $cacheManagerOptions = array())
{
$this->cacheManagerOptions = $this->setCacheOptionsArray($cacheManagerOptions);
if(!$this->cacheManager) {
if (!$this->cacheManager) {
$this->setCacheManager($this->cacheManagerOptions['cachemanager']);
}
return $this;
Expand Down Expand Up @@ -278,46 +274,41 @@ public function build()
{
$apiKeyProperties = null;

if ($this->apiKeyProperties)
{
if ($this->apiKeyProperties) {

$apiKeyProperties = parse_ini_string($this->apiKeyProperties);

} else
{
} else {

// need to load the properties file
$apiKeyProperties = $this->getFileExtract();

if (!$apiKeyProperties)
{
if (!$apiKeyProperties) {
throw new \InvalidArgumentException('No API Key file could be found or loaded from a file location. ' .
'Please configure the "apiKeyFileLocation" property or alternatively configure a ' .
"PHP 'ini' compliant string, by setting the 'apiKeyProperties' property.");
}
}

if (!$this->cacheManager)
{
if (!$this->cacheManager) {
$this->setCacheManagerOptions();
}


$apiKeyId = $this->getRequiredPropertyValue($apiKeyProperties, 'apiKeyId', $this->apiKeyIdPropertyName);

$apiKeySecret = $this->getRequiredPropertyValue($apiKeyProperties, 'apiKeySecret', $this->apiKeySecretPropertyName);

$apiKey = new ApiKey($apiKeyId, $apiKeySecret);

$signer = $this->resolveSigner();
$requestSigner = new $signer;
Client::$apiKeyProperties = "apiKey.id=".$apiKeyId."\napiKey.secret=".$apiKeySecret;

return new Client(
$apiKey,
$this->cacheManager,
$this->cacheManagerOptions,
$this->baseURL,
$requestSigner
null,
$this->authenticationScheme
);

}
Expand All @@ -332,8 +323,7 @@ private function getRequiredPropertyValue(array $apiKeyProperties, $masterName,
{
$result = array_key_exists($propertyName, $apiKeyProperties) ? $apiKeyProperties[$propertyName] : false;

if (!$result)
{
if (!$result) {
throw new \InvalidArgumentException("There is no '$propertyName' property in the " .
"configured apiKey file or properties string. You can either specify that property or " .
"configure the '$masterName' PropertyName value on the ClientBuilder to specify a " .
Expand All @@ -346,29 +336,25 @@ private function getRequiredPropertyValue(array $apiKeyProperties, $masterName,
private function getFileExtract()
{
// @codeCoverageIgnoreStart
if (stripos($this->apiKeyFileLocation, 'http') === 0)
{
if (stripos($this->apiKeyFileLocation, 'http') === 0) {
$request = new DefaultRequest(Request::METHOD_GET, $this->apiKeyFileLocation);

$executor = new HttpClientRequestExecutor;

try {
$response = $executor->executeRequest($request);

if (!$response->isError())
{
if (!$response->isError()) {
return parse_ini_string($response->getBody());

}
} catch (Exception $e)
{
} catch (Exception $e) {
return false;
}
}
// @codeCoverageIgnoreEnd

if ($this->apiKeyFileLocation)
{
if ($this->apiKeyFileLocation) {
return parse_ini_file($this->apiKeyFileLocation);
}
}
Expand All @@ -384,25 +370,25 @@ private function setCacheOptionsArray($overrides)
'regions' => array(
'accounts' => array(
'ttl' => 60,
'tti' => 120
'tti' => 120,
),
'applications' => array(
'ttl' => 60,
'tti' => 120
'tti' => 120,
),
'directories' => array(
'ttl' => 60,
'tti' => 120
'tti' => 120,
),
'groups' => array(
'ttl' => 60,
'tti' => 120
'tti' => 120,
),
'tenants' => array(
'ttl' => 60,
'tti' => 120
'tti' => 120,
),
)
),
);
return array_replace($defaults, $overrides);
}
Expand All @@ -411,30 +397,23 @@ private function qualifyCacheManager($cacheManager)
{
$notCoreClass = true;

if(class_exists($cacheManager))
if (class_exists($cacheManager)) {
$notCoreClass = class_implements($cacheManager) == 'Stormpath\Cache\CacheManager';
}

if(class_exists($cacheManager) && $notCoreClass) return $cacheManager;
if (class_exists($cacheManager) && $notCoreClass) {
return $cacheManager;
}

if(strpos($cacheManager, 'CacheManager')) {
if (strpos($cacheManager, 'CacheManager')) {
$cacheManagerPath = "{$cacheManager}";
} else {
$cacheManagerPath = "Stormpath\\Cache\\{$cacheManager}CacheManager";
}


if(class_exists($cacheManagerPath)) return $cacheManagerPath;

}

private function resolveSigner()
{
$signer = "\\Stormpath\\Http\\Authc\\" . $this->authenticationScheme . "RequestSigner";

if(!class_exists($signer))
throw new \InvalidArgumentException('Authentication Scheme is not supported.');

return new $signer;
if (class_exists($cacheManagerPath)) {
return $cacheManagerPath;
}

}
}
Loading

0 comments on commit f6c025e

Please sign in to comment.