Giter Site home page Giter Site logo

jcasbin / casbin-spring-boot-starter Goto Github PK

View Code? Open in Web Editor NEW
181.0 5.0 69.0 255 KB

Spring Boot 2.x & 3.x Starter for Casbin, see example at: https://github.com/jcasbin/casbin-spring-boot-example

Home Page: https://mvnrepository.com/artifact/org.casbin/casbin-spring-boot-starter

License: Apache License 2.0

Java 100.00%
casbin spring springboot springbootstarter jcasbin spring-boot abac acl auth authorization

casbin-spring-boot-starter's Introduction

Casbin Spring Boot Starter

Codecov branch GitHub Actions Maven Central License SpringBootVersion JCasbinVersion

Casbin Spring Boot Starter is designed to help you easily integrate jCasbin into your Spring Boot project.

how to use

  1. Add casbin-spring-boot-starter to the Spring Boot project.

Maven

<dependency>
    <groupId>org.casbin</groupId>
    <artifactId>casbin-spring-boot-starter</artifactId>
    <version>version</version>
</dependency>

Gradle

implementation 'org.casbin:casbin-spring-boot-starter:version'
  1. Inject the Enforcer where you need to use it
@Component
public class Test {
    @Autowired
    private Enforcer enforcer;
}
  1. Add configuration
casbin:
  #Whether to enable Casbin, it is enabled by default.
  enableCasbin: true
  #Whether to use thread-synchronized Enforcer, default false
  useSyncedEnforcer: false
  #Whether to enable automatic policy saving, if the adapter supports this function, it is enabled by default.
  autoSave: true
  #Storage type [file, jdbc], currently supported jdbc database [mysql (mariadb), h2, oracle, postgresql, db2]
  #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
  #Default use jdbc, and use the built-in h2 database for memory storage
  storeType: jdbc
  #Customized policy table name when use jdbc, casbin_rule as default.
  tableName: casbin_rule
  #Data source initialization policy [create (automatically create data table, no longer initialized if created), never (always do not initialize)]
  initializeSchema: create
  #Local model configuration file address, the default reading 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
  #Local policy configuration file address, the default reading location: classpath: casbin/policy.csv
  #If the configuration file is not found in the default location, an exception will be thrown.
  #This configuration item takes effect only when casbin.storeType is set to file.
  policy: classpath:casbin/policy.csv
  #Whether to enable the CasbinWatcher mechanism, the default is not enabled.
  #If the mechanism is enabled, casbin.storeType must be jdbc, otherwise the configuration is invalid.
  enableWatcher: false
  #CasbinWatcher notification mode, defaults to use Redis for notification synchronization, temporarily only supports Redis
  #After opening Watcher, you need to manually add spring-boot-starter-data-redis dependency.
  watcherType: redis
  exception:
    ... See Schedule A for exception settings.
  1. The simplest configuration
  • Do not use other add-on configurations
casbin:
  #If you are using a model profile at this address, no configuration is required
  model: classpath:casbin/model.conf
  • Turn on Watcher
casbin:
  #If the model profile you are using is located at this address, you do not need this configuration
  model: classpath:casbin/model.conf
  #When you open Watcher, the default use of RedisWatcher requires manual addition of spring-boot-starter-data-redis dependency.
  enableWatcher: true
  1. Use custom independent data sources
  • Only increase @CasbinDataSource annotation when injecting custom data source
@Configuration
public class CasbinDataSourceConfiguration {
    @Bean
    @CasbinDataSource
    public DataSource casbinDataSource() {
        return DataSourceBuilder.create().url("jdbc:h2:mem:casbin").build();
    }
}
Schedule A
  • ExceptionSettings(casbin.exception)
name description default
removePolicyFailed Throws an exception when the delete policy fails false
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.

Notice:

Since version 0.0.11, casbin-spring-boot-starter adds an id field to the database table structure by default.

The version before 0.0.11 is upgraded to version 0.0.11 and later requires the user to manually add the id field.

See #21 for details

casbin-spring-boot-starter's People

Contributors

d1zzzy1 avatar divyagar avatar doctormacky avatar fabian4 avatar fangzhengjin avatar fengxq2014 avatar hamid646m avatar hsluoyz avatar imp2002 avatar loukkyy avatar nitro8 avatar nomeguy avatar outofeastgate avatar seriouszyx avatar shingmoyeung avatar shink avatar shy1st avatar tangyang9464 avatar xgaxpp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

casbin-spring-boot-starter's Issues

Model not found

When the application was deployed, model can not find, This is the error message I got.

class path resource [casbin/model.conf] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/mnt/app. jar!/BOOT-INF/classes!/casbin/model.conf

unable to refresh roles for user

First, two roles were added to alice in the configuration table, and her role information was also obtained normally.

image image

But after adding a third role, it still doesn't get it after a long time, and the config is set to auto-refresh.
image

image image

image

What is the problem?

Replace jacsbin 1.9.2 in casbin-spring-boot-starter with version 1.21.0

<dependency> <groupId>org.casbin</groupId> <artifactId>casbin-spring-boot-starter</artifactId> <version>0.3.0</version> <exclusions> <exclusion> <groupId>org.casbin</groupId> <artifactId>jcasbin</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.casbin</groupId> <artifactId>jcasbin</artifactId> <version>1.21.0</version> </dependency>
Since jacsbin 1.9.2 does not support batch operations, we use 1.21.0, but after changing the version, 1.9.2 can enforce the permissions of true, now all are false, and there is no change in mode.conf and library data. Please fix it or introduce the latest version of jcasbin

Dependency conflict + wrong tag for dependency jcasbin

The following dependency creates a conflict for jcasbin:

implementation 'org.casbin:jdbc-adapter:2.5.0'

Also, it is not using a correct tagging ("LATEST")
image

Workaround
Exclude jcasbin dependency from and re-import it as follows:

<dependency>
	<groupId>org.casbin</groupId>
	<artifactId>casbin-spring-boot-starter</artifactId>
	<version>1.2.0</version>
	<exclusions>
		<exclusion>
			<artifactId>jcasbin</artifactId>
			<groupId>org.casbin</groupId>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupId>org.casbin</groupId>
	<artifactId>jcasbin</artifactId>
	<version>1.40.0</version>
</dependency>

Two databases

I have two databases in my project

How can I tell which database to create tables in?

Support for policy subset loading

How to use policy subset loading here? I am not able to find any documentation regarding this. Note that I am using JDBC with postgres.

Redis Connection Failure

Hey,
there I m trying to run this application where it get over with this error 'ERROR 21647 --- [enerContainer-1] o.s.d.r.l.RedisMessageListenerContainer : Connection failure occurred. Restarting subscription task after 5000 ms'

I have already tried with these combinations -

plugins {
    id 'org.springframework.boot' version '2.3.5.RELEASE'
    id "com.jfrog.bintray" version "1.8.4"
    id 'java'
}

apply plugin: 'io.spring.dependency-management'
apply from: "maven.gradle"
apply from: "bintray.gradle"
apply from: "jacoco.gradle"

group = 'org.casbin'
version VERSION_CODE
sourceCompatibility = '1.8'
compileJava.options.encoding = 'UTF-8'

bootJar.enabled = false
jar.enabled = true

repositories {
    mavenLocal()
    maven { url "https://maven.aliyun.com/repository/public/" }
    mavenCentral()
}

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

dependencies {
    compile 'org.casbin:jcasbin:1.6.4'
    compile 'com.h2database:h2'
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'

    compileOnly 'org.springframework.boot:spring-boot-starter-data-redis'
    testImplementation 'org.springframework.boot:spring-boot-starter-data-redis'
    testRuntimeOnly 'mysql:mysql-connector-java:5.1.47'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation 'org.casbin:casbin-spring-boot-starter:version'
    // implementation 'org.springframework.boot:spring-boot-starter-data-redis:2.2.0.RELEASE'
    // implementation 'redis.clients:jedis:2.8.0'
    // implementation group: org.springframework.boot 
    // name: spring-boot-starter-data-redis 
    // version: 2.4.0-M3

}

But I m unable to run the application.

Could you add JDK information to the docs?

While running this project, I kept encountering errors and thought it might be a configuration issue, which took me a long time to troubleshoot. Eventually, I noticed in the 'specialThank' section, there was a mention of Java 17. After switching to that JDK version, the project was able to run successfully

最简配置下 H2 如何生效的呢?

最简配置下 autoConfigJdbcAdapter入参 jdbcTemplate 默认使用的是h2 和HikariPool.
连接池HikariPool 是springboot 2.X 默认的 h2是怎么回事呢?

H2 2.0.202 seems not work with default jdbcadapter

If I change the h2 database version from 1.4.200 to 2.0.202, following error message will appear:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoConfigJdbcAdapter' defined in class path resource [org/casbin/spring/boot/autoconfigure/CasbinAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.casbin.jcasbin.persist.Adapter]: Factory method 'autoConfigJdbcAdapter' threw exception; nested exception is org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [CREATE TABLE IF NOT EXISTS casbin_rule ( id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, ptype varchar(255) NOT NULL, v0 varchar(255) DEFAULT NULL, v1 varchar(255) DEFAULT NULL, v2 varchar(255) DEFAULT NULL, v3 varchar(255) DEFAULT NULL, v4 varchar(255) DEFAULT NULL, v5 varchar(255) DEFAULT NULL)]; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE IF NOT EXISTS CASBIN_RULE ( ID INT([]11) NOT NULL AUTO_INCREMENT PRIMARY KEY, PTYPE VARCHAR(255) NOT NULL, V0 VARCHAR(255) DEFAULT NULL, V1 VARCHAR(255) DEFAULT NULL, V2 VARCHAR(255) DEFAULT NULL, V3 VARCHAR(255) DEFAULT NULL, V4 VARCHAR(255) DEFAULT NULL, V5 VARCHAR(255) DEFAULT NULL)"; expected "ARRAY, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, DEFAULT, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, COMMENT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ., )"; SQL statement:
CREATE TABLE IF NOT EXISTS casbin_rule ( id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, ptype varchar(255) NOT NULL, v0 varchar(255) DEFAULT NULL, v1 varchar(255) DEFAULT NULL, v2 varchar(255) DEFAULT NULL, v3 varchar(255) DEFAULT NULL, v4 varchar(255) DEFAULT NULL, v5 varchar(255) DEFAULT NULL) [42001-202]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.14.jar:5.3.14]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.14.jar:5.3.14]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) [spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302) [spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) [spring-boot-2.6.2.jar:2.6.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290) [spring-boot-2.6.2.jar:2.6.2]
at org.joinfaces.example.JoinFacesExampleApplication.main(JoinFacesExampleApplication.java:35) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.6.2.jar:2.6.2]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.casbin.jcasbin.persist.Adapter]: Factory method 'autoConfigJdbcAdapter' threw exception; nested exception is org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [CREATE TABLE IF NOT EXISTS casbin_rule ( id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, ptype varchar(255) NOT NULL, v0 varchar(255) DEFAULT NULL, v1 varchar(255) DEFAULT NULL, v2 varchar(255) DEFAULT NULL, v3 varchar(255) DEFAULT NULL, v4 varchar(255) DEFAULT NULL, v5 varchar(255) DEFAULT NULL)]; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE IF NOT EXISTS CASBIN_RULE ( ID INT([
]11) NOT NULL AUTO_INCREMENT PRIMARY KEY, PTYPE VARCHAR(255) NOT NULL, V0 VARCHAR(255) DEFAULT NULL, V1 VARCHAR(255) DEFAULT NULL, V2 VARCHAR(255) DEFAULT NULL, V3 VARCHAR(255) DEFAULT NULL, V4 VARCHAR(255) DEFAULT NULL, V5 VARCHAR(255) DEFAULT NULL)"; expected "ARRAY, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, DEFAULT, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, COMMENT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ., )"; SQL statement:
CREATE TABLE IF NOT EXISTS casbin_rule ( id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, ptype varchar(255) NOT NULL, v0 varchar(255) DEFAULT NULL, v1 varchar(255) DEFAULT NULL, v2 varchar(255) DEFAULT NULL, v3 varchar(255) DEFAULT NULL, v4 varchar(255) DEFAULT NULL, v5 varchar(255) DEFAULT NULL) [42001-202]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.14.jar:5.3.14]
... 24 common frames omitted
Caused by: org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [CREATE TABLE IF NOT EXISTS casbin_rule ( id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, ptype varchar(255) NOT NULL, v0 varchar(255) DEFAULT NULL, v1 varchar(255) DEFAULT NULL, v2 varchar(255) DEFAULT NULL, v3 varchar(255) DEFAULT NULL, v4 varchar(255) DEFAULT NULL, v5 varchar(255) DEFAULT NULL)]; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE IF NOT EXISTS CASBIN_RULE ( ID INT([]11) NOT NULL AUTO_INCREMENT PRIMARY KEY, PTYPE VARCHAR(255) NOT NULL, V0 VARCHAR(255) DEFAULT NULL, V1 VARCHAR(255) DEFAULT NULL, V2 VARCHAR(255) DEFAULT NULL, V3 VARCHAR(255) DEFAULT NULL, V4 VARCHAR(255) DEFAULT NULL, V5 VARCHAR(255) DEFAULT NULL)"; expected "ARRAY, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, DEFAULT, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, COMMENT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ., )"; SQL statement:
CREATE TABLE IF NOT EXISTS casbin_rule ( id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, ptype varchar(255) NOT NULL, v0 varchar(255) DEFAULT NULL, v1 varchar(255) DEFAULT NULL, v2 varchar(255) DEFAULT NULL, v3 varchar(255) DEFAULT NULL, v4 varchar(255) DEFAULT NULL, v5 varchar(255) DEFAULT NULL) [42001-202]
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:239) ~[spring-jdbc-5.3.14.jar:5.3.14]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70) ~[spring-jdbc-5.3.14.jar:5.3.14]
at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1541) ~[spring-jdbc-5.3.14.jar:5.3.14]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:393) ~[spring-jdbc-5.3.14.jar:5.3.14]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:431) ~[spring-jdbc-5.3.14.jar:5.3.14]
at org.casbin.adapter.JdbcAdapter.initTable(JdbcAdapter.java:113) ~[casbin-spring-boot-starter-0.4.0.jar:na]
at org.casbin.adapter.JdbcAdapter.(JdbcAdapter.java:68) ~[casbin-spring-boot-starter-0.4.0.jar:na]
at org.casbin.spring.boot.autoconfigure.CasbinAutoConfiguration.autoConfigJdbcAdapter(CasbinAutoConfiguration.java:97) ~[casbin-spring-boot-starter-0.4.0.jar:na]
at org.casbin.spring.boot.autoconfigure.CasbinAutoConfiguration$$EnhancerBySpringCGLIB$$6afe6f40.CGLIB$autoConfigJdbcAdapter$0() ~[casbin-spring-boot-starter-0.4.0.jar:na]
at org.casbin.spring.boot.autoconfigure.CasbinAutoConfiguration$$EnhancerBySpringCGLIB$$6afe6f40$$FastClassBySpringCGLIB$$76092b9e.invoke() ~[casbin-spring-boot-starter-0.4.0.jar:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.3.14.jar:5.3.14]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.3.14.jar:5.3.14]
at org.casbin.spring.boot.autoconfigure.CasbinAutoConfiguration$$EnhancerBySpringCGLIB$$6afe6f40.autoConfigJdbcAdapter() ~[casbin-spring-boot-starter-0.4.0.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_202]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_202]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_202]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_202]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.14.jar:5.3.14]
... 25 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE IF NOT EXISTS CASBIN_RULE ( ID INT([
]11) NOT NULL AUTO_INCREMENT PRIMARY KEY, PTYPE VARCHAR(255) NOT NULL, V0 VARCHAR(255) DEFAULT NULL, V1 VARCHAR(255) DEFAULT NULL, V2 VARCHAR(255) DEFAULT NULL, V3 VARCHAR(255) DEFAULT NULL, V4 VARCHAR(255) DEFAULT NULL, V5 VARCHAR(255) DEFAULT NULL)"; expected "ARRAY, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, DEFAULT, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, COMMENT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ., )"; SQL statement:
CREATE TABLE IF NOT EXISTS casbin_rule ( id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, ptype varchar(255) NOT NULL, v0 varchar(255) DEFAULT NULL, v1 varchar(255) DEFAULT NULL, v2 varchar(255) DEFAULT NULL, v3 varchar(255) DEFAULT NULL, v4 varchar(255) DEFAULT NULL, v5 varchar(255) DEFAULT NULL) [42001-202]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:502) ~[h2-2.0.202.jar:2.0.202]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:477) ~[h2-2.0.202.jar:2.0.202]
at org.h2.message.DbException.getSyntaxError(DbException.java:261) ~[h2-2.0.202.jar:2.0.202]
at org.h2.command.Parser.getSyntaxError(Parser.java:1286) ~[h2-2.0.202.jar:2.0.202]
at org.h2.command.Parser.read(Parser.java:6099) ~[h2-2.0.202.jar:2.0.202]
at org.h2.command.Parser.readIfMore(Parser.java:1656) ~[h2-2.0.202.jar:2.0.202]
at org.h2.command.Parser.parseCreateTable(Parser.java:10337) ~[h2-2.0.202.jar:2.0.202]
at org.h2.command.Parser.parseCreate(Parser.java:7803) ~[h2-2.0.202.jar:2.0.202]
at org.h2.command.Parser.parsePrepared(Parser.java:1140) ~[h2-2.0.202.jar:2.0.202]
at org.h2.command.Parser.parse(Parser.java:1068) ~[h2-2.0.202.jar:2.0.202]
at org.h2.command.Parser.parse(Parser.java:1041) ~[h2-2.0.202.jar:2.0.202]
at org.h2.command.Parser.prepareCommand(Parser.java:965) ~[h2-2.0.202.jar:2.0.202]
at org.h2.engine.SessionLocal.prepareLocal(SessionLocal.java:614) ~[h2-2.0.202.jar:2.0.202]
at org.h2.engine.SessionLocal.prepareCommand(SessionLocal.java:552) ~[h2-2.0.202.jar:2.0.202]
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1111) ~[h2-2.0.202.jar:2.0.202]
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:237) ~[h2-2.0.202.jar:2.0.202]
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:223) ~[h2-2.0.202.jar:2.0.202]
at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:94) ~[HikariCP-4.0.3.jar:na]
at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-4.0.3.jar:na]
at org.springframework.jdbc.core.JdbcTemplate$1ExecuteStatementCallback.doInStatement(JdbcTemplate.java:422) ~[spring-jdbc-5.3.14.jar:5.3.14]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:381) ~[spring-jdbc-5.3.14.jar:5.3.14]
... 39 common frames omitted

Or It is related to Hibernate ORM:H2 version 2.0.202 )auto_increment not working

WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils

Spring Boot:v2.2.2.RELEASE
OpenJDK:

openjdk 11 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

WARNING:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/C:/Users/Tinywan/.m2/repository/org/springframework/spring-core/5.2.2.RELEASE/spring-core-5.2.2.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

FilteredPolicy for JdbcAdapter

With large dataset policy in database, JdbcAdapter need implement FilteredPolicy method allow load dynamic policy based on user

JDBCAdapter only support fixed table name

Hi guys, when customer using this project. the table name are fixed.(casbin_rule) we need a way to support the configurable table name. I will submit PR whe I am available.

RedisWatcherAutoConfigration bug

in

src/main/java/org/casbin/spring/boot/autoconfigure/CasbinRedisWatcherAutoConfiguration.java

casbinProperties.getPolicyTopic() should be passed in, not redisProperties.getClientName().

// fixed channel-name RedisWatcher watcher = new RedisWatcher(redisProperties.getHost(), redisProperties.getPort(), casbinProperties.getPolicyTopic(), timeout, redisProperties.getPassword());

Casbin Starter Can't Use Dynamic Data Source

As the project needed, we used the dynamic data source, so there is no config as follows:

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://ip:3306/dev
    username: root
    password: root

What we have used is:

spring:
  datasource:
    dynamic:
      datasource:
        # master
        master:
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://ip:3306/dev
          username: root
          password: root

When I start my application, I got an error something like datasource init failed because of the dataSourceProperties information is null
Code Path:casbin-spring-boot-starter/src/main/java/org/casbin/spring/boot/autoconfigure/CasbinAutoConfiguration.java:72

   /**
     * Automatic configuration of JDBC adapter
     */
    @Bean
    @ConditionalOnProperty(name = "casbin.storeType", havingValue = "jdbc", matchIfMissing = true)
    @ConditionalOnBean(JdbcTemplate.class)
    @ConditionalOnMissingBean
    public Adapter autoConfigJdbcAdapter(
            @CasbinDataSource ObjectProvider<DataSource> casbinDataSource,
            JdbcTemplate jdbcTemplate,
            CasbinProperties properties,
            CasbinExceptionProperties exceptionProperties,
            DataSourceProperties dataSourceProperties
    ) throws Exception {
        JdbcTemplate jdbcTemplateToUse = getJdbcTemplate(jdbcTemplate, casbinDataSource);
        String databaseName = getDatabaseName(jdbcTemplateToUse.getDataSource());
        CasbinDataSourceInitializationMode initializeSchema = properties.getInitializeSchema();
        boolean autoCreateTable = initializeSchema == CasbinDataSourceInitializationMode.CREATE;
        String tableName = properties.getTableName();
        logger.info("Casbin current use database product: {}", databaseName);
        return new JDBCAdapter(dataSourceProperties.determineDriverClassName(), dataSourceProperties.getUrl(),
                dataSourceProperties.getUsername(), dataSourceProperties.getPassword(),
                exceptionProperties.isRemovePolicyFailed(), tableName, autoCreateTable);

    }

To solve this problem, I have modified this code block as follows:

/**
     * Automatic configuration of JDBC adapter
     */
    @Bean
    @ConditionalOnProperty(name = "casbin.storeType", havingValue = "jdbc", matchIfMissing = true)
    @ConditionalOnBean(JdbcTemplate.class)
    @ConditionalOnMissingBean
    public Adapter autoConfigJdbcAdapter(
            @CasbinDataSource ObjectProvider<DataSource> casbinDataSource,
            JdbcTemplate jdbcTemplate,
            CasbinProperties properties,
            CasbinExceptionProperties exceptionProperties,
            DataSourceProperties dataSourceProperties
    ) throws Exception {
        JdbcTemplate jdbcTemplateToUse = getJdbcTemplate(jdbcTemplate, casbinDataSource);
        if (jdbcTemplateToUse == null || jdbcTemplateToUse.getDataSource() == null) {
            throw new CasbinAdapterException("Cannot create jdbc adapter, because jdbc template is not set");
        }
        String databaseName = getDatabaseName(jdbcTemplateToUse.getDataSource());
        CasbinDataSourceInitializationMode initializeSchema = properties.getInitializeSchema();
        boolean autoCreateTable = initializeSchema == CasbinDataSourceInitializationMode.CREATE;
        String tableName = properties.getTableName();
        logger.info("Casbin current use database product: {}", databaseName);
        // datasource properties are configed
        if (dataSourceProperties.getUrl() != null) {
            return new JDBCAdapter(dataSourceProperties.determineDriverClassName(), dataSourceProperties.getUrl(),
                    dataSourceProperties.getUsername(), dataSourceProperties.getPassword(),
                    exceptionProperties.isRemovePolicyFailed(), tableName, autoCreateTable);
        }
        // when datasource properties are not configed, use the default datasource in jdbcTemplate
        else {
            return new JDBCAdapter(jdbcTemplateToUse.getDataSource(), exceptionProperties.isRemovePolicyFailed(), tableName, autoCreateTable);
        }
    }

JDBC Adapter for PostgreSQL fails for creation of Table

Hi Team,

casbin-spring-boot-starter - Version used - 0.0.13
postgresql version - 10.10

Currently I am integrating the casbin sprin boot starter using the JDBCAdapter for - PostgreSQL. I am encountering following execption during the table creation

2021-05-27 15:38:08.306 DEBUG 25048 --- [ main] o.s.jdbc.core.JdbcTemplate : Executing SQL statement [CREATE TABLE IF NOT EXISTS casbin_rule ( id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, ptype varchar(255) NOT NULL, v0 varchar(255) DEFAULT NULL, v1 varchar(255) DEFAULT NULL, v2 varchar(255) DEFAULT NULL, v3 varchar(255) DEFAULT NULL, v4 varchar(255) DEFAULT NULL, v5 varchar(255) DEFAULT NULL)]
2021-05-27 15:38:08.383 WARN 25048 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authorizationCMDStartup': Unsatisfied dependency expressed through field 'rbacDBTest'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'RBACdbTest': Unsatisfied dependency expressed through field 'adapter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoConfigJdbcAdapter' defined in class path resource [org/casbin/spring/boot/autoconfigure/CasbinAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.casbin.jcasbin.persist.Adapter]: Factory method 'autoConfigJdbcAdapter' threw exception; nested exception is org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [CREATE TABLE IF NOT EXISTS casbin_rule ( id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, ptype varchar(255) NOT NULL, v0 varchar(255) DEFAULT NULL, v1 varchar(255) DEFAULT NULL, v2 varchar(255) DEFAULT NULL, v3 varchar(255) DEFAULT NULL, v4 varchar(255) DEFAULT NULL, v5 varchar(255) DEFAULT NULL)]; nested exception is org.postgresql.util.PSQLException: ERROR: syntax error at or near "("
Position: 51

On debugging deeper, I found in JDBC Adapter the "INIT TABLE SQL" throws the syntax error for PostgreSQL
Tried executing same in PostgreSQL editor
image

Could suggest or guide on this ?

jdk 11 报错

经过排查已确认是该模块的报错
环境 jdk 11, Spring boot 2.2

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/Users/hurui/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.2.1.RELEASE/32b265ff5c7c35257b5a242b9628dcd321a2b010/spring-core-5.2.1.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release

jvm加入参数 --illegal-access=debug 后显示的错误

ARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils (file:/Users/hurui/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.2.1.RELEASE/32b265ff5c7c35257b5a242b9628dcd321a2b010/spring-core-5.2.1.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:525) at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:582) at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:569) at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:416) at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:57) at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:205) at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:471) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:350) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:299) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1807) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)

Watcher Jedis java.lang.NoSuchMethodError error

Hi, I enabled watcher configuration (in my application.yml) using this configuration:

casbin:
  enableWatcher: true
  use-synced-enforcer: true

When I do some operation over Enforcer, I get this error:
Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: 'java.lang.Long redis.clients.jedis.Jedis.publish(java.lang.String, java.lang.String)'

I googled the error, some says it could be because of Jedis version is incompatible with the Spring Boot version I use (which is 2.7.5).

First, I used the default Jedis package comes with casbin-spring-boot-starter. After I got the error, I upgraded its version to 4.3.1, unfortunately the error still persists.

Any idea why I get this error? Maybe missing configuration on my project?
Any solution?

Thanks in advance.

Delete Perm throws a CasbibException

background:
spring boot project, with 2.1.7.RELEASE and casbin spring boot starter the latest

default model, with jdbc adapter

situation 1
put no data in the table of casbin_rule
excute enforcer.deletePermission("perm");

situation 2
put some data in the table of casbin_rule:
p,ROLE_ADMIN,res,add
g,admin,ROLE_ADMIN

excute enforcer.deletePermission("res","delete");
it will throw a Casbin Exception with info:
CasbinAdapterException: Remove filtered policy error, remove 0 rows, expect least 1 rows
I have debugged and found it's something wrong with the jdbc adapter.

Impact of upgrading to 0.0.11 and later

Since version 0.0.11, casbin-spring-boot-starter adds an id field to the database table structure by default.
The version before 0.0.11 is upgraded to version 0.0.11 and later requires the user to manually add the id field.
See #21 for details

JdbcAdapter will not load the policy from database in initial phase

When we try to run the springboot, it will not load existing policy from database. that means the poliicy in memoy of the appliication are empty, this should not work as expected.

from my understanding, the adapter should load all the policy from database during the initial phase of application.
Suggest we set following attribute in JdbcAdapter from true to false as default.
private volatile boolean isFiltered = false ;

Any idea ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.