{"action":"created","comment":{"url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls/comments/65005682","id":65005682,"diff_hunk":"@@ -0,0 +1,42 @@\n+package ch.wisv.areafiftylan.service;\n+\n+import ch.wisv.areafiftylan.model.User;\n+import ch.wisv.areafiftylan.security.token.AuthenticationToken;\n+import ch.wisv.areafiftylan.service.repository.token.AuthenticationTokenRepository;\n+import org.springframework.beans.factory.annotation.Autowired;\n+import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;\n+import org.springframework.security.core.userdetails.UsernameNotFoundException;\n+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;\n+import org.springframework.stereotype.Service;\n+\n+/**\n+ * Created by Sille Kamoen on 6-5-16.\n+ */\n+@Service\n+public class AuthenticationServiceImpl implements AuthenticationService {\n+\n+    @Autowired\n+    AuthenticationTokenRepository authenticationTokenRepository;\n+\n+    @Autowired\n+    UserService userService;\n+\n+    @Override\n+    public String createNewAuthToken(String username, String password) {\n+        User user = userService.getUserByUsername(username).orElseThrow(() -> new UsernameNotFoundException(username));\n+\n+        if (correctCredentials(user, password)) {\n+            // Delete the old Token\n+            authenticationTokenRepository.findByUserUsername(username)\n+                    .ifPresent(t -> authenticationTokenRepository.delete(t));\n+\n+            return authenticationTokenRepository.save(new AuthenticationToken(user, 60 * 24 * 2)).getToken();","path":"src/main/java/ch/wisv/areafiftylan/service/AuthenticationServiceImpl.java","position":33,"original_position":33,"commit_id":"4e77ea6a67abee6346c28f80596bbe85557c122d","original_commit_id":"4e77ea6a67abee6346c28f80596bbe85557c122d","user":{"login":"bvanderdrift","id":6398452,"avatar_url":"https://avatars.githubusercontent.com/u/6398452?v=3","gravatar_id":"","url":"https://api.github.com/users/bvanderdrift","html_url":"https://github.com/bvanderdrift","followers_url":"https://api.github.com/users/bvanderdrift/followers","following_url":"https://api.github.com/users/bvanderdrift/following{/other_user}","gists_url":"https://api.github.com/users/bvanderdrift/gists{/gist_id}","starred_url":"https://api.github.com/users/bvanderdrift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bvanderdrift/subscriptions","organizations_url":"https://api.github.com/users/bvanderdrift/orgs","repos_url":"https://api.github.com/users/bvanderdrift/repos","events_url":"https://api.github.com/users/bvanderdrift/events{/privacy}","received_events_url":"https://api.github.com/users/bvanderdrift/received_events","type":"User","site_admin":false},"body":"I see a magic number! Please use an internal EXPIRATION final as seen in [other tokens](https://github.com/AreaFiftyLAN/lancie-api/blob/master/src/main/java/ch/wisv/areafiftylan/security/token/Token.java#L14) for default values.","created_at":"2016-05-29T14:18:00Z","updated_at":"2016-05-29T14:18:00Z","html_url":"https://github.com/AreaFiftyLAN/lancie-api/pull/243#discussion_r65005682","pull_request_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls/243","_links":{"self":{"href":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls/comments/65005682"},"html":{"href":"https://github.com/AreaFiftyLAN/lancie-api/pull/243#discussion_r65005682"},"pull_request":{"href":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls/243"}}},"pull_request":{"url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls/243","id":71547597,"html_url":"https://github.com/AreaFiftyLAN/lancie-api/pull/243","diff_url":"https://github.com/AreaFiftyLAN/lancie-api/pull/243.diff","patch_url":"https://github.com/AreaFiftyLAN/lancie-api/pull/243.patch","issue_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/issues/243","number":243,"state":"open","locked":false,"title":"Token based authentication","user":{"login":"skamoen","id":3198784,"avatar_url":"https://avatars.githubusercontent.com/u/3198784?v=3","gravatar_id":"","url":"https://api.github.com/users/skamoen","html_url":"https://github.com/skamoen","followers_url":"https://api.github.com/users/skamoen/followers","following_url":"https://api.github.com/users/skamoen/following{/other_user}","gists_url":"https://api.github.com/users/skamoen/gists{/gist_id}","starred_url":"https://api.github.com/users/skamoen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skamoen/subscriptions","organizations_url":"https://api.github.com/users/skamoen/orgs","repos_url":"https://api.github.com/users/skamoen/repos","events_url":"https://api.github.com/users/skamoen/events{/privacy}","received_events_url":"https://api.github.com/users/skamoen/received_events","type":"User","site_admin":false},"body":"Lets try this again (#208), as this is required for Echo-gaming (Intranet)\r\n\r\nFor clients that are not the browser, the form-based authentication doesn't work. This implements a Token-based authentication method that generates a Token with which clients can perform actions.\r\n\r\nTokens are generated with a POST on /token with a username and password. If credentials are correct, a Token will be returned and saved.\r\n\r\nRequests with a token in the X-Auth-Token header will be authenticated by the new Filter.\r\n\r\nRequests with a valid token are excluded from CSRF. ","created_at":"2016-05-26T12:31:21Z","updated_at":"2016-05-29T14:18:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bc41369e23bc0d87214fd9fe7eee971585fa83ed","assignee":{"login":"bvanderdrift","id":6398452,"avatar_url":"https://avatars.githubusercontent.com/u/6398452?v=3","gravatar_id":"","url":"https://api.github.com/users/bvanderdrift","html_url":"https://github.com/bvanderdrift","followers_url":"https://api.github.com/users/bvanderdrift/followers","following_url":"https://api.github.com/users/bvanderdrift/following{/other_user}","gists_url":"https://api.github.com/users/bvanderdrift/gists{/gist_id}","starred_url":"https://api.github.com/users/bvanderdrift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bvanderdrift/subscriptions","organizations_url":"https://api.github.com/users/bvanderdrift/orgs","repos_url":"https://api.github.com/users/bvanderdrift/repos","events_url":"https://api.github.com/users/bvanderdrift/events{/privacy}","received_events_url":"https://api.github.com/users/bvanderdrift/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls/243/commits","review_comments_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls/243/comments","review_comment_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/issues/243/comments","statuses_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/statuses/4e77ea6a67abee6346c28f80596bbe85557c122d","head":{"label":"AreaFiftyLAN:feature-token-based-authentication","ref":"feature-token-based-authentication","sha":"4e77ea6a67abee6346c28f80596bbe85557c122d","user":{"login":"AreaFiftyLAN","id":13952301,"avatar_url":"https://avatars.githubusercontent.com/u/13952301?v=3","gravatar_id":"","url":"https://api.github.com/users/AreaFiftyLAN","html_url":"https://github.com/AreaFiftyLAN","followers_url":"https://api.github.com/users/AreaFiftyLAN/followers","following_url":"https://api.github.com/users/AreaFiftyLAN/following{/other_user}","gists_url":"https://api.github.com/users/AreaFiftyLAN/gists{/gist_id}","starred_url":"https://api.github.com/users/AreaFiftyLAN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AreaFiftyLAN/subscriptions","organizations_url":"https://api.github.com/users/AreaFiftyLAN/orgs","repos_url":"https://api.github.com/users/AreaFiftyLAN/repos","events_url":"https://api.github.com/users/AreaFiftyLAN/events{/privacy}","received_events_url":"https://api.github.com/users/AreaFiftyLAN/received_events","type":"Organization","site_admin":false},"repo":{"id":40057514,"name":"lancie-api","full_name":"AreaFiftyLAN/lancie-api","owner":{"login":"AreaFiftyLAN","id":13952301,"avatar_url":"https://avatars.githubusercontent.com/u/13952301?v=3","gravatar_id":"","url":"https://api.github.com/users/AreaFiftyLAN","html_url":"https://github.com/AreaFiftyLAN","followers_url":"https://api.github.com/users/AreaFiftyLAN/followers","following_url":"https://api.github.com/users/AreaFiftyLAN/following{/other_user}","gists_url":"https://api.github.com/users/AreaFiftyLAN/gists{/gist_id}","starred_url":"https://api.github.com/users/AreaFiftyLAN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AreaFiftyLAN/subscriptions","organizations_url":"https://api.github.com/users/AreaFiftyLAN/orgs","repos_url":"https://api.github.com/users/AreaFiftyLAN/repos","events_url":"https://api.github.com/users/AreaFiftyLAN/events{/privacy}","received_events_url":"https://api.github.com/users/AreaFiftyLAN/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/AreaFiftyLAN/lancie-api","description":"Spring based implementation of the LANcie API","fork":false,"url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api","forks_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/forks","keys_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/teams","hooks_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/hooks","issue_events_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/issues/events{/number}","events_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/events","assignees_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/assignees{/user}","branches_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/branches{/branch}","tags_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/tags","blobs_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/statuses/{sha}","languages_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/languages","stargazers_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/stargazers","contributors_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/contributors","subscribers_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/subscribers","subscription_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/subscription","commits_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/contents/{+path}","compare_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/merges","archive_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/downloads","issues_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/issues{/number}","pulls_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls{/number}","milestones_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/milestones{/number}","notifications_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/labels{/name}","releases_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/releases{/id}","deployments_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/deployments","created_at":"2015-08-01T19:20:38Z","updated_at":"2016-05-20T07:23:20Z","pushed_at":"2016-05-28T23:05:31Z","git_url":"git://github.com/AreaFiftyLAN/lancie-api.git","ssh_url":"git@github.com:AreaFiftyLAN/lancie-api.git","clone_url":"https://github.com/AreaFiftyLAN/lancie-api.git","svn_url":"https://github.com/AreaFiftyLAN/lancie-api","homepage":null,"size":11086,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":46,"forks":1,"open_issues":46,"watchers":3,"default_branch":"master"}},"base":{"label":"AreaFiftyLAN:master","ref":"master","sha":"18203fe57222d46c5ed09a5ae239590bff33f0bf","user":{"login":"AreaFiftyLAN","id":13952301,"avatar_url":"https://avatars.githubusercontent.com/u/13952301?v=3","gravatar_id":"","url":"https://api.github.com/users/AreaFiftyLAN","html_url":"https://github.com/AreaFiftyLAN","followers_url":"https://api.github.com/users/AreaFiftyLAN/followers","following_url":"https://api.github.com/users/AreaFiftyLAN/following{/other_user}","gists_url":"https://api.github.com/users/AreaFiftyLAN/gists{/gist_id}","starred_url":"https://api.github.com/users/AreaFiftyLAN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AreaFiftyLAN/subscriptions","organizations_url":"https://api.github.com/users/AreaFiftyLAN/orgs","repos_url":"https://api.github.com/users/AreaFiftyLAN/repos","events_url":"https://api.github.com/users/AreaFiftyLAN/events{/privacy}","received_events_url":"https://api.github.com/users/AreaFiftyLAN/received_events","type":"Organization","site_admin":false},"repo":{"id":40057514,"name":"lancie-api","full_name":"AreaFiftyLAN/lancie-api","owner":{"login":"AreaFiftyLAN","id":13952301,"avatar_url":"https://avatars.githubusercontent.com/u/13952301?v=3","gravatar_id":"","url":"https://api.github.com/users/AreaFiftyLAN","html_url":"https://github.com/AreaFiftyLAN","followers_url":"https://api.github.com/users/AreaFiftyLAN/followers","following_url":"https://api.github.com/users/AreaFiftyLAN/following{/other_user}","gists_url":"https://api.github.com/users/AreaFiftyLAN/gists{/gist_id}","starred_url":"https://api.github.com/users/AreaFiftyLAN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AreaFiftyLAN/subscriptions","organizations_url":"https://api.github.com/users/AreaFiftyLAN/orgs","repos_url":"https://api.github.com/users/AreaFiftyLAN/repos","events_url":"https://api.github.com/users/AreaFiftyLAN/events{/privacy}","received_events_url":"https://api.github.com/users/AreaFiftyLAN/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/AreaFiftyLAN/lancie-api","description":"Spring based implementation of the LANcie API","fork":false,"url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api","forks_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/forks","keys_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/teams","hooks_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/hooks","issue_events_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/issues/events{/number}","events_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/events","assignees_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/assignees{/user}","branches_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/branches{/branch}","tags_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/tags","blobs_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/statuses/{sha}","languages_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/languages","stargazers_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/stargazers","contributors_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/contributors","subscribers_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/subscribers","subscription_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/subscription","commits_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/contents/{+path}","compare_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/merges","archive_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/downloads","issues_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/issues{/number}","pulls_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls{/number}","milestones_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/milestones{/number}","notifications_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/labels{/name}","releases_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/releases{/id}","deployments_url":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/deployments","created_at":"2015-08-01T19:20:38Z","updated_at":"2016-05-20T07:23:20Z","pushed_at":"2016-05-28T23:05:31Z","git_url":"git://github.com/AreaFiftyLAN/lancie-api.git","ssh_url":"git@github.com:AreaFiftyLAN/lancie-api.git","clone_url":"https://github.com/AreaFiftyLAN/lancie-api.git","svn_url":"https://github.com/AreaFiftyLAN/lancie-api","homepage":null,"size":11086,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":46,"forks":1,"open_issues":46,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls/243"},"html":{"href":"https://github.com/AreaFiftyLAN/lancie-api/pull/243"},"issue":{"href":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/issues/243"},"comments":{"href":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/issues/243/comments"},"review_comments":{"href":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls/243/comments"},"review_comment":{"href":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/pulls/243/commits"},"statuses":{"href":"https://api.github.com/repos/AreaFiftyLAN/lancie-api/statuses/4e77ea6a67abee6346c28f80596bbe85557c122d"}}}}
{"actor":{"display_login":"bvanderdrift"}}