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.(WildcardPermission.java:144)
	at org.apache.shiro.authz.permission.WildcardPermission.(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 permissions = userService.selectPermissionsByUserId(user.getId());

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

IllegalArgumentException: Wildcard string cannot be null or empty. Make sure permission strings are_第1张图片

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

三. 解决办法

将集合中的空值过滤掉!

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

 

你可能感兴趣的:(异常解决)