diff --git a/src/main/java/org/casbin/spring/boot/autoconfigure/CasbinAutoConfiguration.java b/src/main/java/org/casbin/spring/boot/autoconfigure/CasbinAutoConfiguration.java index c621c5e..41a292d 100644 --- a/src/main/java/org/casbin/spring/boot/autoconfigure/CasbinAutoConfiguration.java +++ b/src/main/java/org/casbin/spring/boot/autoconfigure/CasbinAutoConfiguration.java @@ -47,7 +47,7 @@ @Configuration @EnableConfigurationProperties({CasbinProperties.class, CasbinExceptionProperties.class, DataSourceProperties.class}) @AutoConfigureAfter({JdbcTemplateAutoConfiguration.class}) -@ConditionalOnExpression("${casbin.enableCasbin:true}") +@ConditionalOnExpression("${casbin.enable-casbin:true}") public class CasbinAutoConfiguration { private static final Logger logger = LoggerFactory.getLogger(CasbinAutoConfiguration.class); @@ -56,7 +56,7 @@ public class CasbinAutoConfiguration { * Automatic configuration file storage adapter */ @Bean - @ConditionalOnProperty(name = "casbin.storeType", havingValue = "file") + @ConditionalOnProperty(name = "casbin.store-type", havingValue = "file") @ConditionalOnMissingBean public Adapter autoConfigFileAdapter(CasbinProperties properties) { // if the file storage is chosen and the policy file location is set correctly, then create a file adapter @@ -73,7 +73,7 @@ public Adapter autoConfigFileAdapter(CasbinProperties properties) { * Automatic configuration of JDBC adapter */ @Bean - @ConditionalOnProperty(name = "casbin.storeType", havingValue = "jdbc", matchIfMissing = true) + @ConditionalOnProperty(name = "casbin.store-type", havingValue = "jdbc", matchIfMissing = true) @ConditionalOnBean(JdbcTemplate.class) @ConditionalOnMissingBean public Adapter autoConfigJdbcAdapter( diff --git a/src/main/java/org/casbin/spring/boot/autoconfigure/CasbinRedisWatcherAutoConfiguration.java b/src/main/java/org/casbin/spring/boot/autoconfigure/CasbinRedisWatcherAutoConfiguration.java index 5723917..e4f8dd3 100644 --- a/src/main/java/org/casbin/spring/boot/autoconfigure/CasbinRedisWatcherAutoConfiguration.java +++ b/src/main/java/org/casbin/spring/boot/autoconfigure/CasbinRedisWatcherAutoConfiguration.java @@ -29,7 +29,7 @@ @Configuration @EnableConfigurationProperties({CasbinProperties.class, RedisProperties.class}) @AutoConfigureAfter({RedisAutoConfiguration.class, CasbinAutoConfiguration.class}) -@ConditionalOnExpression("'jdbc'.equalsIgnoreCase('${casbin.storeType:jdbc}') && ${casbin.enableWatcher:false} && 'redis'.equalsIgnoreCase('${casbin.watcherType:redis}') ") +@ConditionalOnExpression("'jdbc'.equalsIgnoreCase('${casbin.store-type:jdbc}') && ${casbin.enable-watcher:false} && 'redis'.equalsIgnoreCase('${casbin.watcher-type:redis}') ") public class CasbinRedisWatcherAutoConfiguration { private final static Logger logger = LoggerFactory.getLogger(CasbinRedisWatcherAutoConfiguration.class); @@ -37,11 +37,12 @@ public class CasbinRedisWatcherAutoConfiguration { @Bean @ConditionalOnBean(RedisTemplate.class) @ConditionalOnMissingBean - public Watcher redisWatcher(RedisProperties redisProperties, Enforcer enforcer) { + public Watcher redisWatcher(RedisProperties redisProperties, CasbinProperties casbinProperties, Enforcer enforcer) { int timeout = redisProperties.getTimeout() != null ? (int) redisProperties.getTimeout().toMillis() : 2000; - RedisWatcher watcher = new RedisWatcher(redisProperties.getHost(), redisProperties.getPort(), redisProperties.getClientName(), timeout, redisProperties.getPassword()); + RedisWatcher watcher = new RedisWatcher(redisProperties.getHost(), redisProperties.getPort(), + casbinProperties.getPolicyTopic(), timeout, redisProperties.getPassword()); enforcer.setWatcher(watcher); logger.info("Casbin set watcher: {}", watcher.getClass().getName()); return watcher; } -} +} \ No newline at end of file diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 71aa4ec..1d40100 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -1,34 +1,34 @@ casbin: # Whether to turn on Casbin, it is turned on by default - enableCasbin: true + enable-casbin: true # Whether to enable automatic saving of the policy, if the adapter supports this function, it is enabled by default - autoSave: true + auto-save: true # Storage type [file,jdbc], currently supported jdbc database [mysql(mariadb),h2,oracle,postgresql] # Welcome to write and submit the jdbc adapter you are using, see: org.casbin.adapter.OracleAdapter # The jdbc adapter will actively look for the data source information you configured in spring.datasource # Use jdbc by default, and use the built-in h2 database for memory storage - storeType: jdbc + store-type: jdbc # Data source initialization strategy [create (automatically create a data table, if it has been created, # then no longer initialize), never (always do not initialize)] - initializeSchema: create + initialize-schema: create # Local model configuration file address, agreed by default read location: classpath:casbin/model.conf model: classpath:casbin/model.conf # 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 - useDefaultModelIfModelNotSetting: true + use-default-model-if-model-not-setting: true # Local policy configuration file address, agreed by default read location: classpath:casbin/policy.csv # If the configuration file is not found in the default location, an exception will be thrown # This configuration item only takes effect when storeType is set to file policy: classpath:casbin/policy.csv # Whether to turn on the CasbinWatcher mechanism, it is not turned on by default # If the mechanism is turned on, the storeType must be jdbc, otherwise the configuration is invalid - enableWatcher: true + enable-watcher: true # CasbinWatcher notification method, Redis is used by default for notification synchronization, # and only Redis is supported for the time being # After opening Watcher, you need to manually add spring-boot-starter-data-redis dependency - watcherType: redis + watcher-type: redis # Add your Customer Topic here or it will go with 'CASBIN_POLICY_TOPIC' by default - policyTopic: YOUR_CUSTOMER_TOPIC + policy-topic: 'YOUR_CUSTOMER_TOPIC' spring: # Although the data source is configured here, the custom data source is switched to H2 when the unit test is tested.