{"action":"created","comment":{"url":"https://api.github.com/repos/pac4j/pac4j/pulls/comments/53545018","id":53545018,"diff_hunk":"@@ -0,0 +1,73 @@\n+package org.pac4j.http.client.direct;\n+\n+import org.pac4j.core.context.WebContext;\n+import org.pac4j.core.exception.RequiresHttpAction;\n+import org.pac4j.core.util.CommonHelper;\n+import org.pac4j.http.credentials.CredentialUtil;\n+import org.pac4j.http.credentials.DigestCredentials;\n+import org.pac4j.http.credentials.authenticator.DigestAuthenticator;\n+import org.pac4j.http.credentials.extractor.DigestAuthExtractor;\n+import org.pac4j.http.profile.creator.ProfileCreator;\n+\n+import java.text.SimpleDateFormat;\n+import java.util.Date;\n+import java.util.Random;\n+\n+/**\n+ * <p>This class is the client to authenticate users directly through HTTP digest auth.</p>\n+ * <p>It returns a {@link org.pac4j.http.profile.HttpProfile}.</p>\n+ *\n+ * @see org.pac4j.http.profile.HttpProfile\n+ * @author Mircea Carasel\n+ */\n+public class DirectDigestAuthClient extends DirectHttpClient<DigestCredentials> {\n+    private String realm = \"pac4jRealm\";\n+\n+    public DirectDigestAuthClient() {\n+    }\n+\n+    public DirectDigestAuthClient(final DigestAuthenticator digestAuthenticator) {\n+        setAuthenticator(digestAuthenticator);\n+    }\n+\n+    public DirectDigestAuthClient(final DigestAuthenticator digestAuthenticator,\n+                                 final ProfileCreator profileCreator) {\n+        setAuthenticator(digestAuthenticator);\n+        setProfileCreator(profileCreator);\n+    }\n+\n+    @Override\n+    public DigestCredentials getCredentials(WebContext context) throws RequiresHttpAction {\n+        DigestCredentials credentials = super.getCredentials(context);\n+        if (credentials == null) {\n+            String nonce = calculateNonce();\n+            /* Per RFC 2617","path":"pac4j-http/src/main/java/org/pac4j/http/client/direct/DirectDigestAuthClient.java","position":44,"original_position":44,"commit_id":"0b98bafe3fa59c12bfc8496f8052a07ef5549745","original_commit_id":"0b98bafe3fa59c12bfc8496f8052a07ef5549745","user":{"login":"mmoayyed","id":1205228,"avatar_url":"https://avatars.githubusercontent.com/u/1205228?v=3","gravatar_id":"","url":"https://api.github.com/users/mmoayyed","html_url":"https://github.com/mmoayyed","followers_url":"https://api.github.com/users/mmoayyed/followers","following_url":"https://api.github.com/users/mmoayyed/following{/other_user}","gists_url":"https://api.github.com/users/mmoayyed/gists{/gist_id}","starred_url":"https://api.github.com/users/mmoayyed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmoayyed/subscriptions","organizations_url":"https://api.github.com/users/mmoayyed/orgs","repos_url":"https://api.github.com/users/mmoayyed/repos","events_url":"https://api.github.com/users/mmoayyed/events{/privacy}","received_events_url":"https://api.github.com/users/mmoayyed/received_events","type":"User","site_admin":false},"body":"Could we make this an actual javadoc? ","created_at":"2016-02-20T05:33:47Z","updated_at":"2016-02-20T05:33:47Z","html_url":"https://github.com/pac4j/pac4j/pull/493#discussion_r53545018","pull_request_url":"https://api.github.com/repos/pac4j/pac4j/pulls/493","_links":{"self":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/comments/53545018"},"html":{"href":"https://github.com/pac4j/pac4j/pull/493#discussion_r53545018"},"pull_request":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/493"}}},"pull_request":{"url":"https://api.github.com/repos/pac4j/pac4j/pulls/493","id":59935217,"html_url":"https://github.com/pac4j/pac4j/pull/493","diff_url":"https://github.com/pac4j/pac4j/pull/493.diff","patch_url":"https://github.com/pac4j/pac4j/pull/493.patch","issue_url":"https://api.github.com/repos/pac4j/pac4j/issues/493","number":493,"state":"open","locked":false,"title":"HTTP Digest Direct Authenticator","user":{"login":"mirceac","id":294875,"avatar_url":"https://avatars.githubusercontent.com/u/294875?v=3","gravatar_id":"","url":"https://api.github.com/users/mirceac","html_url":"https://github.com/mirceac","followers_url":"https://api.github.com/users/mirceac/followers","following_url":"https://api.github.com/users/mirceac/following{/other_user}","gists_url":"https://api.github.com/users/mirceac/gists{/gist_id}","starred_url":"https://api.github.com/users/mirceac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mirceac/subscriptions","organizations_url":"https://api.github.com/users/mirceac/orgs","repos_url":"https://api.github.com/users/mirceac/repos","events_url":"https://api.github.com/users/mirceac/events{/privacy}","received_events_url":"https://api.github.com/users/mirceac/received_events","type":"User","site_admin":false},"body":"-implement RFC 2617 for digest authentication\r\nCreate DigestCredentials given Digest Authorization header\r\nThis has to be used similar as the Direct Basic Authenticator is used\r\nCreate new DigestAuthenticator intervace to validate DigestCredentials retrieved from the authenticator\r\n\r\nThe realm value is configurable:\r\n\r\n DirectDigestAuthClient digestAuthClient = new DirectDigestAuthClient(new SecurityDigestAuthenticator());\r\n digestAuthClient.setRealm(\"myRealm\");\r\n\r\nIn order to validate that Digest authentication is successful is needed that:\r\n\r\ndigestCredentials.getResponse().equals(digestCredentials.calculateServerDigest(true, pwd))\r\n\r\nwhere pwd is the user password kept in database.\r\nAccording to RFC 2617 the user may keep HA1 encoded format\r\nof the password in database: HA1=MD5(username-value + \":\" + realm-value + \":\" + passwd)\r\nIf the user keeps password in clear (not recommended) then the digest validation should be performed like this:\r\n\r\ndigestCredentials.getResponse().equals(digestCredentials.calculateServerDigest(false, pwd))\r\n\r\ndigestCredentials.getResponse() represents the client response digest\r\ndigestCredentials.calculcateServerDigest represents the server digest. These two must be equal for a successful digest authentication","created_at":"2016-02-19T11:09:22Z","updated_at":"2016-02-20T05:33:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"932398fb1d7e7c2cdb55e4bc80dedc32deb2ad39","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pac4j/pac4j/pulls/493/commits","review_comments_url":"https://api.github.com/repos/pac4j/pac4j/pulls/493/comments","review_comment_url":"https://api.github.com/repos/pac4j/pac4j/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pac4j/pac4j/issues/493/comments","statuses_url":"https://api.github.com/repos/pac4j/pac4j/statuses/0b98bafe3fa59c12bfc8496f8052a07ef5549745","head":{"label":"mirceac:master","ref":"master","sha":"0b98bafe3fa59c12bfc8496f8052a07ef5549745","user":{"login":"mirceac","id":294875,"avatar_url":"https://avatars.githubusercontent.com/u/294875?v=3","gravatar_id":"","url":"https://api.github.com/users/mirceac","html_url":"https://github.com/mirceac","followers_url":"https://api.github.com/users/mirceac/followers","following_url":"https://api.github.com/users/mirceac/following{/other_user}","gists_url":"https://api.github.com/users/mirceac/gists{/gist_id}","starred_url":"https://api.github.com/users/mirceac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mirceac/subscriptions","organizations_url":"https://api.github.com/users/mirceac/orgs","repos_url":"https://api.github.com/users/mirceac/repos","events_url":"https://api.github.com/users/mirceac/events{/privacy}","received_events_url":"https://api.github.com/users/mirceac/received_events","type":"User","site_admin":false},"repo":{"id":51522072,"name":"pac4j","full_name":"mirceac/pac4j","owner":{"login":"mirceac","id":294875,"avatar_url":"https://avatars.githubusercontent.com/u/294875?v=3","gravatar_id":"","url":"https://api.github.com/users/mirceac","html_url":"https://github.com/mirceac","followers_url":"https://api.github.com/users/mirceac/followers","following_url":"https://api.github.com/users/mirceac/following{/other_user}","gists_url":"https://api.github.com/users/mirceac/gists{/gist_id}","starred_url":"https://api.github.com/users/mirceac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mirceac/subscriptions","organizations_url":"https://api.github.com/users/mirceac/orgs","repos_url":"https://api.github.com/users/mirceac/repos","events_url":"https://api.github.com/users/mirceac/events{/privacy}","received_events_url":"https://api.github.com/users/mirceac/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mirceac/pac4j","description":"Security engine for Java (authentication, authorization, multi frameworks)","fork":true,"url":"https://api.github.com/repos/mirceac/pac4j","forks_url":"https://api.github.com/repos/mirceac/pac4j/forks","keys_url":"https://api.github.com/repos/mirceac/pac4j/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mirceac/pac4j/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mirceac/pac4j/teams","hooks_url":"https://api.github.com/repos/mirceac/pac4j/hooks","issue_events_url":"https://api.github.com/repos/mirceac/pac4j/issues/events{/number}","events_url":"https://api.github.com/repos/mirceac/pac4j/events","assignees_url":"https://api.github.com/repos/mirceac/pac4j/assignees{/user}","branches_url":"https://api.github.com/repos/mirceac/pac4j/branches{/branch}","tags_url":"https://api.github.com/repos/mirceac/pac4j/tags","blobs_url":"https://api.github.com/repos/mirceac/pac4j/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mirceac/pac4j/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mirceac/pac4j/git/refs{/sha}","trees_url":"https://api.github.com/repos/mirceac/pac4j/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mirceac/pac4j/statuses/{sha}","languages_url":"https://api.github.com/repos/mirceac/pac4j/languages","stargazers_url":"https://api.github.com/repos/mirceac/pac4j/stargazers","contributors_url":"https://api.github.com/repos/mirceac/pac4j/contributors","subscribers_url":"https://api.github.com/repos/mirceac/pac4j/subscribers","subscription_url":"https://api.github.com/repos/mirceac/pac4j/subscription","commits_url":"https://api.github.com/repos/mirceac/pac4j/commits{/sha}","git_commits_url":"https://api.github.com/repos/mirceac/pac4j/git/commits{/sha}","comments_url":"https://api.github.com/repos/mirceac/pac4j/comments{/number}","issue_comment_url":"https://api.github.com/repos/mirceac/pac4j/issues/comments{/number}","contents_url":"https://api.github.com/repos/mirceac/pac4j/contents/{+path}","compare_url":"https://api.github.com/repos/mirceac/pac4j/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mirceac/pac4j/merges","archive_url":"https://api.github.com/repos/mirceac/pac4j/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mirceac/pac4j/downloads","issues_url":"https://api.github.com/repos/mirceac/pac4j/issues{/number}","pulls_url":"https://api.github.com/repos/mirceac/pac4j/pulls{/number}","milestones_url":"https://api.github.com/repos/mirceac/pac4j/milestones{/number}","notifications_url":"https://api.github.com/repos/mirceac/pac4j/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mirceac/pac4j/labels{/name}","releases_url":"https://api.github.com/repos/mirceac/pac4j/releases{/id}","deployments_url":"https://api.github.com/repos/mirceac/pac4j/deployments","created_at":"2016-02-11T15:02:19Z","updated_at":"2016-02-11T15:02:21Z","pushed_at":"2016-02-19T15:36:01Z","git_url":"git://github.com/mirceac/pac4j.git","ssh_url":"git@github.com:mirceac/pac4j.git","clone_url":"https://github.com/mirceac/pac4j.git","svn_url":"https://github.com/mirceac/pac4j","homepage":"http://www.pac4j.org","size":22238,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"pac4j:master","ref":"master","sha":"e37de32016aff9b344a56c07bd1520eca1a77f8d","user":{"login":"pac4j","id":7540865,"avatar_url":"https://avatars.githubusercontent.com/u/7540865?v=3","gravatar_id":"","url":"https://api.github.com/users/pac4j","html_url":"https://github.com/pac4j","followers_url":"https://api.github.com/users/pac4j/followers","following_url":"https://api.github.com/users/pac4j/following{/other_user}","gists_url":"https://api.github.com/users/pac4j/gists{/gist_id}","starred_url":"https://api.github.com/users/pac4j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pac4j/subscriptions","organizations_url":"https://api.github.com/users/pac4j/orgs","repos_url":"https://api.github.com/users/pac4j/repos","events_url":"https://api.github.com/users/pac4j/events{/privacy}","received_events_url":"https://api.github.com/users/pac4j/received_events","type":"Organization","site_admin":false},"repo":{"id":3291848,"name":"pac4j","full_name":"pac4j/pac4j","owner":{"login":"pac4j","id":7540865,"avatar_url":"https://avatars.githubusercontent.com/u/7540865?v=3","gravatar_id":"","url":"https://api.github.com/users/pac4j","html_url":"https://github.com/pac4j","followers_url":"https://api.github.com/users/pac4j/followers","following_url":"https://api.github.com/users/pac4j/following{/other_user}","gists_url":"https://api.github.com/users/pac4j/gists{/gist_id}","starred_url":"https://api.github.com/users/pac4j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pac4j/subscriptions","organizations_url":"https://api.github.com/users/pac4j/orgs","repos_url":"https://api.github.com/users/pac4j/repos","events_url":"https://api.github.com/users/pac4j/events{/privacy}","received_events_url":"https://api.github.com/users/pac4j/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pac4j/pac4j","description":"Security engine for Java (authentication, authorization, multi frameworks)","fork":false,"url":"https://api.github.com/repos/pac4j/pac4j","forks_url":"https://api.github.com/repos/pac4j/pac4j/forks","keys_url":"https://api.github.com/repos/pac4j/pac4j/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pac4j/pac4j/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pac4j/pac4j/teams","hooks_url":"https://api.github.com/repos/pac4j/pac4j/hooks","issue_events_url":"https://api.github.com/repos/pac4j/pac4j/issues/events{/number}","events_url":"https://api.github.com/repos/pac4j/pac4j/events","assignees_url":"https://api.github.com/repos/pac4j/pac4j/assignees{/user}","branches_url":"https://api.github.com/repos/pac4j/pac4j/branches{/branch}","tags_url":"https://api.github.com/repos/pac4j/pac4j/tags","blobs_url":"https://api.github.com/repos/pac4j/pac4j/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pac4j/pac4j/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pac4j/pac4j/git/refs{/sha}","trees_url":"https://api.github.com/repos/pac4j/pac4j/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pac4j/pac4j/statuses/{sha}","languages_url":"https://api.github.com/repos/pac4j/pac4j/languages","stargazers_url":"https://api.github.com/repos/pac4j/pac4j/stargazers","contributors_url":"https://api.github.com/repos/pac4j/pac4j/contributors","subscribers_url":"https://api.github.com/repos/pac4j/pac4j/subscribers","subscription_url":"https://api.github.com/repos/pac4j/pac4j/subscription","commits_url":"https://api.github.com/repos/pac4j/pac4j/commits{/sha}","git_commits_url":"https://api.github.com/repos/pac4j/pac4j/git/commits{/sha}","comments_url":"https://api.github.com/repos/pac4j/pac4j/comments{/number}","issue_comment_url":"https://api.github.com/repos/pac4j/pac4j/issues/comments{/number}","contents_url":"https://api.github.com/repos/pac4j/pac4j/contents/{+path}","compare_url":"https://api.github.com/repos/pac4j/pac4j/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pac4j/pac4j/merges","archive_url":"https://api.github.com/repos/pac4j/pac4j/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pac4j/pac4j/downloads","issues_url":"https://api.github.com/repos/pac4j/pac4j/issues{/number}","pulls_url":"https://api.github.com/repos/pac4j/pac4j/pulls{/number}","milestones_url":"https://api.github.com/repos/pac4j/pac4j/milestones{/number}","notifications_url":"https://api.github.com/repos/pac4j/pac4j/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pac4j/pac4j/labels{/name}","releases_url":"https://api.github.com/repos/pac4j/pac4j/releases{/id}","deployments_url":"https://api.github.com/repos/pac4j/pac4j/deployments","created_at":"2012-01-28T17:04:12Z","updated_at":"2016-02-19T12:37:16Z","pushed_at":"2016-02-19T15:36:01Z","git_url":"git://github.com/pac4j/pac4j.git","ssh_url":"git@github.com:pac4j/pac4j.git","clone_url":"https://github.com/pac4j/pac4j.git","svn_url":"https://github.com/pac4j/pac4j","homepage":"http://www.pac4j.org","size":23843,"stargazers_count":461,"watchers_count":461,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":174,"mirror_url":null,"open_issues_count":21,"forks":174,"open_issues":21,"watchers":461,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/493"},"html":{"href":"https://github.com/pac4j/pac4j/pull/493"},"issue":{"href":"https://api.github.com/repos/pac4j/pac4j/issues/493"},"comments":{"href":"https://api.github.com/repos/pac4j/pac4j/issues/493/comments"},"review_comments":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/493/comments"},"review_comment":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/493/commits"},"statuses":{"href":"https://api.github.com/repos/pac4j/pac4j/statuses/0b98bafe3fa59c12bfc8496f8052a07ef5549745"}}}}