{"action":"created","comment":{"url":"https://api.github.com/repos/FenixEdu/bennu/pulls/comments/152856482","pull_request_review_id":78782886,"id":152856482,"diff_hunk":"@@ -84,64 +97,80 @@ public static User login(HttpServletRequest request, HttpServletResponse respons\n      * @param response\n      *            The response associated with the requires that triggered the logout\n      */\n-    public static void logout(HttpServletRequest request, HttpServletResponse response) {\n-        HttpSession session = request.getSession(false);\n+    public static void logout(final HttpServletRequest request, final HttpServletResponse response) {\n+        final HttpSession session = request.getSession(false);\n         if (session != null) {\n             User user = (User) session.getAttribute(LOGGED_USER_ATTRIBUTE);\n             if (user != null) {\n                 fireLogoutListeners(request, response, user);\n             }\n             session.invalidate();\n         }\n-        loggedUser.set(null);\n+        clear();\n     }\n \n-    public static void mock(User user) {\n-        loggedUser.set(user);\n+    public static void mock(final User user, final String authenticationMethod) {\n+        final AuthenticationContext authenticationContext = loggedUserContext.get();\n+        if (authenticationContext == null || authenticationContext.getUser() != user) {\n+            loggedUserContext.set(new AuthenticationContext(user, authenticationMethod));\n+        } else {\n+            authenticationContext.addAuthenticationMethodEvent(authenticationMethod);\n+        }\n     }\n \n     public static void unmock() {\n-        loggedUser.set(null);\n+        clear();\n     }\n \n     public static User getUser() {\n-        return loggedUser.get();\n+        final AuthenticationContext context = loggedUserContext.get();\n+        return context == null ? null : context.getUser();\n     }\n \n     public static boolean isLogged() {\n-        return loggedUser.get() != null;\n+        final AuthenticationContext context = loggedUserContext.get();\n+        return context != null && context.getUser() != null;\n     }\n \n-    static void updateFromSession(HttpSession session) {\n-        User user = (User) (session == null ? null : session.getAttribute(LOGGED_USER_ATTRIBUTE));\n+    private static void storeInSession(final HttpServletRequest request, final AuthenticationContext authenticationContext) {\n+        final HttpSession session = request.getSession();\n+        session.setAttribute(LOGGED_USER_ATTRIBUTE, authenticationContext.getUser());\n+        session.setAttribute(LOGGED_USER_AUTHENTICATION_CONTEXT_ATTRIBUTE, authenticationContext.export());\n+    }\n+\n+    static void updateFromSession(final HttpSession session) {\n+        final String json = (String) session.getAttribute(LOGGED_USER_AUTHENTICATION_CONTEXT_ATTRIBUTE);","path":"bennu-core/src/main/java/org/fenixedu/bennu/core/security/Authenticate.java","position":122,"original_position":121,"commit_id":"0d6a68cadccfff40256adad349e304ad9ffff2f0","original_commit_id":"35db7c313ee8bb2a578e828bb9a16fdeb265b724","user":{"login":"Luis-Cruz","id":1499685,"avatar_url":"https://avatars2.githubusercontent.com/u/1499685?v=4","gravatar_id":"","url":"https://api.github.com/users/Luis-Cruz","html_url":"https://github.com/Luis-Cruz","followers_url":"https://api.github.com/users/Luis-Cruz/followers","following_url":"https://api.github.com/users/Luis-Cruz/following{/other_user}","gists_url":"https://api.github.com/users/Luis-Cruz/gists{/gist_id}","starred_url":"https://api.github.com/users/Luis-Cruz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Luis-Cruz/subscriptions","organizations_url":"https://api.github.com/users/Luis-Cruz/orgs","repos_url":"https://api.github.com/users/Luis-Cruz/repos","events_url":"https://api.github.com/users/Luis-Cruz/events{/privacy}","received_events_url":"https://api.github.com/users/Luis-Cruz/received_events","type":"User","site_admin":false},"body":"Same answer as above.","created_at":"2017-11-23T18:11:23Z","updated_at":"2017-11-23T18:11:23Z","html_url":"https://github.com/FenixEdu/bennu/pull/310#discussion_r152856482","pull_request_url":"https://api.github.com/repos/FenixEdu/bennu/pulls/310","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/FenixEdu/bennu/pulls/comments/152856482"},"html":{"href":"https://github.com/FenixEdu/bennu/pull/310#discussion_r152856482"},"pull_request":{"href":"https://api.github.com/repos/FenixEdu/bennu/pulls/310"}},"in_reply_to_id":152852367},"pull_request":{"url":"https://api.github.com/repos/FenixEdu/bennu/pulls/310","id":154378178,"html_url":"https://github.com/FenixEdu/bennu/pull/310","diff_url":"https://github.com/FenixEdu/bennu/pull/310.diff","patch_url":"https://github.com/FenixEdu/bennu/pull/310.patch","issue_url":"https://api.github.com/repos/FenixEdu/bennu/issues/310","number":310,"state":"open","locked":false,"title":"Add authentication origin information to logged user context. BNN-347 #resolve","user":{"login":"Luis-Cruz","id":1499685,"avatar_url":"https://avatars2.githubusercontent.com/u/1499685?v=4","gravatar_id":"","url":"https://api.github.com/users/Luis-Cruz","html_url":"https://github.com/Luis-Cruz","followers_url":"https://api.github.com/users/Luis-Cruz/followers","following_url":"https://api.github.com/users/Luis-Cruz/following{/other_user}","gists_url":"https://api.github.com/users/Luis-Cruz/gists{/gist_id}","starred_url":"https://api.github.com/users/Luis-Cruz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Luis-Cruz/subscriptions","organizations_url":"https://api.github.com/users/Luis-Cruz/orgs","repos_url":"https://api.github.com/users/Luis-Cruz/repos","events_url":"https://api.github.com/users/Luis-Cruz/events{/privacy}","received_events_url":"https://api.github.com/users/Luis-Cruz/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-11-23T13:35:44Z","updated_at":"2017-11-23T18:11:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a9b676399ec7838b6ad5ef7aa78609c29a726ef7","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/FenixEdu/bennu/pulls/310/commits","review_comments_url":"https://api.github.com/repos/FenixEdu/bennu/pulls/310/comments","review_comment_url":"https://api.github.com/repos/FenixEdu/bennu/pulls/comments{/number}","comments_url":"https://api.github.com/repos/FenixEdu/bennu/issues/310/comments","statuses_url":"https://api.github.com/repos/FenixEdu/bennu/statuses/0d6a68cadccfff40256adad349e304ad9ffff2f0","head":{"label":"Luis-Cruz:feature/EnhanceUserLogonInfo","ref":"feature/EnhanceUserLogonInfo","sha":"0d6a68cadccfff40256adad349e304ad9ffff2f0","user":{"login":"Luis-Cruz","id":1499685,"avatar_url":"https://avatars2.githubusercontent.com/u/1499685?v=4","gravatar_id":"","url":"https://api.github.com/users/Luis-Cruz","html_url":"https://github.com/Luis-Cruz","followers_url":"https://api.github.com/users/Luis-Cruz/followers","following_url":"https://api.github.com/users/Luis-Cruz/following{/other_user}","gists_url":"https://api.github.com/users/Luis-Cruz/gists{/gist_id}","starred_url":"https://api.github.com/users/Luis-Cruz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Luis-Cruz/subscriptions","organizations_url":"https://api.github.com/users/Luis-Cruz/orgs","repos_url":"https://api.github.com/users/Luis-Cruz/repos","events_url":"https://api.github.com/users/Luis-Cruz/events{/privacy}","received_events_url":"https://api.github.com/users/Luis-Cruz/received_events","type":"User","site_admin":false},"repo":{"id":14042004,"name":"bennu","full_name":"Luis-Cruz/bennu","owner":{"login":"Luis-Cruz","id":1499685,"avatar_url":"https://avatars2.githubusercontent.com/u/1499685?v=4","gravatar_id":"","url":"https://api.github.com/users/Luis-Cruz","html_url":"https://github.com/Luis-Cruz","followers_url":"https://api.github.com/users/Luis-Cruz/followers","following_url":"https://api.github.com/users/Luis-Cruz/following{/other_user}","gists_url":"https://api.github.com/users/Luis-Cruz/gists{/gist_id}","starred_url":"https://api.github.com/users/Luis-Cruz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Luis-Cruz/subscriptions","organizations_url":"https://api.github.com/users/Luis-Cruz/orgs","repos_url":"https://api.github.com/users/Luis-Cruz/repos","events_url":"https://api.github.com/users/Luis-Cruz/events{/privacy}","received_events_url":"https://api.github.com/users/Luis-Cruz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Luis-Cruz/bennu","description":null,"fork":true,"url":"https://api.github.com/repos/Luis-Cruz/bennu","forks_url":"https://api.github.com/repos/Luis-Cruz/bennu/forks","keys_url":"https://api.github.com/repos/Luis-Cruz/bennu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Luis-Cruz/bennu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Luis-Cruz/bennu/teams","hooks_url":"https://api.github.com/repos/Luis-Cruz/bennu/hooks","issue_events_url":"https://api.github.com/repos/Luis-Cruz/bennu/issues/events{/number}","events_url":"https://api.github.com/repos/Luis-Cruz/bennu/events","assignees_url":"https://api.github.com/repos/Luis-Cruz/bennu/assignees{/user}","branches_url":"https://api.github.com/repos/Luis-Cruz/bennu/branches{/branch}","tags_url":"https://api.github.com/repos/Luis-Cruz/bennu/tags","blobs_url":"https://api.github.com/repos/Luis-Cruz/bennu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Luis-Cruz/bennu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Luis-Cruz/bennu/git/refs{/sha}","trees_url":"https://api.github.com/repos/Luis-Cruz/bennu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Luis-Cruz/bennu/statuses/{sha}","languages_url":"https://api.github.com/repos/Luis-Cruz/bennu/languages","stargazers_url":"https://api.github.com/repos/Luis-Cruz/bennu/stargazers","contributors_url":"https://api.github.com/repos/Luis-Cruz/bennu/contributors","subscribers_url":"https://api.github.com/repos/Luis-Cruz/bennu/subscribers","subscription_url":"https://api.github.com/repos/Luis-Cruz/bennu/subscription","commits_url":"https://api.github.com/repos/Luis-Cruz/bennu/commits{/sha}","git_commits_url":"https://api.github.com/repos/Luis-Cruz/bennu/git/commits{/sha}","comments_url":"https://api.github.com/repos/Luis-Cruz/bennu/comments{/number}","issue_comment_url":"https://api.github.com/repos/Luis-Cruz/bennu/issues/comments{/number}","contents_url":"https://api.github.com/repos/Luis-Cruz/bennu/contents/{+path}","compare_url":"https://api.github.com/repos/Luis-Cruz/bennu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Luis-Cruz/bennu/merges","archive_url":"https://api.github.com/repos/Luis-Cruz/bennu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Luis-Cruz/bennu/downloads","issues_url":"https://api.github.com/repos/Luis-Cruz/bennu/issues{/number}","pulls_url":"https://api.github.com/repos/Luis-Cruz/bennu/pulls{/number}","milestones_url":"https://api.github.com/repos/Luis-Cruz/bennu/milestones{/number}","notifications_url":"https://api.github.com/repos/Luis-Cruz/bennu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Luis-Cruz/bennu/labels{/name}","releases_url":"https://api.github.com/repos/Luis-Cruz/bennu/releases{/id}","deployments_url":"https://api.github.com/repos/Luis-Cruz/bennu/deployments","created_at":"2013-11-01T11:56:12Z","updated_at":"2014-08-29T14:17:13Z","pushed_at":"2017-11-23T18:04:42Z","git_url":"git://github.com/Luis-Cruz/bennu.git","ssh_url":"git@github.com:Luis-Cruz/bennu.git","clone_url":"https://github.com/Luis-Cruz/bennu.git","svn_url":"https://github.com/Luis-Cruz/bennu","homepage":null,"size":69716,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"FenixEdu:master","ref":"master","sha":"4a96f934a6a06d1004fc4c486dbe65e204dbae2a","user":{"login":"FenixEdu","id":5507979,"avatar_url":"https://avatars2.githubusercontent.com/u/5507979?v=4","gravatar_id":"","url":"https://api.github.com/users/FenixEdu","html_url":"https://github.com/FenixEdu","followers_url":"https://api.github.com/users/FenixEdu/followers","following_url":"https://api.github.com/users/FenixEdu/following{/other_user}","gists_url":"https://api.github.com/users/FenixEdu/gists{/gist_id}","starred_url":"https://api.github.com/users/FenixEdu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FenixEdu/subscriptions","organizations_url":"https://api.github.com/users/FenixEdu/orgs","repos_url":"https://api.github.com/users/FenixEdu/repos","events_url":"https://api.github.com/users/FenixEdu/events{/privacy}","received_events_url":"https://api.github.com/users/FenixEdu/received_events","type":"Organization","site_admin":false},"repo":{"id":8903055,"name":"bennu","full_name":"FenixEdu/bennu","owner":{"login":"FenixEdu","id":5507979,"avatar_url":"https://avatars2.githubusercontent.com/u/5507979?v=4","gravatar_id":"","url":"https://api.github.com/users/FenixEdu","html_url":"https://github.com/FenixEdu","followers_url":"https://api.github.com/users/FenixEdu/followers","following_url":"https://api.github.com/users/FenixEdu/following{/other_user}","gists_url":"https://api.github.com/users/FenixEdu/gists{/gist_id}","starred_url":"https://api.github.com/users/FenixEdu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FenixEdu/subscriptions","organizations_url":"https://api.github.com/users/FenixEdu/orgs","repos_url":"https://api.github.com/users/FenixEdu/repos","events_url":"https://api.github.com/users/FenixEdu/events{/privacy}","received_events_url":"https://api.github.com/users/FenixEdu/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/FenixEdu/bennu","description":"Framework for developing Java web applications based on the Fenix Framework","fork":false,"url":"https://api.github.com/repos/FenixEdu/bennu","forks_url":"https://api.github.com/repos/FenixEdu/bennu/forks","keys_url":"https://api.github.com/repos/FenixEdu/bennu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FenixEdu/bennu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FenixEdu/bennu/teams","hooks_url":"https://api.github.com/repos/FenixEdu/bennu/hooks","issue_events_url":"https://api.github.com/repos/FenixEdu/bennu/issues/events{/number}","events_url":"https://api.github.com/repos/FenixEdu/bennu/events","assignees_url":"https://api.github.com/repos/FenixEdu/bennu/assignees{/user}","branches_url":"https://api.github.com/repos/FenixEdu/bennu/branches{/branch}","tags_url":"https://api.github.com/repos/FenixEdu/bennu/tags","blobs_url":"https://api.github.com/repos/FenixEdu/bennu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FenixEdu/bennu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FenixEdu/bennu/git/refs{/sha}","trees_url":"https://api.github.com/repos/FenixEdu/bennu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FenixEdu/bennu/statuses/{sha}","languages_url":"https://api.github.com/repos/FenixEdu/bennu/languages","stargazers_url":"https://api.github.com/repos/FenixEdu/bennu/stargazers","contributors_url":"https://api.github.com/repos/FenixEdu/bennu/contributors","subscribers_url":"https://api.github.com/repos/FenixEdu/bennu/subscribers","subscription_url":"https://api.github.com/repos/FenixEdu/bennu/subscription","commits_url":"https://api.github.com/repos/FenixEdu/bennu/commits{/sha}","git_commits_url":"https://api.github.com/repos/FenixEdu/bennu/git/commits{/sha}","comments_url":"https://api.github.com/repos/FenixEdu/bennu/comments{/number}","issue_comment_url":"https://api.github.com/repos/FenixEdu/bennu/issues/comments{/number}","contents_url":"https://api.github.com/repos/FenixEdu/bennu/contents/{+path}","compare_url":"https://api.github.com/repos/FenixEdu/bennu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FenixEdu/bennu/merges","archive_url":"https://api.github.com/repos/FenixEdu/bennu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FenixEdu/bennu/downloads","issues_url":"https://api.github.com/repos/FenixEdu/bennu/issues{/number}","pulls_url":"https://api.github.com/repos/FenixEdu/bennu/pulls{/number}","milestones_url":"https://api.github.com/repos/FenixEdu/bennu/milestones{/number}","notifications_url":"https://api.github.com/repos/FenixEdu/bennu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FenixEdu/bennu/labels{/name}","releases_url":"https://api.github.com/repos/FenixEdu/bennu/releases{/id}","deployments_url":"https://api.github.com/repos/FenixEdu/bennu/deployments","created_at":"2013-03-20T11:53:37Z","updated_at":"2017-02-27T11:26:13Z","pushed_at":"2017-11-23T18:04:43Z","git_url":"git://github.com/FenixEdu/bennu.git","ssh_url":"git@github.com:FenixEdu/bennu.git","clone_url":"https://github.com/FenixEdu/bennu.git","svn_url":"https://github.com/FenixEdu/bennu","homepage":"","size":69779,"stargazers_count":6,"watchers_count":6,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":26,"mirror_url":null,"archived":false,"open_issues_count":25,"forks":26,"open_issues":25,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/FenixEdu/bennu/pulls/310"},"html":{"href":"https://github.com/FenixEdu/bennu/pull/310"},"issue":{"href":"https://api.github.com/repos/FenixEdu/bennu/issues/310"},"comments":{"href":"https://api.github.com/repos/FenixEdu/bennu/issues/310/comments"},"review_comments":{"href":"https://api.github.com/repos/FenixEdu/bennu/pulls/310/comments"},"review_comment":{"href":"https://api.github.com/repos/FenixEdu/bennu/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/FenixEdu/bennu/pulls/310/commits"},"statuses":{"href":"https://api.github.com/repos/FenixEdu/bennu/statuses/0d6a68cadccfff40256adad349e304ad9ffff2f0"}},"author_association":"OWNER"}}
{"actor":{"display_login":"Luis-Cruz"}}