{"id":21252631,"url":"https://github.com/jcasbin/kafka-casbin","last_synced_at":"2025-04-14T03:52:43.770Z","repository":{"id":45538686,"uuid":"420668862","full_name":"jcasbin/kafka-casbin","owner":"jcasbin","description":"Kafka authorization plugin based on Casbin","archived":false,"fork":false,"pushed_at":"2024-10-05T00:23:21.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T17:51:57.514Z","etag":null,"topics":["auth","authorization","authz","casbin","kafka","rbac"],"latest_commit_sha":null,"homepage":"https://github.com/casbin/jcasbin","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jcasbin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-24T11:47:17.000Z","updated_at":"2024-10-05T00:22:22.000Z","dependencies_parsed_at":"2022-09-06T04:50:58.085Z","dependency_job_id":null,"html_url":"https://github.com/jcasbin/kafka-casbin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fkafka-casbin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fkafka-casbin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fkafka-casbin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fkafka-casbin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcasbin","download_url":"https://codeload.github.com/jcasbin/kafka-casbin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248819359,"owners_count":21166474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth","authorization","authz","casbin","kafka","rbac"],"created_at":"2024-11-21T03:48:16.405Z","updated_at":"2025-04-14T03:52:43.748Z","avatar_url":"https://github.com/jcasbin.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kafka-casbin\n![License](https://img.shields.io/github/license/jcasbin/kafka-casbin)\n[![Maven Central](https://img.shields.io/maven-central/v/org.casbin/kafka-casbin.svg)](https://central.sonatype.com/artifact/org.casbin/kafka-casbin)\n\n[Kafka](https://kafka.apache.org) authorization plugin based on Casbin.\n\n## Installation\n\n``` xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.casbin\u003c/groupId\u003e\n    \u003cartifactId\u003ekafka-casbin\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n## Simple Example\n\n```java\npublic class Main {\n\n    public static void main(String[] args) throws InstantiationException, IllegalAccessException {\n        // create the CasbinAuthorizer object.\n        CasbinAuthorizer authorizer = new CasbinAuthorizer();\n        Map\u003cString, String\u003e configs = new HashMap\u003c\u003e();\n        configs.put(\"casbin.authorizer.model\", \"examples/acl_model.conf\");\n        configs.put(\"casbin.authorizer.policy\", \"examples/acl_policy.csv\");\n        // Set the configs for the authorizer.\n        authorizer.configure(configs);\n\n        // You should create the real serverInfo object\n        AuthorizerServerInfo serverInfo = mock(AuthorizerServerInfo.class);\n        when(serverInfo.endpoints()).thenReturn(new ArrayList\u003c\u003e());\n        authorizer.start(serverInfo);\n\n        // create ResourcePattern\n        ResourcePattern TOPIC_RESOURCE = new ResourcePattern(\n                org.apache.kafka.common.resource.ResourceType.TOPIC,\n                \"target_topic\",\n                PatternType.LITERAL\n        );\n        Action action = new Action(AclOperation.READ, TOPIC_RESOURCE, 0, true, true);\n\n        // Check the permission.\n        List\u003cAuthorizationResult\u003e results =\n                authorizer.authorize(requestContext(\"User\", \"alice\"),\n                        Arrays.asList(action));\n\n        for (AuthorizationResult result : results) {\n           if (result == AuthorizationResult.ALLOWED) {\n               System.out.println(\"有权限\");\n           } else {\n               System.out.println(\"无权限\");\n           }\n        }\n\n    }\n\n    private static AuthorizableRequestContext requestContext(String principalType, String name) {\n        return new RequestContext(\n                new RequestHeader(ApiKeys.METADATA, (short) 0, \"test-client-id\", 123),\n                \"test-connection-id\",\n                InetAddress.getLoopbackAddress(),\n                new KafkaPrincipal(principalType, name),\n                new ListenerName(\"PLAINTEXT\"),\n                SecurityProtocol.PLAINTEXT,\n                ClientInformation.EMPTY,\n                false\n        );\n    }\n}\n```\n\n## Getting Help\n\n- [jCasbin](https://github.com/casbin/jCasbin)\n- [kafka-client](https://github.com/apache/kafka)\n\n## License\n\nThis project is under Apache 2.0 License. See the [LICENSE](https://github.com/jcasbin/kafka-casbin/blob/master/LICENSE) file for the full license text.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcasbin%2Fkafka-casbin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcasbin%2Fkafka-casbin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcasbin%2Fkafka-casbin/lists"}