{"action":"created","comment":{"url":"https://api.github.com/repos/Jasig/cas/pulls/comments/42214364","id":42214364,"diff_hunk":"@@ -18,67 +18,80 @@\n  */\n package org.jasig.cas.support.pac4j.authentication.handler.support;\n \n-import org.apache.commons.lang3.StringUtils;\n-import org.jasig.cas.authentication.BasicCredentialMetaData;\n-import org.jasig.cas.authentication.DefaultHandlerResult;\n+import org.jasig.cas.authentication.Credential;\n import org.jasig.cas.authentication.HandlerResult;\n import org.jasig.cas.authentication.PreventedException;\n import org.jasig.cas.support.pac4j.authentication.principal.ClientCredential;\n+import org.pac4j.core.client.Client;\n import org.pac4j.core.client.Clients;\n+import org.pac4j.core.context.J2EContext;\n+import org.pac4j.core.context.WebContext;\n+import org.pac4j.core.credentials.Credentials;\n import org.pac4j.core.profile.UserProfile;\n+import org.springframework.beans.factory.annotation.Autowired;\n+import org.springframework.stereotype.Component;\n+import org.springframework.webflow.context.ExternalContextHolder;\n+import org.springframework.webflow.context.servlet.ServletExternalContext;\n \n-import javax.security.auth.login.FailedLoginException;\n+import javax.servlet.http.HttpServletRequest;\n+import javax.servlet.http.HttpServletResponse;\n+import javax.validation.constraints.NotNull;\n import java.security.GeneralSecurityException;\n \n /**\n- * Specialized handler which builds the authenticated user directly from the retrieved user profile.\n+ * Pac4j authentication handler which gets the credentials and then the user profile\n+ * in a delegated authentication process from an external identity provider.\n  *\n  * @author Jerome Leleu\n  * @since 3.5.0\n  */\n-public class ClientAuthenticationHandler extends AbstractClientAuthenticationHandler {\n+@Component(\"clientAuthenticationHandler\")\n+@SuppressWarnings(\"unchecked\")\n+public class ClientAuthenticationHandler extends AbstractPac4jAuthenticationHandler {\n \n     /**\n-     * Whether to use the typed identifier (by default) or just the identifier.\n+     * The clients for authentication.\n      */\n-    private boolean typedIdUsed = true;\n+    @NotNull\n+    @Autowired\n+    private Clients clients;\n \n-    /**\n-     * Define the clients.\n-     *\n-     * @param theClients The clients for authentication\n-     */\n-    public ClientAuthenticationHandler(final Clients theClients) {\n-        super(theClients);\n+    @Override\n+    public final boolean supports(final Credential credential) {\n+        return credential != null && ClientCredential.class.isAssignableFrom(credential.getClass());\n     }\n \n-    /**\n-     * {@inheritDoc}\n-     */\n     @Override\n-    protected HandlerResult createResult(final ClientCredential credentials, final UserProfile profile)\n-        throws GeneralSecurityException, PreventedException {\n-        final String id;\n-        if (typedIdUsed) {\n-            id = profile.getTypedId();\n-        } else {\n-            id = profile.getId();\n-        }\n-        if (StringUtils.isNotBlank(id)) {\n-            credentials.setUserProfile(profile);\n-            return new DefaultHandlerResult(\n-                this,\n-                new BasicCredentialMetaData(credentials),\n-                this.principalFactory.createPrincipal(id, profile.getAttributes()));\n-        }\n-        throw new FailedLoginException(\"No identifier found for this user profile: \" + profile);\n+    protected HandlerResult doAuthentication(final Credential credential) throws GeneralSecurityException, PreventedException {\n+        final ClientCredential clientCredentials = (ClientCredential) credential;\n+        logger.debug(\"clientCredentials  {}\", clientCredentials);\n+\n+        final Credentials credentials = clientCredentials.getCredentials();\n+        final String clientName = credentials.getClientName();\n+        logger.debug(\"clientName:  {}\", clientName);\n+\n+        // get client\n+        final Client<Credentials, UserProfile> client = this.clients.findClient(clientName);\n+        logger.debug(\"client: {}\", client);\n+\n+        // web context\n+        final ServletExternalContext servletExternalContext = (ServletExternalContext) ExternalContextHolder.getExternalContext();\n+        final HttpServletRequest request = (HttpServletRequest) servletExternalContext.getNativeRequest();\n+        final HttpServletResponse response = (HttpServletResponse) servletExternalContext.getNativeResponse();\n+        final WebContext webContext = new J2EContext(request, response);\n+\n+        // get user profile\n+        final UserProfile userProfile = client.getUserProfile(credentials, webContext);\n+        logger.debug(\"userProfile : {}\", userProfile);","path":"cas-server-support-pac4j/src/main/java/org/jasig/cas/support/pac4j/authentication/handler/support/ClientAuthenticationHandler.java","position":102,"original_position":102,"commit_id":"16e79bb1f16323179a9dc7f5e88637eb2879cc01","original_commit_id":"16e79bb1f16323179a9dc7f5e88637eb2879cc01","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":"Credentials are the most sensitive and they are displayed appropriately (a few lines avode). We also consider some information like access token (OAuth) to be sensitive and they would appear here with this log.\r\n\r\nSo the risk is: if you turn on DEBUG on `org.pac4j` and read the log in the following hours (the access token lasts two hours for Facebook for example), you can take it and act on behalf of someone.\r\n\r\nDo you want me to remove this log, change it to `trace` or keep it (as the risk is unlikely)?\r\n","created_at":"2015-10-16T07:10:22Z","updated_at":"2015-10-16T07:10:22Z","html_url":"https://github.com/Jasig/cas/pull/1217#discussion_r42214364","pull_request_url":"https://api.github.com/repos/Jasig/cas/pulls/1217","_links":{"self":{"href":"https://api.github.com/repos/Jasig/cas/pulls/comments/42214364"},"html":{"href":"https://github.com/Jasig/cas/pull/1217#discussion_r42214364"},"pull_request":{"href":"https://api.github.com/repos/Jasig/cas/pulls/1217"}}},"pull_request":{"url":"https://api.github.com/repos/Jasig/cas/pulls/1217","id":47798323,"html_url":"https://github.com/Jasig/cas/pull/1217","diff_url":"https://github.com/Jasig/cas/pull/1217.diff","patch_url":"https://github.com/Jasig/cas/pull/1217.patch","issue_url":"https://api.github.com/repos/Jasig/cas/issues/1217","number":1217,"state":"open","locked":false,"title":"Update CAS to use pac4j 1.8","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":"","created_at":"2015-10-15T15:01:37Z","updated_at":"2015-10-16T07:10:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8cf7e36ab3855561889fccd91d84c43f9bd9f847","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Jasig/cas/pulls/1217/commits","review_comments_url":"https://api.github.com/repos/Jasig/cas/pulls/1217/comments","review_comment_url":"https://api.github.com/repos/Jasig/cas/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Jasig/cas/issues/1217/comments","statuses_url":"https://api.github.com/repos/Jasig/cas/statuses/16e79bb1f16323179a9dc7f5e88637eb2879cc01","head":{"label":"leleuj:cas-1046","ref":"cas-1046","sha":"16e79bb1f16323179a9dc7f5e88637eb2879cc01","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},"repo":{"id":2370939,"name":"cas","full_name":"leleuj/cas","owner":{"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},"private":false,"html_url":"https://github.com/leleuj/cas","description":"Jasig CAS - Single Sign On for the Web","fork":true,"url":"https://api.github.com/repos/leleuj/cas","forks_url":"https://api.github.com/repos/leleuj/cas/forks","keys_url":"https://api.github.com/repos/leleuj/cas/keys{/key_id}","collaborators_url":"https://api.github.com/repos/leleuj/cas/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/leleuj/cas/teams","hooks_url":"https://api.github.com/repos/leleuj/cas/hooks","issue_events_url":"https://api.github.com/repos/leleuj/cas/issues/events{/number}","events_url":"https://api.github.com/repos/leleuj/cas/events","assignees_url":"https://api.github.com/repos/leleuj/cas/assignees{/user}","branches_url":"https://api.github.com/repos/leleuj/cas/branches{/branch}","tags_url":"https://api.github.com/repos/leleuj/cas/tags","blobs_url":"https://api.github.com/repos/leleuj/cas/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/leleuj/cas/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/leleuj/cas/git/refs{/sha}","trees_url":"https://api.github.com/repos/leleuj/cas/git/trees{/sha}","statuses_url":"https://api.github.com/repos/leleuj/cas/statuses/{sha}","languages_url":"https://api.github.com/repos/leleuj/cas/languages","stargazers_url":"https://api.github.com/repos/leleuj/cas/stargazers","contributors_url":"https://api.github.com/repos/leleuj/cas/contributors","subscribers_url":"https://api.github.com/repos/leleuj/cas/subscribers","subscription_url":"https://api.github.com/repos/leleuj/cas/subscription","commits_url":"https://api.github.com/repos/leleuj/cas/commits{/sha}","git_commits_url":"https://api.github.com/repos/leleuj/cas/git/commits{/sha}","comments_url":"https://api.github.com/repos/leleuj/cas/comments{/number}","issue_comment_url":"https://api.github.com/repos/leleuj/cas/issues/comments{/number}","contents_url":"https://api.github.com/repos/leleuj/cas/contents/{+path}","compare_url":"https://api.github.com/repos/leleuj/cas/compare/{base}...{head}","merges_url":"https://api.github.com/repos/leleuj/cas/merges","archive_url":"https://api.github.com/repos/leleuj/cas/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/leleuj/cas/downloads","issues_url":"https://api.github.com/repos/leleuj/cas/issues{/number}","pulls_url":"https://api.github.com/repos/leleuj/cas/pulls{/number}","milestones_url":"https://api.github.com/repos/leleuj/cas/milestones{/number}","notifications_url":"https://api.github.com/repos/leleuj/cas/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/leleuj/cas/labels{/name}","releases_url":"https://api.github.com/repos/leleuj/cas/releases{/id}","created_at":"2011-09-12T12:30:36Z","updated_at":"2014-11-17T15:34:37Z","pushed_at":"2015-10-15T15:09:30Z","git_url":"git://github.com/leleuj/cas.git","ssh_url":"git@github.com:leleuj/cas.git","clone_url":"https://github.com/leleuj/cas.git","svn_url":"https://github.com/leleuj/cas","homepage":"http://www.jasig.org/cas","size":37464,"stargazers_count":2,"watchers_count":2,"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":2,"default_branch":"master"}},"base":{"label":"Jasig:master","ref":"master","sha":"9fb1500631b01a72e510f4e57e9efe65b5dce4a5","user":{"login":"Jasig","id":884285,"avatar_url":"https://avatars.githubusercontent.com/u/884285?v=3","gravatar_id":"","url":"https://api.github.com/users/Jasig","html_url":"https://github.com/Jasig","followers_url":"https://api.github.com/users/Jasig/followers","following_url":"https://api.github.com/users/Jasig/following{/other_user}","gists_url":"https://api.github.com/users/Jasig/gists{/gist_id}","starred_url":"https://api.github.com/users/Jasig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jasig/subscriptions","organizations_url":"https://api.github.com/users/Jasig/orgs","repos_url":"https://api.github.com/users/Jasig/repos","events_url":"https://api.github.com/users/Jasig/events{/privacy}","received_events_url":"https://api.github.com/users/Jasig/received_events","type":"Organization","site_admin":false},"repo":{"id":2352744,"name":"cas","full_name":"Jasig/cas","owner":{"login":"Jasig","id":884285,"avatar_url":"https://avatars.githubusercontent.com/u/884285?v=3","gravatar_id":"","url":"https://api.github.com/users/Jasig","html_url":"https://github.com/Jasig","followers_url":"https://api.github.com/users/Jasig/followers","following_url":"https://api.github.com/users/Jasig/following{/other_user}","gists_url":"https://api.github.com/users/Jasig/gists{/gist_id}","starred_url":"https://api.github.com/users/Jasig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jasig/subscriptions","organizations_url":"https://api.github.com/users/Jasig/orgs","repos_url":"https://api.github.com/users/Jasig/repos","events_url":"https://api.github.com/users/Jasig/events{/privacy}","received_events_url":"https://api.github.com/users/Jasig/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Jasig/cas","description":"Apereo CAS - Single Sign On for the Web","fork":false,"url":"https://api.github.com/repos/Jasig/cas","forks_url":"https://api.github.com/repos/Jasig/cas/forks","keys_url":"https://api.github.com/repos/Jasig/cas/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Jasig/cas/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Jasig/cas/teams","hooks_url":"https://api.github.com/repos/Jasig/cas/hooks","issue_events_url":"https://api.github.com/repos/Jasig/cas/issues/events{/number}","events_url":"https://api.github.com/repos/Jasig/cas/events","assignees_url":"https://api.github.com/repos/Jasig/cas/assignees{/user}","branches_url":"https://api.github.com/repos/Jasig/cas/branches{/branch}","tags_url":"https://api.github.com/repos/Jasig/cas/tags","blobs_url":"https://api.github.com/repos/Jasig/cas/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Jasig/cas/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Jasig/cas/git/refs{/sha}","trees_url":"https://api.github.com/repos/Jasig/cas/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Jasig/cas/statuses/{sha}","languages_url":"https://api.github.com/repos/Jasig/cas/languages","stargazers_url":"https://api.github.com/repos/Jasig/cas/stargazers","contributors_url":"https://api.github.com/repos/Jasig/cas/contributors","subscribers_url":"https://api.github.com/repos/Jasig/cas/subscribers","subscription_url":"https://api.github.com/repos/Jasig/cas/subscription","commits_url":"https://api.github.com/repos/Jasig/cas/commits{/sha}","git_commits_url":"https://api.github.com/repos/Jasig/cas/git/commits{/sha}","comments_url":"https://api.github.com/repos/Jasig/cas/comments{/number}","issue_comment_url":"https://api.github.com/repos/Jasig/cas/issues/comments{/number}","contents_url":"https://api.github.com/repos/Jasig/cas/contents/{+path}","compare_url":"https://api.github.com/repos/Jasig/cas/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Jasig/cas/merges","archive_url":"https://api.github.com/repos/Jasig/cas/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Jasig/cas/downloads","issues_url":"https://api.github.com/repos/Jasig/cas/issues{/number}","pulls_url":"https://api.github.com/repos/Jasig/cas/pulls{/number}","milestones_url":"https://api.github.com/repos/Jasig/cas/milestones{/number}","notifications_url":"https://api.github.com/repos/Jasig/cas/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Jasig/cas/labels{/name}","releases_url":"https://api.github.com/repos/Jasig/cas/releases{/id}","created_at":"2011-09-09T01:36:42Z","updated_at":"2015-10-15T08:33:09Z","pushed_at":"2015-10-16T04:07:35Z","git_url":"git://github.com/Jasig/cas.git","ssh_url":"git@github.com:Jasig/cas.git","clone_url":"https://github.com/Jasig/cas.git","svn_url":"https://github.com/Jasig/cas","homepage":"http://jasig.github.io/cas/","size":645832,"stargazers_count":902,"watchers_count":902,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":699,"mirror_url":null,"open_issues_count":60,"forks":699,"open_issues":60,"watchers":902,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Jasig/cas/pulls/1217"},"html":{"href":"https://github.com/Jasig/cas/pull/1217"},"issue":{"href":"https://api.github.com/repos/Jasig/cas/issues/1217"},"comments":{"href":"https://api.github.com/repos/Jasig/cas/issues/1217/comments"},"review_comments":{"href":"https://api.github.com/repos/Jasig/cas/pulls/1217/comments"},"review_comment":{"href":"https://api.github.com/repos/Jasig/cas/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Jasig/cas/pulls/1217/commits"},"statuses":{"href":"https://api.github.com/repos/Jasig/cas/statuses/16e79bb1f16323179a9dc7f5e88637eb2879cc01"}}}}