当我尝试在spring-boot maven项目中实例化IniSecurityManagerFactory类时面临IllegalArgumentException

时间:2016-06-13 05:52:46

标签: java maven spring-boot shiro rbac

我试图将Apache shiro的RBAC身份验证逻辑添加到我的Spring启动应用程序中。我正在使用Shiro.ini文件。 但是当我尝试实例化IniSecurityManagerFactory(加载shiro.ini文件)时面临IllegalArgumentException。

这是我的代码:

 @Controller
    @RequestMapping("/ServiceDesigner/User")
    public class UserTest {
            @RequestMapping("/test")
            @ResponseBody
            public String create(String username,String password) throws IOException {
                Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
                SecurityManager securityManager = factory.getInstance();
                SecurityUtils.setSecurityManager(securityManager);

                    UsernamePasswordToken token = new UsernamePasswordToken(username, password);

                    Subject currentUser = SecurityUtils.getSubject();

                    try {
                        currentUser.login(token);

                    } catch ( Exception uae ) { 
                        System.out.println(uae.getMessage());
                    }

                    return "Authenticated";
                    }

StackTrace:

 java.lang.IllegalArgumentException: Line argument must contain a key and a value.  Only one string token was found.
at org.apache.shiro.config.Ini$Section.splitKeyValue(Ini.java:542) ~[shiro-core-1.2.2.jar:1.2.2]
at org.apache.shiro.config.Ini$Section.toMapProps(Ini.java:567) ~[shiro-core-1.2.2.jar:1.2.2]
at org.apache.shiro.config.Ini$Section.<init>(Ini.java:464) ~[shiro-core-1.2.2.jar:1.2.2]
at org.apache.shiro.config.Ini$Section.<init>(Ini.java:445) ~[shiro-core-1.2.2.jar:1.2.2]
at org.apache.shiro.config.Ini.addSection(Ini.java:302) ~[shiro-core-1.2.2.jar:1.2.2]
at org.apache.shiro.config.Ini.load(Ini.java:334) ~[shiro-core-1.2.2.jar:1.2.2]
at org.apache.shiro.config.Ini.load(Ini.java:287) ~[shiro-core-1.2.2.jar:1.2.2]
at org.apache.shiro.config.Ini.load(Ini.java:275) ~[shiro-core-1.2.2.jar:1.2.2]
at org.apache.shiro.config.Ini.loadFromPath(Ini.java:244) ~[shiro-core-1.2.2.jar:1.2.2]
at org.apache.shiro.config.IniFactorySupport.loadDefaultClassPathIni(IniFactorySupport.java:69) ~[shiro-core-1.2.2.jar:1.2.2]
at org.apache.shiro.config.IniFactorySupport.resolveIni(IniFactorySupport.java:92) ~[shiro-core-1.2.2.jar:1.2.2]
at org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:108) ~[shiro-core-1.2.2.jar:1.2.2]
at org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47) ~[shiro-core-1.2.2.jar:1.2.2]
at com.verizon.servicedesginer.api.UserTest.create(UserTest.java:89) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_51]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:832) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:743) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.33.jar:8.0.33]

我很感激任何建设性的反馈。

1 个答案:

答案 0 :(得分:0)

听起来你的.ini文件可能有问题吗?它符合标准吗? https://shiro.apache.org/static/1.2.1/apidocs/org/apache/shiro/config/Ini.html