public function testPolicies() { $policy = new Policy(); $statement = new Statement(); $action = new Action('s3', 'Get*'); $statement->addAction($action); $action = new Action('s3', 'List*'); $statement->addAction($action); $resource = new Resource('xrn:aws:s3:eu-west-1::some-bucket'); $statement->addResource($resource); $principal = new Principal('AWS'); $principal->addKey('xrn:aws:iam::AWS-account-ID:user/bob'); $principal->addKey('xrn:aws:iam::AWS-account-ID:user/alice'); $statement->setPrincipal($principal); $policy->addStatement($statement); $serializer = new JsonPolicySerializer(); $json = $serializer->serialize($policy); //echo $json; }
private function matchPrincipal(Identity $identity, Principal $principal) { if (!$this->matchString($identity->getType(), $principal->getType())) { return false; } foreach ($principal->getKeys() as $key) { if ($this->matchString($identity->getKey(), $key)) { return true; } } return false; }