Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalAccessError: class org.casbin.adapter.JDBCBaseAdapter tried to access private field org.casbin.adapter.CasbinRule.ptype #271

Closed
suryamukerjee1982 opened this issue May 5, 2022 · 4 comments
Assignees
Labels

Comments

@suryamukerjee1982
Copy link

I am creating a Spring Boot app with spring data jpa and with the policy persisted in PostgreSQL DB.

pom ---

<dependency>
            <groupId>org.casbin</groupId>
            <artifactId>casbin-spring-boot-starter</artifactId>
            <version>0.0.10</version>
        </dependency>
        <dependency>
  			<groupId>org.casbin</groupId>
  			<artifactId>jdbc-adapter</artifactId>
  			<version>2.2.2</version>
		</dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>

application.properties

casbin.storeType=jdbc
spring.datasource.hikari.connectionTimeout=20000
spring.datasource.hikari.maximumPoolSize=5
## PostgreSQL
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.jpa.properties.hibernate.default_schema=public
spring.datasource.username=postgres
spring.datasource.password=admin
logging.level.org.springframework=ERROR
spring.jpa.hibernate.ddl-auto=none
spring.datasource.initialization-mode=always
spring.datasource.platform=postgres
spring.jpa.properties.hibernate.id.new_generator_mappings=false
debug=true
logging.level.com.example.casbinspringbootdemo=de

Model - I am loading the model in my Main application class inside a Bean

    @Bean
    public Model getModel(){
    	Model model = new Model();
    	model.addDef("r", "r", "sub, obj, act");
    	model.addDef("p", "p", "sub, obj, act");
    	model.addDef("g", "g", "_, _");
    	model.addDef("e", "e", "some(where (p.eft == allow))");
    	model.addDef("m", "m", "g(r.sub, p.sub) && keyMatch2(r.obj, p.obj) && regexMatch(r.act, p.act)");
		return model;
    }

### In my Filter Class, I am doing the following for initializing the Enforcer with the Model and the Policy-

    @Autowired   
    private Model model;
    @Autowired   
    private HikariDataSource dataSource;

     public void doFilter(...){
               JDBCAdapter adapter = new JDBCAdapter(dataSource);
    	       Enforcer enforcer = new Enforcer(model, adapter);
    	       enforcer.addPolicy("sites_apps_admin", "/ws/policymanagement/policy", "POST");
}

### The application starts fine and the table casbin_rule gets created in my postgreSQL DB. But as soon as the code hits the enforcer.addPolicy() line, it throws an exception as follows -

java.lang.IllegalAccessError: class org.casbin.adapter.JDBCBaseAdapter tried to access private field org.casbin.adapter.CasbinRule.ptype (org.casbin.adapter.JDBCBaseAdapter and org.casbin.adapter.CasbinRule are in unnamed module of loader 'app')
	at org.casbin.adapter.JDBCBaseAdapter.lambda$loadPolicy$0(JDBCBaseAdapter.java:191) ~[jdbc-adapter-2.2.2.jar:na]
	at dev.failsafe.Functions.lambda$toCtxSupplier$10(Functions.java:236) ~[failsafe-3.2.3.jar:3.2.3]
	at dev.failsafe.Functions.lambda$get$0(Functions.java:46) ~[failsafe-3.2.3.jar:3.2.3]
	at dev.failsafe.internal.RetryPolicyExecutor.lambda$apply$0(RetryPolicyExecutor.java:74) ~[failsafe-3.2.3.jar:3.2.3]
	at dev.failsafe.SyncExecutionImpl.executeSync(SyncExecutionImpl.java:193) ~[failsafe-3.2.3.jar:3.2.3]
	at dev.failsafe.FailsafeExecutor.call(FailsafeExecutor.java:376) ~[failsafe-3.2.3.jar:3.2.3]
	at dev.failsafe.FailsafeExecutor.run(FailsafeExecutor.java:231) ~[failsafe-3.2.3.jar:3.2.3]
	at org.casbin.adapter.JDBCBaseAdapter.loadPolicy(JDBCBaseAdapter.java:182) ~[jdbc-adapter-2.2.2.jar:na]
	at org.casbin.adapter.JDBCAdapter.loadPolicy(JDBCAdapter.java:34) ~[jdbc-adapter-2.2.2.jar:na]
	at org.casbin.jcasbin.main.CoreEnforcer.loadPolicy(CoreEnforcer.java:211) ~[jcasbin-1.6.1.jar:na]
	at org.casbin.jcasbin.main.Enforcer.<init>(Enforcer.java:76) ~[jcasbin-1.6.1.jar:na]
	at com.casbindemo.auth.JCasbinAuthzFilter.authorized(JCasbinAuthzFilter.java:71) ~[classes/:na]
	at com.casbindemo.auth.JCasbinAuthzFilter.doFilter(JCasbinAuthzFilter.java:50) ~[classes/:na]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.19.jar:5.3.19]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.19.jar:5.3.19]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.19.jar:5.3.19]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.19.jar:5.3.19]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96) ~[spring-boot-actuator-2.6.7.jar:2.6.7]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.19.jar:5.3.19]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.19.jar:5.3.19]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.19.jar:5.3.19]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
	at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

@casbin-bot casbin-bot added the bug label May 5, 2022
@casbin-bot
Copy link
Member

@hsluoyz
Copy link
Member

hsluoyz commented May 5, 2022

@tangyang9464

@tangyang9464
Copy link
Member

@suryamukerjee1982 The easiest solution is to remove the casbin-spring-boot-starter dependency or jdbc-adapter.
Because the CasbinRule structure in casbin-spring-boot-starter and jdbc-adapter is conflicting. And It looks like you don't use casbin-spring-boot-starter at all. Currently casbin-spring-boot-starter has its own built-in jdbc-adapter, but it is not compatible, so you cannot import jdbc-adapter at the same time. This is a legacy problem, and we will fix it later.

@hsluoyz
Copy link
Member

hsluoyz commented Jul 6, 2022

Fixed by: jcasbin/casbin-spring-boot-starter#68

@suryamukerjee1982 plz have a try

@hsluoyz hsluoyz closed this as completed Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants