{"action":"created","comment":{"url":"https://api.github.com/repos/pac4j/pac4j/pulls/comments/32293037","id":32293037,"diff_hunk":"@@ -0,0 +1,86 @@\n+/*\n+ * Copyright 2012 - 2015 pac4j organization\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ *\n+ */\n+\n+package org.pac4j.cas.client.rest;\n+\n+import org.apache.commons.httpclient.HttpStatus;\n+import org.jasig.cas.client.validation.TicketValidator;\n+import org.pac4j.http.credentials.UsernamePasswordCredentials;\n+import org.pac4j.http.credentials.authenticator.Authenticator;\n+\n+import java.io.BufferedWriter;\n+import java.io.IOException;\n+import java.io.OutputStreamWriter;\n+import java.net.HttpURLConnection;\n+import java.net.URL;\n+\n+/**\n+ * This is {@link CasRestAuthenticator}.\n+ *\n+ * @author Misagh Moayyed\n+ * @since 1.8.0\n+ */\n+public class CasRestAuthenticator implements Authenticator<UsernamePasswordCredentials> {\n+    private final URL endpointURL;\n+    private final TicketValidator ticketValidator;\n+\n+    public CasRestAuthenticator(final URL endpointURL, final TicketValidator ticketValidator) {\n+        this.endpointURL = endpointURL;\n+        this.ticketValidator = ticketValidator;\n+    }\n+\n+    @Override\n+    public void validate(final UsernamePasswordCredentials credentials) {\n+        final String ticketGrantingTicketId = requestTicketGrantingTicket(credentials.getUsername(), credentials.getPassword());\n+        final HttpTGTProfile profile = new HttpTGTProfile(ticketGrantingTicketId);","path":"pac4j-cas/src/main/java/org/pac4j/cas/client/rest/CasRestAuthenticator.java","position":49,"original_position":49,"commit_id":"ff1307aeb73e9b057b60ad5ad5ff3fd2ba5f0ce4","original_commit_id":"ff1307aeb73e9b057b60ad5ad5ff3fd2ba5f0ce4","user":{"login":"leleuj","id":1038508,"avatar_url":"https://avatars.githubusercontent.com/u/1038508?v=3","gravatar_id":"","url":"https://api.github.com/users/leleuj","html_url":"https://github.com/leleuj","followers_url":"https://api.github.com/users/leleuj/followers","following_url":"https://api.github.com/users/leleuj/following{/other_user}","gists_url":"https://api.github.com/users/leleuj/gists{/gist_id}","starred_url":"https://api.github.com/users/leleuj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leleuj/subscriptions","organizations_url":"https://api.github.com/users/leleuj/orgs","repos_url":"https://api.github.com/users/leleuj/repos","events_url":"https://api.github.com/users/leleuj/events{/privacy}","received_events_url":"https://api.github.com/users/leleuj/received_events","type":"User","site_admin":false},"body":"What's the identifier for this profile? We may use the `username` even if that doesn't change anything actually.","created_at":"2015-06-12T06:32:45Z","updated_at":"2015-06-12T06:32:45Z","html_url":"https://github.com/pac4j/pac4j/pull/175#discussion_r32293037","pull_request_url":"https://api.github.com/repos/pac4j/pac4j/pulls/175","_links":{"self":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/comments/32293037"},"html":{"href":"https://github.com/pac4j/pac4j/pull/175#discussion_r32293037"},"pull_request":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/175"}}},"pull_request":{"url":"https://api.github.com/repos/pac4j/pac4j/pulls/175","id":37479951,"html_url":"https://github.com/pac4j/pac4j/pull/175","diff_url":"https://github.com/pac4j/pac4j/pull/175.diff","patch_url":"https://github.com/pac4j/pac4j/pull/175.patch","issue_url":"https://api.github.com/repos/pac4j/pac4j/issues/175","number":175,"state":"open","locked":false,"title":"Cas Rest Client","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":"```java\r\nfinal URL endpointURL = new URL(\"https://mmoayyed.unicon.net:8443/cas/v1/tickets\");\r\nfinal String casUrlPrefix = endpointURL.getProtocol() + \"://\" + endpointURL.getHost() + \":\"\r\n        + endpointURL.getPort() + \"/\" + endpointURL.getPath().split(\"/\")[1];\r\n\r\nfinal CasRestAuthenticator authenticator = new CasRestAuthenticator(endpointURL,\r\n        new Cas20ServiceTicketValidator(casUrlPrefix));\r\nfinal CasRestClient client = new CasRestClient(authenticator);\r\nfinal UsernamePasswordCredentials creds = new UsernamePasswordCredentials(\"casuser\", \"Mellon\", client.getName());\r\n\r\nfinal MockWebContext context = MockWebContext.create();\r\ncontext.addRequestParameter(client.getUsernameParameter(), creds.getUsername());\r\ncontext.addRequestParameter(client.getPasswordParameter(), creds.getPassword());\r\n\r\nfinal HttpProfile profile = client.requestTicketGrantingTicket(context);\r\nfinal CasCredentials casCreds = client.requestServiceTicket(endpointURL, profile);\r\nfinal CasProfile casProfile = client.validateServiceTicket(endpointURL, casCreds);\r\n```","created_at":"2015-06-11T16:03:37Z","updated_at":"2015-06-12T06:32:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e1936ba2a464cd6c029fb2401396bd66dc709bb3","assignee":null,"milestone":{"url":"https://api.github.com/repos/pac4j/pac4j/milestones/2","html_url":"https://github.com/pac4j/pac4j/milestones/1.8","labels_url":"https://api.github.com/repos/pac4j/pac4j/milestones/2/labels","id":1159821,"number":2,"title":"1.8","description":null,"creator":{"login":"leleuj","id":1038508,"avatar_url":"https://avatars.githubusercontent.com/u/1038508?v=3","gravatar_id":"","url":"https://api.github.com/users/leleuj","html_url":"https://github.com/leleuj","followers_url":"https://api.github.com/users/leleuj/followers","following_url":"https://api.github.com/users/leleuj/following{/other_user}","gists_url":"https://api.github.com/users/leleuj/gists{/gist_id}","starred_url":"https://api.github.com/users/leleuj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leleuj/subscriptions","organizations_url":"https://api.github.com/users/leleuj/orgs","repos_url":"https://api.github.com/users/leleuj/repos","events_url":"https://api.github.com/users/leleuj/events{/privacy}","received_events_url":"https://api.github.com/users/leleuj/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":2,"state":"open","created_at":"2015-06-11T07:51:25Z","updated_at":"2015-06-11T16:03:38Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/pac4j/pac4j/pulls/175/commits","review_comments_url":"https://api.github.com/repos/pac4j/pac4j/pulls/175/comments","review_comment_url":"https://api.github.com/repos/pac4j/pac4j/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pac4j/pac4j/issues/175/comments","statuses_url":"https://api.github.com/repos/pac4j/pac4j/statuses/ff1307aeb73e9b057b60ad5ad5ff3fd2ba5f0ce4","head":{"label":"mmoayyed:cas-rest-client","ref":"cas-rest-client","sha":"ff1307aeb73e9b057b60ad5ad5ff3fd2ba5f0ce4","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},"repo":{"id":35601449,"name":"pac4j","full_name":"mmoayyed/pac4j","owner":{"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},"private":false,"html_url":"https://github.com/mmoayyed/pac4j","description":"Multi protocols (OAuth, OpenID, CAS, SAML, HTTP, GAE) auhentication/authorization engine for Java","fork":true,"url":"https://api.github.com/repos/mmoayyed/pac4j","forks_url":"https://api.github.com/repos/mmoayyed/pac4j/forks","keys_url":"https://api.github.com/repos/mmoayyed/pac4j/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mmoayyed/pac4j/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mmoayyed/pac4j/teams","hooks_url":"https://api.github.com/repos/mmoayyed/pac4j/hooks","issue_events_url":"https://api.github.com/repos/mmoayyed/pac4j/issues/events{/number}","events_url":"https://api.github.com/repos/mmoayyed/pac4j/events","assignees_url":"https://api.github.com/repos/mmoayyed/pac4j/assignees{/user}","branches_url":"https://api.github.com/repos/mmoayyed/pac4j/branches{/branch}","tags_url":"https://api.github.com/repos/mmoayyed/pac4j/tags","blobs_url":"https://api.github.com/repos/mmoayyed/pac4j/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mmoayyed/pac4j/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mmoayyed/pac4j/git/refs{/sha}","trees_url":"https://api.github.com/repos/mmoayyed/pac4j/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mmoayyed/pac4j/statuses/{sha}","languages_url":"https://api.github.com/repos/mmoayyed/pac4j/languages","stargazers_url":"https://api.github.com/repos/mmoayyed/pac4j/stargazers","contributors_url":"https://api.github.com/repos/mmoayyed/pac4j/contributors","subscribers_url":"https://api.github.com/repos/mmoayyed/pac4j/subscribers","subscription_url":"https://api.github.com/repos/mmoayyed/pac4j/subscription","commits_url":"https://api.github.com/repos/mmoayyed/pac4j/commits{/sha}","git_commits_url":"https://api.github.com/repos/mmoayyed/pac4j/git/commits{/sha}","comments_url":"https://api.github.com/repos/mmoayyed/pac4j/comments{/number}","issue_comment_url":"https://api.github.com/repos/mmoayyed/pac4j/issues/comments{/number}","contents_url":"https://api.github.com/repos/mmoayyed/pac4j/contents/{+path}","compare_url":"https://api.github.com/repos/mmoayyed/pac4j/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mmoayyed/pac4j/merges","archive_url":"https://api.github.com/repos/mmoayyed/pac4j/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mmoayyed/pac4j/downloads","issues_url":"https://api.github.com/repos/mmoayyed/pac4j/issues{/number}","pulls_url":"https://api.github.com/repos/mmoayyed/pac4j/pulls{/number}","milestones_url":"https://api.github.com/repos/mmoayyed/pac4j/milestones{/number}","notifications_url":"https://api.github.com/repos/mmoayyed/pac4j/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mmoayyed/pac4j/labels{/name}","releases_url":"https://api.github.com/repos/mmoayyed/pac4j/releases{/id}","created_at":"2015-05-14T08:54:29Z","updated_at":"2015-05-14T08:54:30Z","pushed_at":"2015-06-11T16:02:38Z","git_url":"git://github.com/mmoayyed/pac4j.git","ssh_url":"git@github.com:mmoayyed/pac4j.git","clone_url":"https://github.com/mmoayyed/pac4j.git","svn_url":"https://github.com/mmoayyed/pac4j","homepage":"http://www.pac4j.org","size":12638,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"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":"73ba940cf29be006bc50b4529213ffccceb45065","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":"Multi protocols (OAuth, OpenID, CAS, SAML, HTTP, GAE) auhentication/authorization engine for Java","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}","created_at":"2012-01-28T17:04:12Z","updated_at":"2015-06-08T22:24:34Z","pushed_at":"2015-06-11T16:03:38Z","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":15246,"stargazers_count":271,"watchers_count":271,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":93,"mirror_url":null,"open_issues_count":14,"forks":93,"open_issues":14,"watchers":271,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/175"},"html":{"href":"https://github.com/pac4j/pac4j/pull/175"},"issue":{"href":"https://api.github.com/repos/pac4j/pac4j/issues/175"},"comments":{"href":"https://api.github.com/repos/pac4j/pac4j/issues/175/comments"},"review_comments":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/175/comments"},"review_comment":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/175/commits"},"statuses":{"href":"https://api.github.com/repos/pac4j/pac4j/statuses/ff1307aeb73e9b057b60ad5ad5ff3fd2ba5f0ce4"}}}}