casbin / jcasbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Java
https://casbin.org
Apache License 2.0
2.39k stars 464 forks source link

springboot fatjar can't read casbin config resources #48

Closed jianchengwang closed 4 years ago

jianchengwang commented 4 years ago

when I maven package my springboot project as a fatjar, then i run commed java -jar, here are some exception stack messages below.

Caused by: org.casbin.jcasbin.exception.CasbinConfigException: file:\C:\Users\lenovo\Desktop\pgcm-1.0-SNAPSHOT-exec.jar!\BOOT-INF\classes!\casbin\rbac_model.conf (文件名、目录名或卷标语法不正确。)
        at org.casbin.jcasbin.config.Config.parse(Config.java:92) ~[jcasbin-1.4.0.jar!/:na]
        at org.casbin.jcasbin.config.Config.newConfig(Config.java:49) ~[jcasbin-1.4.0.jar!/:na]
        at org.casbin.jcasbin.model.Model.loadModel(Model.java:108) ~[jcasbin-1.4.0.jar!/:na]
        at org.casbin.spring.boot.autoconfigure.CasbinAutoConfiguration.enforcer(CasbinAutoConfiguration.java:100) ~[casbin-spring-boot-starter-0.0.8.jar!/:na]

and here is org.casbin.jcasbin.config.Config.parse method below

private void parse(String fname) {
        lock.lock();
        try (FileInputStream fis = new FileInputStream(fname)) {
            BufferedReader buf = new BufferedReader(new InputStreamReader(fis));
            parseBuffer(buf);
        } catch (IOException e) {
            throw new CasbinConfigException(e.getMessage(), e.getCause());
        } finally {
            lock.unlock();
        }
    }

then I found a question inStackOverflow, https://stackoverflow.com/questions/25869428/classpath-resource-not-found-when-running-as-jar

I don't know this is a bug or not, and how to do my problem, hope u can reply me soon.

hsluoyz commented 4 years ago

@fangzhengjin

jianchengwang commented 4 years ago

my fault, it had been fixed in casbin-spring-boot-starter:0.0.9, i use 0.08 before.

in 0.09

 String modelContext = properties.getModelContext();
 model.loadModelFromText(modelContext);

not model.loadModel(), so it work ok.