{"action":"created","comment":{"url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls/comments/26006225","id":26006225,"diff_hunk":"@@ -151,6 +170,55 @@ def reset_state(configuration=None):\n     app = setup_app()\n \n \n+def validate_security_config(cfy_config):\n+    # TODO raise better exceptions\n+    if not hasattr(cfy_config, 'securest_secret_key') or \\\n+            cfy_config.securest_secret_key is None:\n+        raise Exception('securest_secret_key not set')\n+    if not hasattr(cfy_config, 'securest_authentication_methods') or \\\n+            cfy_config.securest_authentication_methods is None:\n+        raise Exception('securest_authentication_methods not set')\n+    if not hasattr(cfy_config, 'securest_userstore_driver') or \\\n+            cfy_config.securest_userstore_driver is None:\n+        raise Exception('securest_userstore_driver not set')\n+    if not hasattr(cfy_config, 'securest_userstore_identifier_attribute') or \\\n+            cfy_config.securest_userstore_identifier_attribute is None:\n+        raise Exception('securest_userstore_identifier_attribute not set')\n+\n+\n+def init_secure_app(app):\n+    cfy_config = config.instance()\n+    validate_security_config(cfy_config)\n+\n+    app.config[SECUREST_SECRET_KEY] = cfy_config.securest_secret_key\n+    app.config[SECUREST_USERSTORE_DRIVER] = \\\n+        cfy_config.securest_userstore_driver\n+    app.config[SECUREST_USERSTORE_IDENTIFIER_ATTRIBUTE] = \\\n+        cfy_config.securest_userstore_identifier_attribute\n+\n+    secure_app = SecuREST(app)\n+\n+    register_authentication_methods(secure_app,\n+                                    cfy_config.securest_authentication_methods)\n+\n+    @secure_app.unauthorized_user_handler\n+    def unauthorized_user_handler():\n+        print '**** GOTCHA!'\n+        raise Exception(401)\n+\n+\n+def register_authentication_methods(secure_app, authentication_providers):\n+    # Note: the order of registration is important here\n+    for auth_method_path in authentication_providers:\n+        try:\n+            auth_provider = util.get_class_instance(auth_method_path)\n+            secure_app.authentication_provider(auth_provider)\n+        except Exception as e:\n+            print('Failed to register authentication method: ',","path":"rest-service/manager_rest/server.py","position":86,"original_position":86,"commit_id":"e74b2b48664df96e5229c2814ce752f2dd7eb606","original_commit_id":"e74b2b48664df96e5229c2814ce752f2dd7eb606","user":{"login":"dankilman","id":1008577,"avatar_url":"https://avatars.githubusercontent.com/u/1008577?v=3","gravatar_id":"","url":"https://api.github.com/users/dankilman","html_url":"https://github.com/dankilman","followers_url":"https://api.github.com/users/dankilman/followers","following_url":"https://api.github.com/users/dankilman/following{/other_user}","gists_url":"https://api.github.com/users/dankilman/gists{/gist_id}","starred_url":"https://api.github.com/users/dankilman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dankilman/subscriptions","organizations_url":"https://api.github.com/users/dankilman/orgs","repos_url":"https://api.github.com/users/dankilman/repos","events_url":"https://api.github.com/users/dankilman/events{/privacy}","received_events_url":"https://api.github.com/users/dankilman/received_events","type":"User","site_admin":false},"body":"don't use print statements in production code, use logger","created_at":"2015-03-08T15:48:24Z","updated_at":"2015-03-08T15:48:24Z","html_url":"https://github.com/cloudify-cosmo/cloudify-manager/pull/223#discussion_r26006225","pull_request_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls/223","_links":{"self":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls/comments/26006225"},"html":{"href":"https://github.com/cloudify-cosmo/cloudify-manager/pull/223#discussion_r26006225"},"pull_request":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls/223"}}},"pull_request":{"url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls/223","id":30719286,"html_url":"https://github.com/cloudify-cosmo/cloudify-manager/pull/223","diff_url":"https://github.com/cloudify-cosmo/cloudify-manager/pull/223.diff","patch_url":"https://github.com/cloudify-cosmo/cloudify-manager/pull/223.patch","issue_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/issues/223","number":223,"state":"open","locked":false,"title":"Cfy 834 security","user":{"login":"noakup","id":1745412,"avatar_url":"https://avatars.githubusercontent.com/u/1745412?v=3","gravatar_id":"","url":"https://api.github.com/users/noakup","html_url":"https://github.com/noakup","followers_url":"https://api.github.com/users/noakup/followers","following_url":"https://api.github.com/users/noakup/following{/other_user}","gists_url":"https://api.github.com/users/noakup/gists{/gist_id}","starred_url":"https://api.github.com/users/noakup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noakup/subscriptions","organizations_url":"https://api.github.com/users/noakup/orgs","repos_url":"https://api.github.com/users/noakup/repos","events_url":"https://api.github.com/users/noakup/events{/privacy}","received_events_url":"https://api.github.com/users/noakup/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-08T13:07:19Z","updated_at":"2015-03-08T15:48:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a77c564f42c093487efcd429fb8f64d2a529e17d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls/223/commits","review_comments_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls/223/comments","review_comment_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/issues/223/comments","statuses_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/statuses/e74b2b48664df96e5229c2814ce752f2dd7eb606","head":{"label":"cloudify-cosmo:CFY-834-security","ref":"CFY-834-security","sha":"e74b2b48664df96e5229c2814ce752f2dd7eb606","user":{"login":"cloudify-cosmo","id":6260555,"avatar_url":"https://avatars.githubusercontent.com/u/6260555?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudify-cosmo","html_url":"https://github.com/cloudify-cosmo","followers_url":"https://api.github.com/users/cloudify-cosmo/followers","following_url":"https://api.github.com/users/cloudify-cosmo/following{/other_user}","gists_url":"https://api.github.com/users/cloudify-cosmo/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudify-cosmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudify-cosmo/subscriptions","organizations_url":"https://api.github.com/users/cloudify-cosmo/orgs","repos_url":"https://api.github.com/users/cloudify-cosmo/repos","events_url":"https://api.github.com/users/cloudify-cosmo/events{/privacy}","received_events_url":"https://api.github.com/users/cloudify-cosmo/received_events","type":"Organization","site_admin":false},"repo":{"id":18326574,"name":"cloudify-manager","full_name":"cloudify-cosmo/cloudify-manager","owner":{"login":"cloudify-cosmo","id":6260555,"avatar_url":"https://avatars.githubusercontent.com/u/6260555?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudify-cosmo","html_url":"https://github.com/cloudify-cosmo","followers_url":"https://api.github.com/users/cloudify-cosmo/followers","following_url":"https://api.github.com/users/cloudify-cosmo/following{/other_user}","gists_url":"https://api.github.com/users/cloudify-cosmo/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudify-cosmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudify-cosmo/subscriptions","organizations_url":"https://api.github.com/users/cloudify-cosmo/orgs","repos_url":"https://api.github.com/users/cloudify-cosmo/repos","events_url":"https://api.github.com/users/cloudify-cosmo/events{/privacy}","received_events_url":"https://api.github.com/users/cloudify-cosmo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudify-cosmo/cloudify-manager","description":"Cloudify's manager related code","fork":false,"url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager","forks_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/forks","keys_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/teams","hooks_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/hooks","issue_events_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/issues/events{/number}","events_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/events","assignees_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/assignees{/user}","branches_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/branches{/branch}","tags_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/tags","blobs_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/languages","stargazers_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/stargazers","contributors_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/contributors","subscribers_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/subscribers","subscription_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/subscription","commits_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/contents/{+path}","compare_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/merges","archive_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/downloads","issues_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/issues{/number}","pulls_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/labels{/name}","releases_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/releases{/id}","created_at":"2014-04-01T11:06:47Z","updated_at":"2015-03-07T16:06:39Z","pushed_at":"2015-03-08T14:59:05Z","git_url":"git://github.com/cloudify-cosmo/cloudify-manager.git","ssh_url":"git@github.com:cloudify-cosmo/cloudify-manager.git","clone_url":"https://github.com/cloudify-cosmo/cloudify-manager.git","svn_url":"https://github.com/cloudify-cosmo/cloudify-manager","homepage":null,"size":18232,"stargazers_count":10,"watchers_count":10,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":16,"mirror_url":null,"open_issues_count":2,"forks":16,"open_issues":2,"watchers":10,"default_branch":"master"}},"base":{"label":"cloudify-cosmo:master","ref":"master","sha":"af3aa12f5f0d376f3e97c0abd59b7c02bde08d4f","user":{"login":"cloudify-cosmo","id":6260555,"avatar_url":"https://avatars.githubusercontent.com/u/6260555?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudify-cosmo","html_url":"https://github.com/cloudify-cosmo","followers_url":"https://api.github.com/users/cloudify-cosmo/followers","following_url":"https://api.github.com/users/cloudify-cosmo/following{/other_user}","gists_url":"https://api.github.com/users/cloudify-cosmo/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudify-cosmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudify-cosmo/subscriptions","organizations_url":"https://api.github.com/users/cloudify-cosmo/orgs","repos_url":"https://api.github.com/users/cloudify-cosmo/repos","events_url":"https://api.github.com/users/cloudify-cosmo/events{/privacy}","received_events_url":"https://api.github.com/users/cloudify-cosmo/received_events","type":"Organization","site_admin":false},"repo":{"id":18326574,"name":"cloudify-manager","full_name":"cloudify-cosmo/cloudify-manager","owner":{"login":"cloudify-cosmo","id":6260555,"avatar_url":"https://avatars.githubusercontent.com/u/6260555?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudify-cosmo","html_url":"https://github.com/cloudify-cosmo","followers_url":"https://api.github.com/users/cloudify-cosmo/followers","following_url":"https://api.github.com/users/cloudify-cosmo/following{/other_user}","gists_url":"https://api.github.com/users/cloudify-cosmo/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudify-cosmo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudify-cosmo/subscriptions","organizations_url":"https://api.github.com/users/cloudify-cosmo/orgs","repos_url":"https://api.github.com/users/cloudify-cosmo/repos","events_url":"https://api.github.com/users/cloudify-cosmo/events{/privacy}","received_events_url":"https://api.github.com/users/cloudify-cosmo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudify-cosmo/cloudify-manager","description":"Cloudify's manager related code","fork":false,"url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager","forks_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/forks","keys_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/teams","hooks_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/hooks","issue_events_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/issues/events{/number}","events_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/events","assignees_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/assignees{/user}","branches_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/branches{/branch}","tags_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/tags","blobs_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/languages","stargazers_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/stargazers","contributors_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/contributors","subscribers_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/subscribers","subscription_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/subscription","commits_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/contents/{+path}","compare_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/merges","archive_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/downloads","issues_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/issues{/number}","pulls_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/labels{/name}","releases_url":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/releases{/id}","created_at":"2014-04-01T11:06:47Z","updated_at":"2015-03-07T16:06:39Z","pushed_at":"2015-03-08T14:59:05Z","git_url":"git://github.com/cloudify-cosmo/cloudify-manager.git","ssh_url":"git@github.com:cloudify-cosmo/cloudify-manager.git","clone_url":"https://github.com/cloudify-cosmo/cloudify-manager.git","svn_url":"https://github.com/cloudify-cosmo/cloudify-manager","homepage":null,"size":18232,"stargazers_count":10,"watchers_count":10,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":16,"mirror_url":null,"open_issues_count":2,"forks":16,"open_issues":2,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls/223"},"html":{"href":"https://github.com/cloudify-cosmo/cloudify-manager/pull/223"},"issue":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/issues/223"},"comments":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/issues/223/comments"},"review_comments":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls/223/comments"},"review_comment":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/pulls/223/commits"},"statuses":{"href":"https://api.github.com/repos/cloudify-cosmo/cloudify-manager/statuses/e74b2b48664df96e5229c2814ce752f2dd7eb606"}}}}