{"action":"created","comment":{"url":"https://api.github.com/repos/sulu-io/sulu-docs/pulls/comments/28757147","id":28757147,"diff_hunk":"@@ -0,0 +1,124 @@\n+Securing your application\n+=========================\n+\n+Sulu is delivered with two different possiblities to protect parts of your\n+application. The first are the permissions based on security contexts, which\n+allow you to restrict access to entire parts of your application or Sulu. The\n+permissions for this kind of security are managed on a roles level. In addition\n+to that the localization for which these permissions are valid has to be\n+defined on the assignment of the role to the user.\n+\n+The second way is to protect the access on a per-object basis. These\n+permissions are set on the specific object. The user still has to have the\n+correct localizations assigned in order to gain access.\n+\n+This tutorial will show how to use Sulu's security functionality on your own\n+application specific code.\n+\n+Protect content using a security context\n+----------------------------------------\n+\n+This chapter describes how to protect an entire part of your application (but\n+not a specific object).\n+\n+Define your security context\n+~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n+\n+First of all you have to define the security context, which is represented by a\n+simple string. This is done in the ``Admin`` class of your Bundle:\n+\n+.. code-block:: php\n+    \n+    <?php\n+\n+    namespace Acme\\Bundle\\ExampleBundle\\Admin;\n+\n+    use Sulu\\Bundle\\AdminBundle\\Admin\\Admin;\n+\n+    class AcmeExampleAdmin extends Admin\n+    {\n+        // ...\n+\n+        public function getSecurityContexts()\n+        {\n+            return array(\n+                'Sulu' => array(\n+                    'Acme' => array(\n+                        'sulu.acme.example'\n+                    )\n+                );\n+            );\n+        }\n+\n+        // ...\n+    }\n+\n+This information is defined in the ``getSecurityContexts`` method, which should\n+return an array. The first level describes the used system being either Sulu\n+for stuff in the Sulu administration or another context you can define for your\n+own applications.\n+\n+The second level just defines the title for another separation used in the\n+administration interface. The third and last level defines the name of the\n+permissions themselves. This name follows a namespacing scheme based on the\n+previously used names.\n+\n+.. note::\n+    \n+    Since the ``Admin`` class is registered as a bundle, you can make use of\n+    different services to define the available security contexts. E.g. the\n+    SuluContentBundle uses a service to create an own security context for all\n+    available webspaces in the system.\n+\n+Protect your controller\n+~~~~~~~~~~~~~~~~~~~~~~~\n+\n+After defining a security context, you can use it to easily protect the actions\n+of one of your controllers. All you have to do is to implement the\n+``SecuredControllerInterface`` telling the ``SuluSecuriyListener`` which\n+security context and locale to use for the permission check:\n+\n+.. code-block:: php\n+\n+    <?php\n+\n+    namespace Acme\\Bundle\\ExampleBundle\\Controller;\n+\n+    use FOS\\RestBundle\\Routing\\ClassResourceInterface;\n+    use Sulu\\Component\\Security\\SecuredControllerInterface;\n+    use Symfony\\Component\\HttpFoundation\\Request;\n+\n+    class ExampleController implements ClassResourceInterface, SecuredControllerInterface\n+    {\n+        public function cgetAction()\n+        {\n+            // code for your get action\n+        }\n+\n+        public function postAction()\n+        {\n+            // code for your post action\n+        }\n+\n+        // ...\n+\n+        public function getLocale(Request $request)\n+        {\n+            return $request->get('locale');\n+        }\n+\n+        public function getSecurityContext()\n+        {\n+            return 'sulu.acme.example';\n+        }\n+    }\n+\n+The ``getLocale`` method returns the locale, which is probably determined\n+somehow by the request, and the ``getSecurityContext`` method defines which\n+security context is required to access this type of resource.\n+\n+The ``SuluSecurityListener`` appends the information on which type of\n+permission (view, add, edit, delete, ...) is required, and automatically takes\n+care of the permission check and returns a page with a status code of 403 in","path":"cookbook/securing-your-application.rst","position":122,"original_position":122,"commit_id":"248d6f2d8bc365438db3d278e2b5bf3bbdf6c051","original_commit_id":"248d6f2d8bc365438db3d278e2b5bf3bbdf6c051","user":{"login":"dantleech","id":530801,"avatar_url":"https://avatars.githubusercontent.com/u/530801?v=3","gravatar_id":"","url":"https://api.github.com/users/dantleech","html_url":"https://github.com/dantleech","followers_url":"https://api.github.com/users/dantleech/followers","following_url":"https://api.github.com/users/dantleech/following{/other_user}","gists_url":"https://api.github.com/users/dantleech/gists{/gist_id}","starred_url":"https://api.github.com/users/dantleech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dantleech/subscriptions","organizations_url":"https://api.github.com/users/dantleech/orgs","repos_url":"https://api.github.com/users/dantleech/repos","events_url":"https://api.github.com/users/dantleech/events{/privacy}","received_events_url":"https://api.github.com/users/dantleech/received_events","type":"User","site_admin":false},"body":"I would put 403 in backticks also","created_at":"2015-04-21T08:02:43Z","updated_at":"2015-04-21T08:02:43Z","html_url":"https://github.com/sulu-io/sulu-docs/pull/25#discussion_r28757147","pull_request_url":"https://api.github.com/repos/sulu-io/sulu-docs/pulls/25","_links":{"self":{"href":"https://api.github.com/repos/sulu-io/sulu-docs/pulls/comments/28757147"},"html":{"href":"https://github.com/sulu-io/sulu-docs/pull/25#discussion_r28757147"},"pull_request":{"href":"https://api.github.com/repos/sulu-io/sulu-docs/pulls/25"}}},"pull_request":{"url":"https://api.github.com/repos/sulu-io/sulu-docs/pulls/25","id":32507146,"html_url":"https://github.com/sulu-io/sulu-docs/pull/25","diff_url":"https://github.com/sulu-io/sulu-docs/pull/25.diff","patch_url":"https://github.com/sulu-io/sulu-docs/pull/25.patch","issue_url":"https://api.github.com/repos/sulu-io/sulu-docs/issues/25","number":25,"state":"open","locked":false,"title":"added cookbook entry for security","user":{"login":"danrot","id":405874,"avatar_url":"https://avatars.githubusercontent.com/u/405874?v=3","gravatar_id":"","url":"https://api.github.com/users/danrot","html_url":"https://github.com/danrot","followers_url":"https://api.github.com/users/danrot/followers","following_url":"https://api.github.com/users/danrot/following{/other_user}","gists_url":"https://api.github.com/users/danrot/gists{/gist_id}","starred_url":"https://api.github.com/users/danrot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danrot/subscriptions","organizations_url":"https://api.github.com/users/danrot/orgs","repos_url":"https://api.github.com/users/danrot/repos","events_url":"https://api.github.com/users/danrot/events{/privacy}","received_events_url":"https://api.github.com/users/danrot/received_events","type":"User","site_admin":false},"body":"Adds a cookbook entry for adding security to the documentation.\r\nCan also be deferred until I've added another chapter about using per-object security.","created_at":"2015-04-02T12:33:18Z","updated_at":"2015-04-21T08:02:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7102c453af74b40747611281799e581d49f48528","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sulu-io/sulu-docs/pulls/25/commits","review_comments_url":"https://api.github.com/repos/sulu-io/sulu-docs/pulls/25/comments","review_comment_url":"https://api.github.com/repos/sulu-io/sulu-docs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sulu-io/sulu-docs/issues/25/comments","statuses_url":"https://api.github.com/repos/sulu-io/sulu-docs/statuses/248d6f2d8bc365438db3d278e2b5bf3bbdf6c051","head":{"label":"sulu-io:security","ref":"security","sha":"248d6f2d8bc365438db3d278e2b5bf3bbdf6c051","user":{"login":"sulu-io","id":5717006,"avatar_url":"https://avatars.githubusercontent.com/u/5717006?v=3","gravatar_id":"","url":"https://api.github.com/users/sulu-io","html_url":"https://github.com/sulu-io","followers_url":"https://api.github.com/users/sulu-io/followers","following_url":"https://api.github.com/users/sulu-io/following{/other_user}","gists_url":"https://api.github.com/users/sulu-io/gists{/gist_id}","starred_url":"https://api.github.com/users/sulu-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sulu-io/subscriptions","organizations_url":"https://api.github.com/users/sulu-io/orgs","repos_url":"https://api.github.com/users/sulu-io/repos","events_url":"https://api.github.com/users/sulu-io/events{/privacy}","received_events_url":"https://api.github.com/users/sulu-io/received_events","type":"Organization","site_admin":false},"repo":{"id":22838344,"name":"sulu-docs","full_name":"sulu-io/sulu-docs","owner":{"login":"sulu-io","id":5717006,"avatar_url":"https://avatars.githubusercontent.com/u/5717006?v=3","gravatar_id":"","url":"https://api.github.com/users/sulu-io","html_url":"https://github.com/sulu-io","followers_url":"https://api.github.com/users/sulu-io/followers","following_url":"https://api.github.com/users/sulu-io/following{/other_user}","gists_url":"https://api.github.com/users/sulu-io/gists{/gist_id}","starred_url":"https://api.github.com/users/sulu-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sulu-io/subscriptions","organizations_url":"https://api.github.com/users/sulu-io/orgs","repos_url":"https://api.github.com/users/sulu-io/repos","events_url":"https://api.github.com/users/sulu-io/events{/privacy}","received_events_url":"https://api.github.com/users/sulu-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sulu-io/sulu-docs","description":"Sulu Documentation","fork":false,"url":"https://api.github.com/repos/sulu-io/sulu-docs","forks_url":"https://api.github.com/repos/sulu-io/sulu-docs/forks","keys_url":"https://api.github.com/repos/sulu-io/sulu-docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sulu-io/sulu-docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sulu-io/sulu-docs/teams","hooks_url":"https://api.github.com/repos/sulu-io/sulu-docs/hooks","issue_events_url":"https://api.github.com/repos/sulu-io/sulu-docs/issues/events{/number}","events_url":"https://api.github.com/repos/sulu-io/sulu-docs/events","assignees_url":"https://api.github.com/repos/sulu-io/sulu-docs/assignees{/user}","branches_url":"https://api.github.com/repos/sulu-io/sulu-docs/branches{/branch}","tags_url":"https://api.github.com/repos/sulu-io/sulu-docs/tags","blobs_url":"https://api.github.com/repos/sulu-io/sulu-docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sulu-io/sulu-docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sulu-io/sulu-docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/sulu-io/sulu-docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sulu-io/sulu-docs/statuses/{sha}","languages_url":"https://api.github.com/repos/sulu-io/sulu-docs/languages","stargazers_url":"https://api.github.com/repos/sulu-io/sulu-docs/stargazers","contributors_url":"https://api.github.com/repos/sulu-io/sulu-docs/contributors","subscribers_url":"https://api.github.com/repos/sulu-io/sulu-docs/subscribers","subscription_url":"https://api.github.com/repos/sulu-io/sulu-docs/subscription","commits_url":"https://api.github.com/repos/sulu-io/sulu-docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/sulu-io/sulu-docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/sulu-io/sulu-docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/sulu-io/sulu-docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/sulu-io/sulu-docs/contents/{+path}","compare_url":"https://api.github.com/repos/sulu-io/sulu-docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sulu-io/sulu-docs/merges","archive_url":"https://api.github.com/repos/sulu-io/sulu-docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sulu-io/sulu-docs/downloads","issues_url":"https://api.github.com/repos/sulu-io/sulu-docs/issues{/number}","pulls_url":"https://api.github.com/repos/sulu-io/sulu-docs/pulls{/number}","milestones_url":"https://api.github.com/repos/sulu-io/sulu-docs/milestones{/number}","notifications_url":"https://api.github.com/repos/sulu-io/sulu-docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sulu-io/sulu-docs/labels{/name}","releases_url":"https://api.github.com/repos/sulu-io/sulu-docs/releases{/id}","created_at":"2014-08-11T12:31:16Z","updated_at":"2015-04-14T14:13:10Z","pushed_at":"2015-04-15T15:04:07Z","git_url":"git://github.com/sulu-io/sulu-docs.git","ssh_url":"git@github.com:sulu-io/sulu-docs.git","clone_url":"https://github.com/sulu-io/sulu-docs.git","svn_url":"https://github.com/sulu-io/sulu-docs","homepage":"docs.sulu.io","size":1038,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":8,"forks":1,"open_issues":8,"watchers":0,"default_branch":"master"}},"base":{"label":"sulu-io:master","ref":"master","sha":"4f9cac9a86b12ce7f82f1ac38db56e3174ce4b3f","user":{"login":"sulu-io","id":5717006,"avatar_url":"https://avatars.githubusercontent.com/u/5717006?v=3","gravatar_id":"","url":"https://api.github.com/users/sulu-io","html_url":"https://github.com/sulu-io","followers_url":"https://api.github.com/users/sulu-io/followers","following_url":"https://api.github.com/users/sulu-io/following{/other_user}","gists_url":"https://api.github.com/users/sulu-io/gists{/gist_id}","starred_url":"https://api.github.com/users/sulu-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sulu-io/subscriptions","organizations_url":"https://api.github.com/users/sulu-io/orgs","repos_url":"https://api.github.com/users/sulu-io/repos","events_url":"https://api.github.com/users/sulu-io/events{/privacy}","received_events_url":"https://api.github.com/users/sulu-io/received_events","type":"Organization","site_admin":false},"repo":{"id":22838344,"name":"sulu-docs","full_name":"sulu-io/sulu-docs","owner":{"login":"sulu-io","id":5717006,"avatar_url":"https://avatars.githubusercontent.com/u/5717006?v=3","gravatar_id":"","url":"https://api.github.com/users/sulu-io","html_url":"https://github.com/sulu-io","followers_url":"https://api.github.com/users/sulu-io/followers","following_url":"https://api.github.com/users/sulu-io/following{/other_user}","gists_url":"https://api.github.com/users/sulu-io/gists{/gist_id}","starred_url":"https://api.github.com/users/sulu-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sulu-io/subscriptions","organizations_url":"https://api.github.com/users/sulu-io/orgs","repos_url":"https://api.github.com/users/sulu-io/repos","events_url":"https://api.github.com/users/sulu-io/events{/privacy}","received_events_url":"https://api.github.com/users/sulu-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sulu-io/sulu-docs","description":"Sulu Documentation","fork":false,"url":"https://api.github.com/repos/sulu-io/sulu-docs","forks_url":"https://api.github.com/repos/sulu-io/sulu-docs/forks","keys_url":"https://api.github.com/repos/sulu-io/sulu-docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sulu-io/sulu-docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sulu-io/sulu-docs/teams","hooks_url":"https://api.github.com/repos/sulu-io/sulu-docs/hooks","issue_events_url":"https://api.github.com/repos/sulu-io/sulu-docs/issues/events{/number}","events_url":"https://api.github.com/repos/sulu-io/sulu-docs/events","assignees_url":"https://api.github.com/repos/sulu-io/sulu-docs/assignees{/user}","branches_url":"https://api.github.com/repos/sulu-io/sulu-docs/branches{/branch}","tags_url":"https://api.github.com/repos/sulu-io/sulu-docs/tags","blobs_url":"https://api.github.com/repos/sulu-io/sulu-docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sulu-io/sulu-docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sulu-io/sulu-docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/sulu-io/sulu-docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sulu-io/sulu-docs/statuses/{sha}","languages_url":"https://api.github.com/repos/sulu-io/sulu-docs/languages","stargazers_url":"https://api.github.com/repos/sulu-io/sulu-docs/stargazers","contributors_url":"https://api.github.com/repos/sulu-io/sulu-docs/contributors","subscribers_url":"https://api.github.com/repos/sulu-io/sulu-docs/subscribers","subscription_url":"https://api.github.com/repos/sulu-io/sulu-docs/subscription","commits_url":"https://api.github.com/repos/sulu-io/sulu-docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/sulu-io/sulu-docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/sulu-io/sulu-docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/sulu-io/sulu-docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/sulu-io/sulu-docs/contents/{+path}","compare_url":"https://api.github.com/repos/sulu-io/sulu-docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sulu-io/sulu-docs/merges","archive_url":"https://api.github.com/repos/sulu-io/sulu-docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sulu-io/sulu-docs/downloads","issues_url":"https://api.github.com/repos/sulu-io/sulu-docs/issues{/number}","pulls_url":"https://api.github.com/repos/sulu-io/sulu-docs/pulls{/number}","milestones_url":"https://api.github.com/repos/sulu-io/sulu-docs/milestones{/number}","notifications_url":"https://api.github.com/repos/sulu-io/sulu-docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sulu-io/sulu-docs/labels{/name}","releases_url":"https://api.github.com/repos/sulu-io/sulu-docs/releases{/id}","created_at":"2014-08-11T12:31:16Z","updated_at":"2015-04-14T14:13:10Z","pushed_at":"2015-04-15T15:04:07Z","git_url":"git://github.com/sulu-io/sulu-docs.git","ssh_url":"git@github.com:sulu-io/sulu-docs.git","clone_url":"https://github.com/sulu-io/sulu-docs.git","svn_url":"https://github.com/sulu-io/sulu-docs","homepage":"docs.sulu.io","size":1038,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":8,"forks":1,"open_issues":8,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sulu-io/sulu-docs/pulls/25"},"html":{"href":"https://github.com/sulu-io/sulu-docs/pull/25"},"issue":{"href":"https://api.github.com/repos/sulu-io/sulu-docs/issues/25"},"comments":{"href":"https://api.github.com/repos/sulu-io/sulu-docs/issues/25/comments"},"review_comments":{"href":"https://api.github.com/repos/sulu-io/sulu-docs/pulls/25/comments"},"review_comment":{"href":"https://api.github.com/repos/sulu-io/sulu-docs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sulu-io/sulu-docs/pulls/25/commits"},"statuses":{"href":"https://api.github.com/repos/sulu-io/sulu-docs/statuses/248d6f2d8bc365438db3d278e2b5bf3bbdf6c051"}}}}