{"action":"created","comment":{"url":"https://api.github.com/repos/Jasig/uPortal/pulls/comments/30054329","id":30054329,"diff_hunk":"@@ -0,0 +1,172 @@\n+/**\n+ * Licensed to Apereo under one or more contributor license\n+ * agreements. See the NOTICE file distributed with this work\n+ * for additional information regarding copyright ownership.\n+ * Apereo licenses this file to you under the Apache License,\n+ * Version 2.0 (the \"License\"); you may not use this file\n+ * except in compliance with the License.  You may obtain a\n+ * copy of the License at the following location:\n+ *\n+ *   http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+package org.jasig.portal.groups.pags.testers;\n+\n+import org.apache.commons.lang.Validate;\n+import org.jasig.portal.EntityIdentifier;\n+import org.jasig.portal.groups.IEntityGroup;\n+import org.jasig.portal.groups.IGroupMember;\n+import org.jasig.portal.groups.pags.IPersonTester;\n+import org.jasig.portal.groups.pags.dao.IPersonAttributesGroupTestDefinition;\n+import org.jasig.portal.portlets.groupselector.EntityEnum;\n+import org.jasig.portal.security.IPerson;\n+import org.jasig.portal.services.GroupService;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.util.HashSet;\n+import java.util.Iterator;\n+import java.util.Set;\n+import java.util.concurrent.ConcurrentSkipListSet;\n+\n+/**\n+ * Immutable PAGS Tester for inclusive/exclusive membership in sets of groups. To avoid infinite recursion,\n+ * calls to {@code test()} are tracked by parameters plus thread ID.\n+ *\n+ * @author  Benito J. Gonzalez <bgonzalez@unicon.net>\n+ * @see     org.jasig.portal.groups.pags.IPersonTester\n+ * @see     org.jasig.portal.groups.pags.dao.EntityPersonAttributesGroupStore\n+ * @see     org.jasig.portal.groups.pags.dao.IPersonAttributesGroupTestGroupDefinition\n+ * @since   4.3\n+ */\n+public final class AdHocGroupTester implements IPersonTester {\n+\n+    private static final Logger logger = LoggerFactory.getLogger(AdHocGroupTester.class);\n+    private static final Set<String> currentPersons = new ConcurrentSkipListSet<>();\n+    private final Set<IEntityGroup> includes = new HashSet<>();\n+    private final Set<IEntityGroup> excludes = new HashSet<>();\n+    private final String hashcode;\n+\n+    public AdHocGroupTester(IPersonAttributesGroupTestDefinition definition) {\n+        Validate.notNull(definition.getIncludes());\n+        Validate.notNull(definition.getExcludes());\n+        collectGroups(definition.getIncludes(), this.includes, true);\n+        collectGroups(definition.getExcludes(), this.excludes, false);\n+        hashcode = calcHashcode();\n+    }\n+\n+    /**\n+     * Given a set of group names, find the entity groups and add them to the {@code groups} collection.\n+     * If a group is not found, either log a warning or throw an {@code IllegalArgumentException} based on\n+     * the {@code throwOnFail} parameter.\n+     *\n+     * @param groupNames    Set of group names to find\n+     * @param groups        Set to add named groups from {@link GroupService}\n+     * @param throwOnFail   flag to indicate whether to log or throw exception if a group is not found\n+     */\n+    private void collectGroups(Set<String> groupNames, Set<IEntityGroup> groups, boolean throwOnFail) {\n+        for (String groupName : groupNames) {\n+            IEntityGroup entityGroup = findGroupByName(groupName);\n+            if (entityGroup != null) {\n+                groups.add(entityGroup);\n+            } else {\n+                if (throwOnFail) {\n+                    logger.error(\"Could not find group named {}\", groupName);\n+                    throw new IllegalArgumentException(\"Could not find group named \" + groupName);\n+                } else {\n+                    logger.warn(\"Could not find group named {}\", groupName);\n+                }\n+            }\n+        }\n+    }\n+\n+    /**\n+     * Create a hashcode based on the includes/excludes groups.\n+     *\n+     * @return      hashcode for this instance\n+     */\n+    private String calcHashcode() {\n+        StringBuilder hash = new StringBuilder(\"__\");\n+        for (IEntityGroup group : includes) {\n+            hash.append(group.getKey());\n+        }\n+        hash.append(\"^\");\n+        for (IEntityGroup group : excludes) {\n+            hash.append(group.getKey());\n+        }\n+        hash.append(\"_#\");\n+        return hash.toString();\n+    }\n+\n+    @Override\n+    public boolean test(IPerson person) {\n+        String personHash = person.getEntityIdentifier().getKey() + hashcode + Thread.currentThread().getId();\n+        logger.debug(personHash);\n+        if (currentPersons.contains(personHash))\n+            return false; // stop recursing\n+        currentPersons.add(personHash);\n+\n+        IGroupMember gmPerson = findPersonAsGroupMember(person);\n+        boolean pass = true;\n+\n+        Iterator<IEntityGroup> groups = includes.iterator();\n+        while (pass && groups.hasNext()) {\n+            IEntityGroup group = groups.next();\n+            if (!gmPerson.isDeepMemberOf(group)) {\n+                logger.debug(\"!! {} is not a member of {}\", person.getUserName(), group.getDescription());\n+                pass = false;\n+            } else {\n+                logger.debug(\"{} is a member of {}\", person.getUserName(), group.getDescription());\n+            }\n+        }\n+        groups = excludes.iterator();\n+        while (pass && groups.hasNext()) {\n+            IEntityGroup group = groups.next();\n+            if (gmPerson.isDeepMemberOf(group)) {\n+                logger.debug(\"!! {} is a member of {}\", person.getUserName(), group.getDescription());\n+                pass = false;\n+            } else {\n+                logger.debug(\"{} is a not member of {}\", person.getUserName(), group.getDescription());\n+            }\n+        }\n+\n+        currentPersons.remove(personHash);\n+        return pass;\n+    }\n+\n+    /**\n+     * Find {@link IEntityGroup} from group name.\n+     *\n+     * @param groupName     name of group to search from {@code GroupService}\n+     * @return              {@code IEntityGroup} with given name or null if no group with given name found\n+     * @see                 org.jasig.portal.services.GroupService\n+     */\n+    private IEntityGroup findGroupByName(String groupName) {\n+        EntityIdentifier[] identifiers = GroupService.searchForGroups(groupName, GroupService.IS, EntityEnum.GROUP.getClazz());","path":"uportal-war/src/main/java/org/jasig/portal/groups/pags/testers/AdHocGroupTester.java","position":151,"original_position":151,"commit_id":"7be41295a5f060179ae76ef1a1e9dce9b56d060d","original_commit_id":"7be41295a5f060179ae76ef1a1e9dce9b56d060d","user":{"login":"drewwills","id":1127174,"avatar_url":"https://avatars.githubusercontent.com/u/1127174?v=3","gravatar_id":"","url":"https://api.github.com/users/drewwills","html_url":"https://github.com/drewwills","followers_url":"https://api.github.com/users/drewwills/followers","following_url":"https://api.github.com/users/drewwills/following{/other_user}","gists_url":"https://api.github.com/users/drewwills/gists{/gist_id}","starred_url":"https://api.github.com/users/drewwills/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drewwills/subscriptions","organizations_url":"https://api.github.com/users/drewwills/orgs","repos_url":"https://api.github.com/users/drewwills/repos","events_url":"https://api.github.com/users/drewwills/events{/privacy}","received_events_url":"https://api.github.com/users/drewwills/received_events","type":"User","site_admin":false},"body":"I suspect the 3rd argument should be `IPerson.class` -- or, alternately `EntityEnum.PERSON`\r\n\r\nI'd rather not refer here to something (`EntityEnum`) in a package called `org.jasig.portal.portlets.groupselector` (to me it feels like coloring-out-of-the-lines) but I see a lot of code all over that does that already.  (Perhaps the enum should be moved.)","created_at":"2015-05-11T16:17:16Z","updated_at":"2015-05-11T16:17:16Z","html_url":"https://github.com/Jasig/uPortal/pull/548#discussion_r30054329","pull_request_url":"https://api.github.com/repos/Jasig/uPortal/pulls/548","_links":{"self":{"href":"https://api.github.com/repos/Jasig/uPortal/pulls/comments/30054329"},"html":{"href":"https://github.com/Jasig/uPortal/pull/548#discussion_r30054329"},"pull_request":{"href":"https://api.github.com/repos/Jasig/uPortal/pulls/548"}}},"pull_request":{"url":"https://api.github.com/repos/Jasig/uPortal/pulls/548","id":35051408,"html_url":"https://github.com/Jasig/uPortal/pull/548","diff_url":"https://github.com/Jasig/uPortal/pull/548.diff","patch_url":"https://github.com/Jasig/uPortal/pull/548.patch","issue_url":"https://api.github.com/repos/Jasig/uPortal/issues/548","number":548,"state":"open","locked":false,"title":"Up 4443 adhoc pags groups","user":{"login":"bjagg","id":1264750,"avatar_url":"https://avatars.githubusercontent.com/u/1264750?v=3","gravatar_id":"","url":"https://api.github.com/users/bjagg","html_url":"https://github.com/bjagg","followers_url":"https://api.github.com/users/bjagg/followers","following_url":"https://api.github.com/users/bjagg/following{/other_user}","gists_url":"https://api.github.com/users/bjagg/gists{/gist_id}","starred_url":"https://api.github.com/users/bjagg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjagg/subscriptions","organizations_url":"https://api.github.com/users/bjagg/orgs","repos_url":"https://api.github.com/users/bjagg/repos","events_url":"https://api.github.com/users/bjagg/events{/privacy}","received_events_url":"https://api.github.com/users/bjagg/received_events","type":"User","site_admin":false},"body":"New PAGS Ad hoc group tester with an example group.","created_at":"2015-05-08T22:13:06Z","updated_at":"2015-05-11T16:17:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f518fd31651866baf9393ae309ae8987401acd45","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Jasig/uPortal/pulls/548/commits","review_comments_url":"https://api.github.com/repos/Jasig/uPortal/pulls/548/comments","review_comment_url":"https://api.github.com/repos/Jasig/uPortal/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Jasig/uPortal/issues/548/comments","statuses_url":"https://api.github.com/repos/Jasig/uPortal/statuses/7be41295a5f060179ae76ef1a1e9dce9b56d060d","head":{"label":"bjagg:UP-4443_adhoc-pags-groups","ref":"UP-4443_adhoc-pags-groups","sha":"7be41295a5f060179ae76ef1a1e9dce9b56d060d","user":{"login":"bjagg","id":1264750,"avatar_url":"https://avatars.githubusercontent.com/u/1264750?v=3","gravatar_id":"","url":"https://api.github.com/users/bjagg","html_url":"https://github.com/bjagg","followers_url":"https://api.github.com/users/bjagg/followers","following_url":"https://api.github.com/users/bjagg/following{/other_user}","gists_url":"https://api.github.com/users/bjagg/gists{/gist_id}","starred_url":"https://api.github.com/users/bjagg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjagg/subscriptions","organizations_url":"https://api.github.com/users/bjagg/orgs","repos_url":"https://api.github.com/users/bjagg/repos","events_url":"https://api.github.com/users/bjagg/events{/privacy}","received_events_url":"https://api.github.com/users/bjagg/received_events","type":"User","site_admin":false},"repo":{"id":21404063,"name":"uPortal","full_name":"bjagg/uPortal","owner":{"login":"bjagg","id":1264750,"avatar_url":"https://avatars.githubusercontent.com/u/1264750?v=3","gravatar_id":"","url":"https://api.github.com/users/bjagg","html_url":"https://github.com/bjagg","followers_url":"https://api.github.com/users/bjagg/followers","following_url":"https://api.github.com/users/bjagg/following{/other_user}","gists_url":"https://api.github.com/users/bjagg/gists{/gist_id}","starred_url":"https://api.github.com/users/bjagg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjagg/subscriptions","organizations_url":"https://api.github.com/users/bjagg/orgs","repos_url":"https://api.github.com/users/bjagg/repos","events_url":"https://api.github.com/users/bjagg/events{/privacy}","received_events_url":"https://api.github.com/users/bjagg/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bjagg/uPortal","description":"Enterprise open source portal built by and for the higher education community.","fork":true,"url":"https://api.github.com/repos/bjagg/uPortal","forks_url":"https://api.github.com/repos/bjagg/uPortal/forks","keys_url":"https://api.github.com/repos/bjagg/uPortal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bjagg/uPortal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bjagg/uPortal/teams","hooks_url":"https://api.github.com/repos/bjagg/uPortal/hooks","issue_events_url":"https://api.github.com/repos/bjagg/uPortal/issues/events{/number}","events_url":"https://api.github.com/repos/bjagg/uPortal/events","assignees_url":"https://api.github.com/repos/bjagg/uPortal/assignees{/user}","branches_url":"https://api.github.com/repos/bjagg/uPortal/branches{/branch}","tags_url":"https://api.github.com/repos/bjagg/uPortal/tags","blobs_url":"https://api.github.com/repos/bjagg/uPortal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bjagg/uPortal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bjagg/uPortal/git/refs{/sha}","trees_url":"https://api.github.com/repos/bjagg/uPortal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bjagg/uPortal/statuses/{sha}","languages_url":"https://api.github.com/repos/bjagg/uPortal/languages","stargazers_url":"https://api.github.com/repos/bjagg/uPortal/stargazers","contributors_url":"https://api.github.com/repos/bjagg/uPortal/contributors","subscribers_url":"https://api.github.com/repos/bjagg/uPortal/subscribers","subscription_url":"https://api.github.com/repos/bjagg/uPortal/subscription","commits_url":"https://api.github.com/repos/bjagg/uPortal/commits{/sha}","git_commits_url":"https://api.github.com/repos/bjagg/uPortal/git/commits{/sha}","comments_url":"https://api.github.com/repos/bjagg/uPortal/comments{/number}","issue_comment_url":"https://api.github.com/repos/bjagg/uPortal/issues/comments{/number}","contents_url":"https://api.github.com/repos/bjagg/uPortal/contents/{+path}","compare_url":"https://api.github.com/repos/bjagg/uPortal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bjagg/uPortal/merges","archive_url":"https://api.github.com/repos/bjagg/uPortal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bjagg/uPortal/downloads","issues_url":"https://api.github.com/repos/bjagg/uPortal/issues{/number}","pulls_url":"https://api.github.com/repos/bjagg/uPortal/pulls{/number}","milestones_url":"https://api.github.com/repos/bjagg/uPortal/milestones{/number}","notifications_url":"https://api.github.com/repos/bjagg/uPortal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bjagg/uPortal/labels{/name}","releases_url":"https://api.github.com/repos/bjagg/uPortal/releases{/id}","created_at":"2014-07-01T22:21:15Z","updated_at":"2015-05-08T20:30:33Z","pushed_at":"2015-05-08T22:03:19Z","git_url":"git://github.com/bjagg/uPortal.git","ssh_url":"git@github.com:bjagg/uPortal.git","clone_url":"https://github.com/bjagg/uPortal.git","svn_url":"https://github.com/bjagg/uPortal","homepage":"http://www.jasig.org/uportal","size":145868,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"Jasig:master","ref":"master","sha":"a6cc87d5191623d23ef6069be7fcd28e691397d7","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":2614085,"name":"uPortal","full_name":"Jasig/uPortal","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/uPortal","description":"Enterprise open source portal built by and for the higher education community.","fork":false,"url":"https://api.github.com/repos/Jasig/uPortal","forks_url":"https://api.github.com/repos/Jasig/uPortal/forks","keys_url":"https://api.github.com/repos/Jasig/uPortal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Jasig/uPortal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Jasig/uPortal/teams","hooks_url":"https://api.github.com/repos/Jasig/uPortal/hooks","issue_events_url":"https://api.github.com/repos/Jasig/uPortal/issues/events{/number}","events_url":"https://api.github.com/repos/Jasig/uPortal/events","assignees_url":"https://api.github.com/repos/Jasig/uPortal/assignees{/user}","branches_url":"https://api.github.com/repos/Jasig/uPortal/branches{/branch}","tags_url":"https://api.github.com/repos/Jasig/uPortal/tags","blobs_url":"https://api.github.com/repos/Jasig/uPortal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Jasig/uPortal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Jasig/uPortal/git/refs{/sha}","trees_url":"https://api.github.com/repos/Jasig/uPortal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Jasig/uPortal/statuses/{sha}","languages_url":"https://api.github.com/repos/Jasig/uPortal/languages","stargazers_url":"https://api.github.com/repos/Jasig/uPortal/stargazers","contributors_url":"https://api.github.com/repos/Jasig/uPortal/contributors","subscribers_url":"https://api.github.com/repos/Jasig/uPortal/subscribers","subscription_url":"https://api.github.com/repos/Jasig/uPortal/subscription","commits_url":"https://api.github.com/repos/Jasig/uPortal/commits{/sha}","git_commits_url":"https://api.github.com/repos/Jasig/uPortal/git/commits{/sha}","comments_url":"https://api.github.com/repos/Jasig/uPortal/comments{/number}","issue_comment_url":"https://api.github.com/repos/Jasig/uPortal/issues/comments{/number}","contents_url":"https://api.github.com/repos/Jasig/uPortal/contents/{+path}","compare_url":"https://api.github.com/repos/Jasig/uPortal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Jasig/uPortal/merges","archive_url":"https://api.github.com/repos/Jasig/uPortal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Jasig/uPortal/downloads","issues_url":"https://api.github.com/repos/Jasig/uPortal/issues{/number}","pulls_url":"https://api.github.com/repos/Jasig/uPortal/pulls{/number}","milestones_url":"https://api.github.com/repos/Jasig/uPortal/milestones{/number}","notifications_url":"https://api.github.com/repos/Jasig/uPortal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Jasig/uPortal/labels{/name}","releases_url":"https://api.github.com/repos/Jasig/uPortal/releases{/id}","created_at":"2011-10-20T15:34:22Z","updated_at":"2015-05-07T23:52:00Z","pushed_at":"2015-05-08T22:13:06Z","git_url":"git://github.com/Jasig/uPortal.git","ssh_url":"git@github.com:Jasig/uPortal.git","clone_url":"https://github.com/Jasig/uPortal.git","svn_url":"https://github.com/Jasig/uPortal","homepage":"http://www.jasig.org/uportal","size":222850,"stargazers_count":97,"watchers_count":97,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":144,"mirror_url":null,"open_issues_count":14,"forks":144,"open_issues":14,"watchers":97,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Jasig/uPortal/pulls/548"},"html":{"href":"https://github.com/Jasig/uPortal/pull/548"},"issue":{"href":"https://api.github.com/repos/Jasig/uPortal/issues/548"},"comments":{"href":"https://api.github.com/repos/Jasig/uPortal/issues/548/comments"},"review_comments":{"href":"https://api.github.com/repos/Jasig/uPortal/pulls/548/comments"},"review_comment":{"href":"https://api.github.com/repos/Jasig/uPortal/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Jasig/uPortal/pulls/548/commits"},"statuses":{"href":"https://api.github.com/repos/Jasig/uPortal/statuses/7be41295a5f060179ae76ef1a1e9dce9b56d060d"}}}}