{"action":"created","comment":{"url":"https://api.github.com/repos/pac4j/pac4j/pulls/comments/32399402","id":32399402,"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) {","path":"pac4j-cas/src/main/java/org/pac4j/cas/client/rest/CasRestAuthenticator.java","position":42,"original_position":41,"commit_id":"0c9ae8ce37c0643c686d48a2b8595f89585e030b","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":"I understand your opinion and value it. It would make sense for the LDAP implementation if I rely on ldaptive and an `Authenticator`. Because it's a very complex object I don't really want to replace it (so much work).\r\n\r\nThe philosophy of `pac4j` is to hide and abstract as much as possible from internal libraries. You should never know that it uses the `cas-client-core` library for Java or `Scribe` for OAuth support.\r\nIn the future, if `pac4j` becomes internally reactive (I had one more discussion with Tim Fox, the creator of Vertx about that), we may change the underlying library.\r\n\r\nYour argument (be able to switch from Cas30 to Cas40) is relevant but in practice, it doesn't work: if ever we upgrade to Cas40, I'm pretty sure we'll need to change the internal logic as well. So it doesn't really make sense to offer this ability.\r\nThe last update to version 3.3.3 of the CAS client generates breaking changes: upgrading is not that seamless as well.\r\n\r\nSo I'd really prefer to set the CAS server prefix url and the CAS REST url and hide the ticket alidator.\r\n","created_at":"2015-06-15T08:23:04Z","updated_at":"2015-06-15T08:23:04Z","html_url":"https://github.com/pac4j/pac4j/pull/175#discussion_r32399402","pull_request_url":"https://api.github.com/repos/pac4j/pac4j/pulls/175","_links":{"self":{"href":"https://api.github.com/repos/pac4j/pac4j/pulls/comments/32399402"},"html":{"href":"https://github.com/pac4j/pac4j/pull/175#discussion_r32399402"},"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-15T08:23:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"322340db364cb3d310081da2fa52609f7a477f27","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":5,"closed_issues":2,"state":"open","created_at":"2015-06-11T07:51:25Z","updated_at":"2015-06-13T07:19:43Z","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/0c9ae8ce37c0643c686d48a2b8595f89585e030b","head":{"label":"mmoayyed:cas-rest-client","ref":"cas-rest-client","sha":"0c9ae8ce37c0643c686d48a2b8595f89585e030b","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-13T21:48:01Z","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-15T02:39:32Z","pushed_at":"2015-06-13T21:48: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":15246,"stargazers_count":274,"watchers_count":274,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":93,"mirror_url":null,"open_issues_count":17,"forks":93,"open_issues":17,"watchers":274,"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/0c9ae8ce37c0643c686d48a2b8595f89585e030b"}}}}