{"id":15024559,"url":"https://github.com/jcasbin/casbin-spring-boot-starter","last_synced_at":"2025-04-09T05:13:19.811Z","repository":{"id":37978296,"uuid":"179850583","full_name":"jcasbin/casbin-spring-boot-starter","owner":"jcasbin","description":"Spring Boot 2.x \u0026 3.x Starter for Casbin, see example at: https://github.com/jcasbin/casbin-spring-boot-example","archived":false,"fork":false,"pushed_at":"2024-10-01T02:19:51.000Z","size":272,"stargazers_count":210,"open_issues_count":0,"forks_count":71,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-01T12:05:58.388Z","etag":null,"topics":["abac","acl","auth","authorization","authz","casbin","java","jcasbin","rbac","spring","spring-boot","spring-boot-2","spring-boot-3","springboot","springbootstarter"],"latest_commit_sha":null,"homepage":"https://mvnrepository.com/artifact/org.casbin/casbin-spring-boot-starter","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-06T15:27:18.000Z","updated_at":"2025-03-24T11:46:44.000Z","dependencies_parsed_at":"2024-08-01T10:59:16.578Z","dependency_job_id":"cde47175-d0a5-4e8d-9ee1-16d5e2de3c4b","html_url":"https://github.com/jcasbin/casbin-spring-boot-starter","commit_stats":null,"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fcasbin-spring-boot-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fcasbin-spring-boot-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fcasbin-spring-boot-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcasbin%2Fcasbin-spring-boot-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcasbin","download_url":"https://codeload.github.com/jcasbin/casbin-spring-boot-starter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980843,"owners_count":21027808,"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":["abac","acl","auth","authorization","authz","casbin","java","jcasbin","rbac","spring","spring-boot","spring-boot-2","spring-boot-3","springboot","springbootstarter"],"created_at":"2024-09-24T20:00:32.693Z","updated_at":"2025-04-09T05:13:19.793Z","avatar_url":"https://github.com/jcasbin.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Casbin Spring Boot Starter\n\n[![Codecov branch](https://img.shields.io/codecov/c/github/jcasbin/casbin-spring-boot-starter/master.svg?logo=codecov\u0026style=flat-square)](https://codecov.io/gh/jcasbin/casbin-spring-boot-starter)\n[![GitHub Actions](https://github.com/jcasbin/casbin-spring-boot-starter/workflows/build/badge.svg)](https://github.com/jcasbin/casbin-spring-boot-starter/actions)\n[![Maven Central](https://img.shields.io/maven-central/v/org.casbin/casbin-spring-boot-starter.svg?style=flat-square\u0026color=brightgreen)](https://mvnrepository.com/artifact/org.casbin/casbin-spring-boot-starter/latest)\n[![License](https://img.shields.io/github/license/jcasbin/casbin-spring-boot-starter.svg?style=flat-square\u0026color=blue)](http://www.apache.org/licenses/LICENSE-2.0.txt)\n[![SpringBootVersion](https://img.shields.io/badge/SpringBoot-2.7.12-heightgreen.svg?style=flat-square)](https://spring.io/projects/spring-boot)\n[![CasbinVersion](https://img.shields.io/badge/jCasbin-1.55.0-heightgreen.svg?style=flat-square)](https://casbin.org)\n\n[![](https://raw.githubusercontent.com/casbin/jcasbin/master/casbin-logo.png)](https://casbin.org)\n\nCasbin Spring Boot Starter is designed to help you easily integrate [jCasbin](https://github.com/casbin/jcasbin) into\nyour Spring Boot project.\n\n## how to use\n\n1. Add ```casbin-spring-boot-starter``` to the Spring Boot project.\n\n```Maven```\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.casbin\u003c/groupId\u003e\n    \u003cartifactId\u003ecasbin-spring-boot-starter\u003c/artifactId\u003e\n    \u003cversion\u003eversion\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n```Gradle```\n\n```groovy\nimplementation 'org.casbin:casbin-spring-boot-starter:version'\n```\n\n2. Inject the Enforcer where you need to use it\n\n```java\n\n@Component\npublic class Test {\n    @Autowired\n    private Enforcer enforcer;\n}\n```\n\n3. Add configuration\n\n```yaml\ncasbin:\n  #Whether to enable Casbin, it is enabled by default.\n  enableCasbin: true\n  #Whether to use thread-synchronized Enforcer, default false\n  useSyncedEnforcer: false\n  #Whether to use distributed Enforcer, default false.\n  #If both useSyncedEnforcer and useDistributedEnforcer are set to true, useDistributedEnforcer will take effect.\n  useDistributedEnforcer: false\n  #Whether to enable automatic policy saving, if the adapter supports this function, it is enabled by default.\n  autoSave: true\n  #Storage type [file, jdbc], currently supported jdbc database [mysql (mariadb), h2, oracle, postgresql, db2]\n  #Welcome to write and submit the jdbc adapter you are using, see: org.casbin.adapter.OracleAdapter\n  #The jdbc adapter will actively look for the data source information you configured in spring.datasource\n  #Default use jdbc, and use the built-in h2 database for memory storage\n  storeType: jdbc\n  #Customized policy table name when use jdbc, casbin_rule as default.\n  tableName: casbin_rule\n  #Data source initialization policy [create (automatically create data table, no longer initialized if created), never (always do not initialize)]\n  initializeSchema: create\n  #Local model configuration file address, the default reading location: classpath: casbin/model.conf\n  model: classpath:casbin/model.conf\n  #If the model configuration file is not found in the default location and casbin.model is not set correctly, the built-in default rbac model is used, which takes effect by default.\n  useDefaultModelIfModelNotSetting: true\n  #Local policy configuration file address, the default reading location: classpath: casbin/policy.csv\n  #If the configuration file is not found in the default location, an exception will be thrown.\n  #This configuration item takes effect only when casbin.storeType is set to file.\n  policy: classpath:casbin/policy.csv\n  #Whether to enable the CasbinWatcher mechanism, the default is not enabled.\n  #If the mechanism is enabled, casbin.storeType must be jdbc, otherwise the configuration is invalid.\n  enableWatcher: false\n  #CasbinWatcher notification mode, defaults to use Redis for notification synchronization, temporarily only supports Redis\n  #After opening Watcher, you need to manually add spring-boot-starter-data-redis dependency.\n  watcherType: redis\n  #Watcher to support spring tx, the default is not enable.\n  #If the mechanism is enabled, When updating policy in a spring transaction, watcher will trigger the update after commit\n  watcherTxSupport: false\n  exception:\n    ... See Schedule A for exception settings.\n```\n\n4. The simplest configuration\n\n- Do not use other add-on configurations\n\n```yaml\ncasbin:\n  #If you are using a model profile at this address, no configuration is required\n  model: classpath:casbin/model.conf\n```\n\n- Turn on Watcher\n\n```yaml\ncasbin:\n  #If the model profile you are using is located at this address, you do not need this configuration\n  model: classpath:casbin/model.conf\n  #When you open Watcher, the default use of RedisWatcher requires manual addition of spring-boot-starter-data-redis dependency.\n  enableWatcher: true\n```\n\n5. Use custom independent data sources\n\n- Only increase ```@CasbinDataSource``` annotation when injecting custom data source\n\n```java\n\n@Configuration\npublic class CasbinDataSourceConfiguration {\n    @Bean\n    @CasbinDataSource\n    public DataSource casbinDataSource() {\n        return DataSourceBuilder.create().url(\"jdbc:h2:mem:casbin\").build();\n    }\n}\n```\n\n##### Schedule A\n\n- ExceptionSettings(casbin.exception)\n\n| name               | description                                      | default |\n|--------------------|--------------------------------------------------|---------|\n| removePolicyFailed | Throws an exception when the delete policy fails | false   |\n\n##### Note: If you do not set another data source, or set the storage file location for H2, the data is stored in memory by default using H2.\n\n#### Notice:\n\nSince version 0.0.11, casbin-spring-boot-starter adds an id field to the database table structure by default.\n\nThe version before 0.0.11 is upgraded to version 0.0.11 and later requires the user to manually add the id field.\n\nSee https://github.com/jcasbin/casbin-spring-boot-starter/issues/21 for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcasbin%2Fcasbin-spring-boot-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcasbin%2Fcasbin-spring-boot-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcasbin%2Fcasbin-spring-boot-starter/lists"}