欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-07-14 18:43:55
...

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空值!

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

在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);

 

相关标签: 异常解决