{"action":"created","comment":{"url":"https://api.github.com/repos/apache/brooklyn-server/pulls/comments/73880683","id":73880683,"diff_hunk":"@@ -37,32 +37,45 @@\n     @Context UriInfo uri;\n \n     @Override\n+    public Response redirectToLogout() {\n+        URI dest = uri.getBaseUriBuilder().path(LogoutApi.class).build();\n+\n+        // Return response with Javascript which will make an asynchronous POST request to the logout method.\n+        // (When calling logout it is important to use wrong username and password in order to make browser forget the old ones)\n+        return Response.status(Status.OK)\n+                .entity(String.format(\"<!DOCTYPE html>\\n<body>\\n\" +\n+                        \"<script>\\n\" +\n+                        \"var a=new window.XMLHttpRequest;\" +\n+                        \"a.open('POST','%1$s',0,'user','wrong'+(new Date).getTime().toString());a.send(\\\"\\\");\\n\" +\n+                        \"window.location.href='/';</script></body>\", dest.toASCIIString()))\n+                .build();\n+    }\n+\n+    @Override\n     public Response logout() {\n         WebEntitlementContext ctx = (WebEntitlementContext) Entitlements.getEntitlementContext();\n-        URI dest = uri.getBaseUriBuilder().path(LogoutApi.class).path(LogoutApi.class, \"logoutUser\").build(ctx.user());\n \n-        // When execution gets here we don't know whether this is the first fetch of logout() or a subsequent one\n-        // with a re-authenticated user. The only way to tell is compare if user names changed. So redirect to an URL\n-        // which contains the user name.\n-        return Response.status(Status.TEMPORARY_REDIRECT)\n+        if (ctx != null && ctx.user() != null) {\n+            doLogout();\n+        }\n+\n+        URI dest = uri.getBaseUriBuilder().build();\n+\n+        return Response.status(Status.UNAUTHORIZED)\n+                .header(\"WWW-Authenticate\", \"Basic realm=\\\"webconsole\\\"\")\n+                // For Status 403, HTTP Location header may be omitted.\n+                // Location is best to be used for http status 302 https://tools.ietf.org/html/rfc2616#section-10.3.3\n                 .header(\"Location\", dest.toASCIIString())\n+                .entity(\"<script>window.location.replace(\\\"/\\\");</script>\")","path":"rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/LogoutResource.java","position":38,"original_position":38,"commit_id":"9f169a7c5d65921b104af2f3c48d0ed5297a25ae","original_commit_id":"9f169a7c5d65921b104af2f3c48d0ed5297a25ae","user":{"login":"neykov","id":3612111,"avatar_url":"https://avatars.githubusercontent.com/u/3612111?v=3","gravatar_id":"","url":"https://api.github.com/users/neykov","html_url":"https://github.com/neykov","followers_url":"https://api.github.com/users/neykov/followers","following_url":"https://api.github.com/users/neykov/following{/other_user}","gists_url":"https://api.github.com/users/neykov/gists{/gist_id}","starred_url":"https://api.github.com/users/neykov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neykov/subscriptions","organizations_url":"https://api.github.com/users/neykov/orgs","repos_url":"https://api.github.com/users/neykov/repos","events_url":"https://api.github.com/users/neykov/events{/privacy}","received_events_url":"https://api.github.com/users/neykov/received_events","type":"User","site_admin":false},"body":"I think we should keep previous behaviour here and for `logoutUser`. Changes in https://github.com/apache/brooklyn-ui/pull/30 don't actually use the `lougout` call anyway - they rely on javascript to invalidate the authentication header.\r\nWhy it's needed (for clients that use it):\r\n  * a client posts to /logout\r\n  * server returns 401\r\n  * browser displays an authentication dialog\r\n  * browser retries request with new credentials (against /logout)\r\n  * server return 401 (because that's all it does)\r\n  * credentials appear to be invalid\r\n\r\nHow current code fixes this:\r\n  * a client posts to /logout\r\n  * server redirects to /logout/username\r\n  * server returns 401\r\n  * browser display an authentication dialog\r\n  * browser retries request with new credentials (against /logout/username)\r\n  * server returns 200 if new username doesn't match username in URL or 401 if it matches\r\n","created_at":"2016-08-08T14:07:03Z","updated_at":"2016-08-08T14:07:03Z","html_url":"https://github.com/apache/brooklyn-server/pull/288#discussion_r73880683","pull_request_url":"https://api.github.com/repos/apache/brooklyn-server/pulls/288","_links":{"self":{"href":"https://api.github.com/repos/apache/brooklyn-server/pulls/comments/73880683"},"html":{"href":"https://github.com/apache/brooklyn-server/pull/288#discussion_r73880683"},"pull_request":{"href":"https://api.github.com/repos/apache/brooklyn-server/pulls/288"}}},"pull_request":{"url":"https://api.github.com/repos/apache/brooklyn-server/pulls/288","id":79968840,"html_url":"https://github.com/apache/brooklyn-server/pull/288","diff_url":"https://github.com/apache/brooklyn-server/pull/288.diff","patch_url":"https://github.com/apache/brooklyn-server/pull/288.patch","issue_url":"https://api.github.com/repos/apache/brooklyn-server/issues/288","number":288,"state":"open","locked":false,"title":"BROOKLYN-323: Simplify Logout api","user":{"login":"bostko","id":1595054,"avatar_url":"https://avatars.githubusercontent.com/u/1595054?v=3","gravatar_id":"","url":"https://api.github.com/users/bostko","html_url":"https://github.com/bostko","followers_url":"https://api.github.com/users/bostko/followers","following_url":"https://api.github.com/users/bostko/following{/other_user}","gists_url":"https://api.github.com/users/bostko/gists{/gist_id}","starred_url":"https://api.github.com/users/bostko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bostko/subscriptions","organizations_url":"https://api.github.com/users/bostko/orgs","repos_url":"https://api.github.com/users/bostko/repos","events_url":"https://api.github.com/users/bostko/events{/privacy}","received_events_url":"https://api.github.com/users/bostko/received_events","type":"User","site_admin":false},"body":"- removed TEMPORARY_REDIRECT step\r\n- fixed redirecting for firefox\r\n- change logout call to a GET request\r\n","created_at":"2016-08-03T19:59:51Z","updated_at":"2016-08-08T14:07:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a2dc1b539771c2fbf00e00a5bc955982b3d32169","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/brooklyn-server/pulls/288/commits","review_comments_url":"https://api.github.com/repos/apache/brooklyn-server/pulls/288/comments","review_comment_url":"https://api.github.com/repos/apache/brooklyn-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/brooklyn-server/issues/288/comments","statuses_url":"https://api.github.com/repos/apache/brooklyn-server/statuses/9f169a7c5d65921b104af2f3c48d0ed5297a25ae","head":{"label":"bostko:logout-api","ref":"logout-api","sha":"9f169a7c5d65921b104af2f3c48d0ed5297a25ae","user":{"login":"bostko","id":1595054,"avatar_url":"https://avatars.githubusercontent.com/u/1595054?v=3","gravatar_id":"","url":"https://api.github.com/users/bostko","html_url":"https://github.com/bostko","followers_url":"https://api.github.com/users/bostko/followers","following_url":"https://api.github.com/users/bostko/following{/other_user}","gists_url":"https://api.github.com/users/bostko/gists{/gist_id}","starred_url":"https://api.github.com/users/bostko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bostko/subscriptions","organizations_url":"https://api.github.com/users/bostko/orgs","repos_url":"https://api.github.com/users/bostko/repos","events_url":"https://api.github.com/users/bostko/events{/privacy}","received_events_url":"https://api.github.com/users/bostko/received_events","type":"User","site_admin":false},"repo":{"id":50875100,"name":"brooklyn-server","full_name":"bostko/brooklyn-server","owner":{"login":"bostko","id":1595054,"avatar_url":"https://avatars.githubusercontent.com/u/1595054?v=3","gravatar_id":"","url":"https://api.github.com/users/bostko","html_url":"https://github.com/bostko","followers_url":"https://api.github.com/users/bostko/followers","following_url":"https://api.github.com/users/bostko/following{/other_user}","gists_url":"https://api.github.com/users/bostko/gists{/gist_id}","starred_url":"https://api.github.com/users/bostko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bostko/subscriptions","organizations_url":"https://api.github.com/users/bostko/orgs","repos_url":"https://api.github.com/users/bostko/repos","events_url":"https://api.github.com/users/bostko/events{/privacy}","received_events_url":"https://api.github.com/users/bostko/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bostko/brooklyn-server","description":"Mirror of Apache Brooklyn server","fork":true,"url":"https://api.github.com/repos/bostko/brooklyn-server","forks_url":"https://api.github.com/repos/bostko/brooklyn-server/forks","keys_url":"https://api.github.com/repos/bostko/brooklyn-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bostko/brooklyn-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bostko/brooklyn-server/teams","hooks_url":"https://api.github.com/repos/bostko/brooklyn-server/hooks","issue_events_url":"https://api.github.com/repos/bostko/brooklyn-server/issues/events{/number}","events_url":"https://api.github.com/repos/bostko/brooklyn-server/events","assignees_url":"https://api.github.com/repos/bostko/brooklyn-server/assignees{/user}","branches_url":"https://api.github.com/repos/bostko/brooklyn-server/branches{/branch}","tags_url":"https://api.github.com/repos/bostko/brooklyn-server/tags","blobs_url":"https://api.github.com/repos/bostko/brooklyn-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bostko/brooklyn-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bostko/brooklyn-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/bostko/brooklyn-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bostko/brooklyn-server/statuses/{sha}","languages_url":"https://api.github.com/repos/bostko/brooklyn-server/languages","stargazers_url":"https://api.github.com/repos/bostko/brooklyn-server/stargazers","contributors_url":"https://api.github.com/repos/bostko/brooklyn-server/contributors","subscribers_url":"https://api.github.com/repos/bostko/brooklyn-server/subscribers","subscription_url":"https://api.github.com/repos/bostko/brooklyn-server/subscription","commits_url":"https://api.github.com/repos/bostko/brooklyn-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/bostko/brooklyn-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/bostko/brooklyn-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/bostko/brooklyn-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/bostko/brooklyn-server/contents/{+path}","compare_url":"https://api.github.com/repos/bostko/brooklyn-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bostko/brooklyn-server/merges","archive_url":"https://api.github.com/repos/bostko/brooklyn-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bostko/brooklyn-server/downloads","issues_url":"https://api.github.com/repos/bostko/brooklyn-server/issues{/number}","pulls_url":"https://api.github.com/repos/bostko/brooklyn-server/pulls{/number}","milestones_url":"https://api.github.com/repos/bostko/brooklyn-server/milestones{/number}","notifications_url":"https://api.github.com/repos/bostko/brooklyn-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bostko/brooklyn-server/labels{/name}","releases_url":"https://api.github.com/repos/bostko/brooklyn-server/releases{/id}","deployments_url":"https://api.github.com/repos/bostko/brooklyn-server/deployments","created_at":"2016-02-01T22:10:47Z","updated_at":"2016-02-01T22:10:59Z","pushed_at":"2016-08-06T06:45:19Z","git_url":"git://github.com/bostko/brooklyn-server.git","ssh_url":"git@github.com:bostko/brooklyn-server.git","clone_url":"https://github.com/bostko/brooklyn-server.git","svn_url":"https://github.com/bostko/brooklyn-server","homepage":null,"size":30636,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"ddb6acc9238d0ea6fe2a02016d2983d089aacdba","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":47246081,"name":"brooklyn-server","full_name":"apache/brooklyn-server","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/brooklyn-server","description":"Mirror of Apache Brooklyn server","fork":false,"url":"https://api.github.com/repos/apache/brooklyn-server","forks_url":"https://api.github.com/repos/apache/brooklyn-server/forks","keys_url":"https://api.github.com/repos/apache/brooklyn-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/brooklyn-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/brooklyn-server/teams","hooks_url":"https://api.github.com/repos/apache/brooklyn-server/hooks","issue_events_url":"https://api.github.com/repos/apache/brooklyn-server/issues/events{/number}","events_url":"https://api.github.com/repos/apache/brooklyn-server/events","assignees_url":"https://api.github.com/repos/apache/brooklyn-server/assignees{/user}","branches_url":"https://api.github.com/repos/apache/brooklyn-server/branches{/branch}","tags_url":"https://api.github.com/repos/apache/brooklyn-server/tags","blobs_url":"https://api.github.com/repos/apache/brooklyn-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/brooklyn-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/brooklyn-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/brooklyn-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/brooklyn-server/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/brooklyn-server/languages","stargazers_url":"https://api.github.com/repos/apache/brooklyn-server/stargazers","contributors_url":"https://api.github.com/repos/apache/brooklyn-server/contributors","subscribers_url":"https://api.github.com/repos/apache/brooklyn-server/subscribers","subscription_url":"https://api.github.com/repos/apache/brooklyn-server/subscription","commits_url":"https://api.github.com/repos/apache/brooklyn-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/brooklyn-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/brooklyn-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/brooklyn-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/brooklyn-server/contents/{+path}","compare_url":"https://api.github.com/repos/apache/brooklyn-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/brooklyn-server/merges","archive_url":"https://api.github.com/repos/apache/brooklyn-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/brooklyn-server/downloads","issues_url":"https://api.github.com/repos/apache/brooklyn-server/issues{/number}","pulls_url":"https://api.github.com/repos/apache/brooklyn-server/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/brooklyn-server/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/brooklyn-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/brooklyn-server/labels{/name}","releases_url":"https://api.github.com/repos/apache/brooklyn-server/releases{/id}","deployments_url":"https://api.github.com/repos/apache/brooklyn-server/deployments","created_at":"2015-12-02T08:00:06Z","updated_at":"2016-05-30T11:46:29Z","pushed_at":"2016-08-08T13:48:35Z","git_url":"git://github.com/apache/brooklyn-server.git","ssh_url":"git@github.com:apache/brooklyn-server.git","clone_url":"https://github.com/apache/brooklyn-server.git","svn_url":"https://github.com/apache/brooklyn-server","homepage":null,"size":30895,"stargazers_count":10,"watchers_count":10,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":35,"mirror_url":"git://git.apache.org/brooklyn-server.git","open_issues_count":21,"forks":35,"open_issues":21,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/brooklyn-server/pulls/288"},"html":{"href":"https://github.com/apache/brooklyn-server/pull/288"},"issue":{"href":"https://api.github.com/repos/apache/brooklyn-server/issues/288"},"comments":{"href":"https://api.github.com/repos/apache/brooklyn-server/issues/288/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/brooklyn-server/pulls/288/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/brooklyn-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/brooklyn-server/pulls/288/commits"},"statuses":{"href":"https://api.github.com/repos/apache/brooklyn-server/statuses/9f169a7c5d65921b104af2f3c48d0ed5297a25ae"}}}}
{"actor":{"display_login":"neykov"}}