{"action":"created","comment":{"url":"https://api.github.com/repos/zalando/planb-revocation/pulls/comments/59049515","id":59049515,"diff_hunk":"@@ -0,0 +1,112 @@\n+package org.zalando.planb.revocation.persistence;\n+\n+import com.datastax.driver.core.BoundStatement;\n+import com.datastax.driver.core.ConsistencyLevel;\n+import com.datastax.driver.core.PreparedStatement;\n+import com.datastax.driver.core.RegularStatement;\n+import com.datastax.driver.core.ResultSet;\n+import com.datastax.driver.core.Row;\n+import com.datastax.driver.core.Session;\n+import com.datastax.driver.core.querybuilder.QueryBuilder;\n+import lombok.extern.slf4j.Slf4j;\n+import org.springframework.scheduling.annotation.Scheduled;\n+import org.zalando.planb.revocation.domain.AuthorizationRule;\n+import org.zalando.planb.revocation.domain.ImmutableAuthorizationRule;\n+\n+import javax.annotation.PostConstruct;\n+import java.util.Collection;\n+import java.util.Collections;\n+import java.util.List;\n+import java.util.Optional;\n+import java.util.stream.Collectors;\n+\n+import static com.datastax.driver.core.querybuilder.QueryBuilder.bindMarker;\n+import static com.datastax.driver.core.querybuilder.QueryBuilder.now;\n+\n+@Slf4j\n+public class CassandraAuthorizationRuleStore implements AuthorizationRulesStore.Internal {\n+\n+    private static final long RELOAD_IN_MS =  1000 * 60 * 10; // 10 minutes\n+\n+    private List<AuthorizationRule> inMemoryRuleStore = Collections.emptyList();\n+\n+    private final Session session;\n+\n+    private final PreparedStatement getRules;\n+\n+    private final PreparedStatement insertRule;\n+\n+    private static final String AUTHORIZATION_TABLE = \"authorization_rule\";\n+    private static final String REQUIRED_USER_CLAIMS = \"required_user_claims\";\n+    private static final String ALLOWED_REVOCATION_CLAIMS = \"allowed_revocation_claims\";\n+    private static final String CREATED_BY = \"created_by\";\n+    private static final String LAST_MODIFIED_BY = \"last_modified_by\";\n+    private static final String UUID = \"uuid\";\n+\n+    private static final RegularStatement INSERT_AUTHORIZATION = QueryBuilder.insertInto(AUTHORIZATION_TABLE)\n+            .value(UUID, now())\n+            .value(REQUIRED_USER_CLAIMS, bindMarker())\n+            .value(ALLOWED_REVOCATION_CLAIMS, bindMarker())\n+            .value(CREATED_BY, bindMarker())\n+            .value(LAST_MODIFIED_BY, bindMarker());\n+    private static final RegularStatement SELECT_AUTHORIZATION = QueryBuilder.select()\n+            .column(REQUIRED_USER_CLAIMS)\n+            .column(ALLOWED_REVOCATION_CLAIMS)\n+            .from(AUTHORIZATION_TABLE);\n+    private static final RegularStatement CLEANUP_AUTHORIZATION = QueryBuilder.truncate(AUTHORIZATION_TABLE);\n+\n+    public CassandraAuthorizationRuleStore(final Session session, final ConsistencyLevel read, final ConsistencyLevel write) {\n+        this.session = session;\n+        getRules = session.prepare(SELECT_AUTHORIZATION).setConsistencyLevel(read);\n+        insertRule = session.prepare(INSERT_AUTHORIZATION).setConsistencyLevel(write);\n+    }\n+\n+    @PostConstruct\n+    void initializeAuthorizationRuleStore() throws Exception {","path":"src/main/java/org/zalando/planb/revocation/persistence/CassandraAuthorizationRuleStore.java","position":65,"original_position":65,"commit_id":"01b1b31c0e633f34bab3faccd5cf1e650ddcbc75","original_commit_id":"01b1b31c0e633f34bab3faccd5cf1e650ddcbc75","user":{"login":"gargravarr","id":1788611,"avatar_url":"https://avatars.githubusercontent.com/u/1788611?v=3","gravatar_id":"","url":"https://api.github.com/users/gargravarr","html_url":"https://github.com/gargravarr","followers_url":"https://api.github.com/users/gargravarr/followers","following_url":"https://api.github.com/users/gargravarr/following{/other_user}","gists_url":"https://api.github.com/users/gargravarr/gists{/gist_id}","starred_url":"https://api.github.com/users/gargravarr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gargravarr/subscriptions","organizations_url":"https://api.github.com/users/gargravarr/orgs","repos_url":"https://api.github.com/users/gargravarr/repos","events_url":"https://api.github.com/users/gargravarr/events{/privacy}","received_events_url":"https://api.github.com/users/gargravarr/received_events","type":"User","site_admin":false},"body":"private","created_at":"2016-04-08T16:13:02Z","updated_at":"2016-04-08T16:13:02Z","html_url":"https://github.com/zalando/planb-revocation/pull/94#discussion_r59049515","pull_request_url":"https://api.github.com/repos/zalando/planb-revocation/pulls/94","_links":{"self":{"href":"https://api.github.com/repos/zalando/planb-revocation/pulls/comments/59049515"},"html":{"href":"https://github.com/zalando/planb-revocation/pull/94#discussion_r59049515"},"pull_request":{"href":"https://api.github.com/repos/zalando/planb-revocation/pulls/94"}}},"pull_request":{"url":"https://api.github.com/repos/zalando/planb-revocation/pulls/94","id":65793841,"html_url":"https://github.com/zalando/planb-revocation/pull/94","diff_url":"https://github.com/zalando/planb-revocation/pull/94.diff","patch_url":"https://github.com/zalando/planb-revocation/pull/94.patch","issue_url":"https://api.github.com/repos/zalando/planb-revocation/issues/94","number":94,"state":"open","locked":false,"title":"Feature/82 store authorization rules","user":{"login":"vroldanbet","id":6774726,"avatar_url":"https://avatars.githubusercontent.com/u/6774726?v=3","gravatar_id":"","url":"https://api.github.com/users/vroldanbet","html_url":"https://github.com/vroldanbet","followers_url":"https://api.github.com/users/vroldanbet/followers","following_url":"https://api.github.com/users/vroldanbet/following{/other_user}","gists_url":"https://api.github.com/users/vroldanbet/gists{/gist_id}","starred_url":"https://api.github.com/users/vroldanbet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vroldanbet/subscriptions","organizations_url":"https://api.github.com/users/vroldanbet/orgs","repos_url":"https://api.github.com/users/vroldanbet/repos","events_url":"https://api.github.com/users/vroldanbet/events{/privacy}","received_events_url":"https://api.github.com/users/vroldanbet/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-08T14:24:37Z","updated_at":"2016-04-08T16:13:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5339ca6e560c3488286726e8247286234517a0d3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/zalando/planb-revocation/pulls/94/commits","review_comments_url":"https://api.github.com/repos/zalando/planb-revocation/pulls/94/comments","review_comment_url":"https://api.github.com/repos/zalando/planb-revocation/pulls/comments{/number}","comments_url":"https://api.github.com/repos/zalando/planb-revocation/issues/94/comments","statuses_url":"https://api.github.com/repos/zalando/planb-revocation/statuses/01b1b31c0e633f34bab3faccd5cf1e650ddcbc75","head":{"label":"zalando:feature/82-store-authorization-rules","ref":"feature/82-store-authorization-rules","sha":"01b1b31c0e633f34bab3faccd5cf1e650ddcbc75","user":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"repo":{"id":51506601,"name":"planb-revocation","full_name":"zalando/planb-revocation","owner":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando/planb-revocation","description":"Plan B Revocation Service for JWT tokens","fork":false,"url":"https://api.github.com/repos/zalando/planb-revocation","forks_url":"https://api.github.com/repos/zalando/planb-revocation/forks","keys_url":"https://api.github.com/repos/zalando/planb-revocation/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando/planb-revocation/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando/planb-revocation/teams","hooks_url":"https://api.github.com/repos/zalando/planb-revocation/hooks","issue_events_url":"https://api.github.com/repos/zalando/planb-revocation/issues/events{/number}","events_url":"https://api.github.com/repos/zalando/planb-revocation/events","assignees_url":"https://api.github.com/repos/zalando/planb-revocation/assignees{/user}","branches_url":"https://api.github.com/repos/zalando/planb-revocation/branches{/branch}","tags_url":"https://api.github.com/repos/zalando/planb-revocation/tags","blobs_url":"https://api.github.com/repos/zalando/planb-revocation/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando/planb-revocation/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando/planb-revocation/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando/planb-revocation/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando/planb-revocation/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando/planb-revocation/languages","stargazers_url":"https://api.github.com/repos/zalando/planb-revocation/stargazers","contributors_url":"https://api.github.com/repos/zalando/planb-revocation/contributors","subscribers_url":"https://api.github.com/repos/zalando/planb-revocation/subscribers","subscription_url":"https://api.github.com/repos/zalando/planb-revocation/subscription","commits_url":"https://api.github.com/repos/zalando/planb-revocation/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando/planb-revocation/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando/planb-revocation/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando/planb-revocation/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando/planb-revocation/contents/{+path}","compare_url":"https://api.github.com/repos/zalando/planb-revocation/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando/planb-revocation/merges","archive_url":"https://api.github.com/repos/zalando/planb-revocation/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando/planb-revocation/downloads","issues_url":"https://api.github.com/repos/zalando/planb-revocation/issues{/number}","pulls_url":"https://api.github.com/repos/zalando/planb-revocation/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando/planb-revocation/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando/planb-revocation/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando/planb-revocation/labels{/name}","releases_url":"https://api.github.com/repos/zalando/planb-revocation/releases{/id}","deployments_url":"https://api.github.com/repos/zalando/planb-revocation/deployments","created_at":"2016-02-11T10:03:34Z","updated_at":"2016-04-07T19:09:31Z","pushed_at":"2016-04-08T16:01:56Z","git_url":"git://github.com/zalando/planb-revocation.git","ssh_url":"git@github.com:zalando/planb-revocation.git","clone_url":"https://github.com/zalando/planb-revocation.git","svn_url":"https://github.com/zalando/planb-revocation","homepage":"http://planb.readthedocs.org/","size":432,"stargazers_count":3,"watchers_count":3,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":3,"default_branch":"master"}},"base":{"label":"zalando:master","ref":"master","sha":"1252ae90668e7b6486b0b3f8e324a0f383c3ec5f","user":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"repo":{"id":51506601,"name":"planb-revocation","full_name":"zalando/planb-revocation","owner":{"login":"zalando","id":1564818,"avatar_url":"https://avatars.githubusercontent.com/u/1564818?v=3","gravatar_id":"","url":"https://api.github.com/users/zalando","html_url":"https://github.com/zalando","followers_url":"https://api.github.com/users/zalando/followers","following_url":"https://api.github.com/users/zalando/following{/other_user}","gists_url":"https://api.github.com/users/zalando/gists{/gist_id}","starred_url":"https://api.github.com/users/zalando/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zalando/subscriptions","organizations_url":"https://api.github.com/users/zalando/orgs","repos_url":"https://api.github.com/users/zalando/repos","events_url":"https://api.github.com/users/zalando/events{/privacy}","received_events_url":"https://api.github.com/users/zalando/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zalando/planb-revocation","description":"Plan B Revocation Service for JWT tokens","fork":false,"url":"https://api.github.com/repos/zalando/planb-revocation","forks_url":"https://api.github.com/repos/zalando/planb-revocation/forks","keys_url":"https://api.github.com/repos/zalando/planb-revocation/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zalando/planb-revocation/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zalando/planb-revocation/teams","hooks_url":"https://api.github.com/repos/zalando/planb-revocation/hooks","issue_events_url":"https://api.github.com/repos/zalando/planb-revocation/issues/events{/number}","events_url":"https://api.github.com/repos/zalando/planb-revocation/events","assignees_url":"https://api.github.com/repos/zalando/planb-revocation/assignees{/user}","branches_url":"https://api.github.com/repos/zalando/planb-revocation/branches{/branch}","tags_url":"https://api.github.com/repos/zalando/planb-revocation/tags","blobs_url":"https://api.github.com/repos/zalando/planb-revocation/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zalando/planb-revocation/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zalando/planb-revocation/git/refs{/sha}","trees_url":"https://api.github.com/repos/zalando/planb-revocation/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zalando/planb-revocation/statuses/{sha}","languages_url":"https://api.github.com/repos/zalando/planb-revocation/languages","stargazers_url":"https://api.github.com/repos/zalando/planb-revocation/stargazers","contributors_url":"https://api.github.com/repos/zalando/planb-revocation/contributors","subscribers_url":"https://api.github.com/repos/zalando/planb-revocation/subscribers","subscription_url":"https://api.github.com/repos/zalando/planb-revocation/subscription","commits_url":"https://api.github.com/repos/zalando/planb-revocation/commits{/sha}","git_commits_url":"https://api.github.com/repos/zalando/planb-revocation/git/commits{/sha}","comments_url":"https://api.github.com/repos/zalando/planb-revocation/comments{/number}","issue_comment_url":"https://api.github.com/repos/zalando/planb-revocation/issues/comments{/number}","contents_url":"https://api.github.com/repos/zalando/planb-revocation/contents/{+path}","compare_url":"https://api.github.com/repos/zalando/planb-revocation/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zalando/planb-revocation/merges","archive_url":"https://api.github.com/repos/zalando/planb-revocation/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zalando/planb-revocation/downloads","issues_url":"https://api.github.com/repos/zalando/planb-revocation/issues{/number}","pulls_url":"https://api.github.com/repos/zalando/planb-revocation/pulls{/number}","milestones_url":"https://api.github.com/repos/zalando/planb-revocation/milestones{/number}","notifications_url":"https://api.github.com/repos/zalando/planb-revocation/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zalando/planb-revocation/labels{/name}","releases_url":"https://api.github.com/repos/zalando/planb-revocation/releases{/id}","deployments_url":"https://api.github.com/repos/zalando/planb-revocation/deployments","created_at":"2016-02-11T10:03:34Z","updated_at":"2016-04-07T19:09:31Z","pushed_at":"2016-04-08T16:01:56Z","git_url":"git://github.com/zalando/planb-revocation.git","ssh_url":"git@github.com:zalando/planb-revocation.git","clone_url":"https://github.com/zalando/planb-revocation.git","svn_url":"https://github.com/zalando/planb-revocation","homepage":"http://planb.readthedocs.org/","size":432,"stargazers_count":3,"watchers_count":3,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zalando/planb-revocation/pulls/94"},"html":{"href":"https://github.com/zalando/planb-revocation/pull/94"},"issue":{"href":"https://api.github.com/repos/zalando/planb-revocation/issues/94"},"comments":{"href":"https://api.github.com/repos/zalando/planb-revocation/issues/94/comments"},"review_comments":{"href":"https://api.github.com/repos/zalando/planb-revocation/pulls/94/comments"},"review_comment":{"href":"https://api.github.com/repos/zalando/planb-revocation/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/zalando/planb-revocation/pulls/94/commits"},"statuses":{"href":"https://api.github.com/repos/zalando/planb-revocation/statuses/01b1b31c0e633f34bab3faccd5cf1e650ddcbc75"}}}}