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);
标签:sure,java,string,permission,AuthorizingRealm,apache,org,shiro From: https://blog.51cto.com/u_7044146/5965617