public function testDelete() { $application = \Stormpath\Resource\Application::instantiate(array('name' => makeUniqueName('AccountStoreMappingTest Test Delete'))); self::createResource(\Stormpath\Resource\Application::PATH, $application); $accountStoreMappingWithDir = \Stormpath\Resource\AccountStoreMapping::create(array('accountStore' => self::$directory, 'application' => $application)); $href = $accountStoreMappingWithDir->href; $accountStoreMapping = \Stormpath\Resource\AccountStoreMapping::get($href); $this->assertInstanceOf('Stormpath\\Resource\\AccountStoreMapping', $accountStoreMapping); $this->assertInstanceOf('Stormpath\\Resource\\Directory', $accountStoreMapping->accountStore); $accountStoreMapping->delete(); try { \Stormpath\Resource\AccountStoreMapping::get($href); $application->delete(); $this->fail('Should have thrown a ResourceError.'); } catch (\Stormpath\Resource\ResourceError $re) { $this->assertTrue(true); } $application->delete(); }
public function createAccountStoreMapping(AccountStoreMapping $accountStoreMapping, array $options = array()) { return AccountStoreMapping::_create($accountStoreMapping, $this, $this->dataStore, $options); }
public function testAuthenticateWithAccountStore() { $application = self::$application; $groupA = new \stdClass(); $groupA->name = 'New Group in town A: ' . md5(time() . microtime() . uniqid()); $groupA = \Stormpath\Resource\Group::instantiate($groupA); $application->createGroup($groupA); $groupB = new \stdClass(); $groupB->name = 'New Group in town B: ' . md5(time() . microtime() . uniqid()); $groupB = \Stormpath\Resource\Group::instantiate($groupB); $application->createGroup($groupB); $accountStoreMappingA = \Stormpath\Resource\AccountStoreMapping::instantiate(array('accountStore' => $groupA)); $application->createAccountStoreMapping($accountStoreMappingA); $accountStoreMappingB = \Stormpath\Resource\AccountStoreMapping::instantiate(array('accountStore' => $groupB)); $application->createAccountStoreMapping($accountStoreMappingB); $account = \Stormpath\Resource\Account::instantiate(array('givenName' => 'Account Name', 'surname' => 'Surname', 'username' => 'super_unique_username', 'email' => '*****@*****.**', 'password' => 'superP4ss')); $application->createAccount($account); $groupA->addAccount($account); $authenticationRequest = new \Stormpath\Authc\UsernamePasswordRequest('*****@*****.**', 'superP4ss', array('accountStore' => $accountStoreMappingA->getAccountStore())); $result = $application->authenticateAccount($authenticationRequest); $this->assertEquals('*****@*****.**', $result->account->email); try { $authenticationRequest = new \Stormpath\Authc\UsernamePasswordRequest('*****@*****.**', 'superP4ss', array('accountStore' => $accountStoreMappingB->getAccountStore())); $application->authenticateAccount($authenticationRequest); $account->delete(); $accountStoreMappingB->delete(); $accountStoreMappingA->delete(); $groupB->delete(); $groupA->delete(); $this->fail('Authentication should have failed.'); } catch (\Stormpath\Resource\ResourceError $re) { $this->assertEquals(400, $re->getStatus()); $this->assertEquals(7104, $re->getErrorCode()); $this->assertContains('Invalid', $re->getMessage()); $this->assertEquals("Login attempt failed because there is no Account in the Application's associated Account Stores with the specified username or email.", $re->getDeveloperMessage()); $this->assertContains('7104', $re->getMoreInfo()); } try { new \Stormpath\Authc\UsernamePasswordRequest('*****@*****.**', 'superP4ss', array('accountStore' => 'not an instance of AccountStore')); $this->fail('UsernamePasswordRequest instantiation should have failed.'); } catch (\InvalidArgumentException $iae) { $this->assertEquals("The value for accountStore in the \$options array should be an instance of \\Stormpath\\Resource\\AccountStore", $iae->getMessage()); } catch (\Exception $e) { $this->fail('UsernamePasswordRequest instantiation with wrong type for account store should have thrown InvalidArgumentException.'); } $account->delete(); $accountStoreMappingB->delete(); $accountStoreMappingA->delete(); $groupB->delete(); $groupA->delete(); }
/** * @test */ public function it_can_add_an_account_store_mapping() { $application = \Stormpath\Resource\Application::instantiate(['name' => makeUniqueName('OrgTest'), 'description' => 'Description of Main App', 'status' => 'enabled']); $application = self::createResource(\Stormpath\Resource\Application::PATH, $application); $accountStoreMapping = \Stormpath\Resource\AccountStoreMapping::instantiate(['organization' => self::$organization, 'accountStore' => self::$directory, 'isDefaultAccountStore' => true, 'isDefaultGroupStore' => true]); $test1 = self::$organization->createOrganizationAccountStoreMapping($accountStoreMapping); $this->assertInstanceOf('\\Stormpath\\Resource\\AccountStoreMapping', $test1); $accountStoreMapping = \Stormpath\Resource\AccountStoreMapping::instantiate(['accountStore' => self::$organization, 'application' => $application, 'isDefaultAccountStore' => true]); $test2 = $application->createAccountStoreMapping($accountStoreMapping); $this->assertInstanceOf('\\Stormpath\\Resource\\AccountStoreMapping', $test2); $org = Organization::get(self::$organization->href); $this->assertNotNull($org->accountStoreMappings->href); $this->assertInstanceOf('Stormpath\\Resource\\AccountStore', $org->defaultAccountStoreMapping); $this->assertInstanceOf('Stormpath\\Resource\\AccountStore', $org->defaultGroupStoreMapping); $asm = $org->accountStoreMappings; foreach ($asm as $mapping) { $this->assertEquals($org->href, $mapping->organization->href); $this->assertEquals(self::$directory->href, $mapping->accountStore->href); } $app = Application::get($application->href); $this->assertNotNull($app->accountStoreMappings->href); $asm = $app->accountStoreMappings; foreach ($asm as $mapping) { $this->assertEquals($app->href, $mapping->application->href); $this->assertEquals(self::$organization->href, $mapping->accountStore->href); } $application->delete(); }
/** * THIS IS NOT PART OF THE STORMPATH PUBLIC API. SDK end-users should not call it - it could be removed or * changed at any time. It has the public modifier only as an implementation technique to be accessible to other * resource implementations. * * @param $accountStoreMapping the account store mapping to create. * @param $application the application to associate with the account store mapping. * @param $dataStore the data store used to create the account store mapping. * @param $options the options to pass to the group mapping creation. * @return the created AccountStoreMapping instance. */ public static function _create(AccountStoreMapping $accountStoreMapping, Application $application, InternalDataStore $dataStore, array $options = array()) { //TODO: enable auto discovery $href = "/" . self::PATH; // properly setting the resource properties $accountStoreMapping->setResourceProperty(self::APPLICATION, $application); $accountStoreMapping->accountStore = $accountStoreMapping->accountStore; return $dataStore->create($href, $accountStoreMapping, Stormpath::ACCOUNT_STORE_MAPPING, $options); }
private function warmResources() { if (config('stormpath.application.href') == null) { return; } $cache = $this->app['cache.store']; if ($cache->has('stormpath.resourcesWarm') && $cache->get('stormpath.resourcesWarm') == true) { return; } app('stormpath.client'); $application = app('stormpath.application'); $dasm = AccountStoreMapping::get($application->defaultAccountStoreMapping->href); $mappings = $application->getAccountStoreMappings(['expand' => 'accountStore']); $accountStoreArray = []; foreach ($mappings as $mapping) { $accountStoreArrayValues = ['href' => $mapping->accountStore->href, 'name' => $mapping->accountStore->name]; if (isset($mapping->accountStore->provider)) { $accountStoreArrayValues['provider'] = ['href' => $mapping->accountStore->provider->href, 'providerId' => $mapping->accountStore->provider->providerId]; } $accountStoreArray[] = $accountStoreArrayValues; } $asm = AccountStoreMapping::get($application->accountStoreMappings->href, ['expand' => 'accountStore']); $passwordPolicy = $dasm->getAccountStore()->getProperty('passwordPolicy'); $accountCreationPolicy = $dasm->getAccountStore(['expand' => 'accountCreationPolicy'])->accountCreationPolicy; $passwordPolicies = PasswordPolicies::get($passwordPolicy->href); $cache->rememberForever('stormpath.defaultAccountStoreMapping', function () use($dasm) { return $dasm; }); $cache->rememberForever('stormpath.accountStoreMappings', function () use($asm) { return $asm; }); $cache->rememberForever('stormpath.accountStores', function () use($accountStoreArray) { return $accountStoreArray; }); $cache->rememberForever('stormpath.passwordPolicy', function () use($passwordPolicy) { return $passwordPolicy; }); $cache->rememberForever('stormpath.accountCreationPolicy', function () use($accountCreationPolicy) { return $accountCreationPolicy; }); $cache->rememberForever('stormpath.passwordPolicies', function () use($passwordPolicies) { return $passwordPolicies; }); $cache->rememberForever('stormpath.resourcesWarm', function () { return true; }); }