IllegalArgumentException: Wildcard string cannot be null or empty. Make sure permission strings are

IllegalArgumentException: Wildcard string cannot be null or empty. Make sure permission strings are properly formatted异常解决办法

一. 异常现象

我在ssm项目中整合shiro时,配置了接口及资源与过滤器之间映射关系时,产生了如下异常信息:

java.lang.IllegalArgumentException: Wildcard string cannot be null or empty. Make sure permission strings are properly formatted.
	at org.apache.shiro.authz.permission.WildcardPermission.setParts(WildcardPermission.java:155)
	at org.apache.shiro.authz.permission.WildcardPermission.<init>(WildcardPermission.java:144)
	at org.apache.shiro.authz.permission.WildcardPermission.<init>(WildcardPermission.java:140)
	at org.apache.shiro.authz.permission.WildcardPermissionResolver.resolvePermission(WildcardPermissionResolver.java:41)
	at org.apache.shiro.realm.AuthorizingRealm.resolvePermissions(AuthorizingRealm.java:434)
	at org.apache.shiro.realm.AuthorizingRealm.getPermissions(AuthorizingRealm.java:410)
	at org.apache.shiro.realm.AuthorizingRealm.isPermitted(AuthorizingRealm.java:468)
	at org.apache.shiro.realm.AuthorizingRealm.isPermitted(AuthorizingRealm.java:463)
	at org.apache.shiro.realm.AuthorizingRealm.isPermitted(AuthorizingRealm.java:458)
	at org.apache.shiro.authz.ModularRealmAuthorizer.isPermitted(ModularRealmAuthorizer.java:223)
	at org.apache.shiro.mgt.AuthorizingSecurityManager.isPermitted(AuthorizingSecurityManager.java:113)
	at org.apache.shiro.subject.support.DelegatingSubject.isPermitted(DelegatingSubject.java:162)
	at ......

二. 异常原因

List<String> permissions = userService.selectPermissionsByUserId(user.getId());

根据用户id查询到的permissions集合中,存在null或者empty空值!

在shiro添加权限的方法addStringPermissions(list)中,集合中的元素不能是空值!

三. 解决办法

将集合中的空值过滤掉!

List<String> permissions = userService.selectPermissionsByUserId(user.getId());
List<String> collect = permissions.stream().filter(item -> item != null).collect(Collectors.toList());
info.addStringPermissions(collect);

 

一一哥Sun CSDN认证博客专家 Elasticsearch Java 架构
十年软件开发授课经验,专注大学生毕业设计及面试求职私塾式指导!对Android/JavaWeb/微服务/H5等技术领域有深入研究!曾任国内最大的智能物联网平台架构师,参与国内最大的智能物流系统平台天眼/冷链/订单/车次系统研发;曾主导国内首款国学教育App及后台架构;负责大庆油田采油管理系统,铝业云计算系统,湖南广电地面波机顶盒等项目的研发。目前担任某著名培训机构教学主管,培养了大批入职阿里,IBM,百度,国家电网等名企的高薪学生.本人坚持只有一心做教育,才能做一流教育的理念,被学生爱称为"一一哥"!QQ:2312119590,今日头条号:一一哥Sun;知乎ID:一一哥
已标记关键词 清除标记
页面用<shiro:hasPermission name="left:banner">标签,报错,为何? java.lang.IllegalArgumentException: Wildcard string cannot be null or empty. Make sure permission strings are properly formatted. at org.apache.shiro.authz.permission.WildcardPermission.setParts(WildcardPermission.java:151) at org.apache.shiro.authz.permission.WildcardPermission.<init>(WildcardPermission.java:142) at org.apache.shiro.authz.permission.WildcardPermission.<init>(WildcardPermission.java:138) at org.apache.shiro.authz.permission.WildcardPermissionResolver.resolvePermission(WildcardPermissionResolver.java:41) at org.apache.shiro.realm.AuthorizingRealm.resolvePermissions(AuthorizingRealm.java:433) at org.apache.shiro.realm.AuthorizingRealm.getPermissions(AuthorizingRealm.java:409) at org.apache.shiro.realm.AuthorizingRealm.isPermitted(AuthorizingRealm.java:466) at org.apache.shiro.realm.AuthorizingRealm.isPermitted(AuthorizingRealm.java:462) at org.apache.shiro.realm.AuthorizingRealm.isPermitted(AuthorizingRealm.java:457) at org.apache.shiro.authz.ModularRealmAuthorizer.isPermitted(ModularRealmAuthorizer.java:223) at org.apache.shiro.mgt.AuthorizingSecurityManager.isPermitted(AuthorizingSecurityManager.java:113) at org.apache.shiro.subject.support.DelegatingSubject.isPermitted(DelegatingSubject.java:158) at org.apache.shiro.web.tags.PermissionTag.isPermitted(PermissionTag.java:66) at org.apache.shiro.web.tags.HasPermissionTag.showTagBody(HasPermissionTag.java:32) at org.apache.shiro.web.tags.PermissionTag.onDoStartTag(PermissionTag.java:57) at org.apache.shiro.web.tags.SecureTag.doStartTag(SecureTag.java:53)
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页