鍍金池/ 問答/Java  Linux/ Shiro報(bào)錯(cuò):“通配符字符串不能為空或空。確保權(quán)限字符串被正確格式化?!?/span>

Shiro報(bào)錯(cuò):“通配符字符串不能為空或空。確保權(quán)限字符串被正確格式化?!?/h1>

權(quán)限列表filterChainDefinitionMap中Debug如下:

clipboard.png

通過實(shí)現(xiàn)自定義filter,繼承自org.apache.shiro.web.filter.AccessControlFilter

@Override
    protected boolean isAccessAllowed(ServletRequest servletRequest, ServletResponse servletResponse, Object mappedValue) throws Exception {
        log.info("PermissionAuthorizationFilter執(zhí)行");
        Subject subject = getSubject(servletRequest, servletResponse);
        if(null != mappedValue){
            String[] value = (String[])mappedValue;
            for (String permission : value) {
                if(subject.isPermitted(permission)){
                    return true;
                }
            }
        }
        return false;
    }

在上述代碼中執(zhí)行到subject.isPermitted部分報(bào)錯(cuò),Debug傳入傳輸為:

clipboard.png

錯(cuò)誤信息:

java.lang.IllegalArgumentException: Wildcard string cannot be null or empty. Make sure permission strings are properly formatted.

shiro源碼部分:

protected void setParts(String wildcardString, boolean caseSensitive) {
        if (wildcardString != null && wildcardString.trim().length() != 0) {
            wildcardString = wildcardString.trim();
            List<String> parts = CollectionUtils.asList(wildcardString.split(":"));
            this.parts = new ArrayList();
            Iterator i$ = parts.iterator();

            while(i$.hasNext()) {
                String part = (String)i$.next();
                Set<String> subparts = CollectionUtils.asSet(part.split(","));
                if (!caseSensitive) {
                    subparts = this.lowercase(subparts);
                }

                if (subparts.isEmpty()) {
                    throw new IllegalArgumentException("Wildcard string cannot contain parts with only dividers. Make sure permission strings are properly formatted.");
                }

                this.parts.add(subparts);
            }

            if (this.parts.isEmpty()) {
                throw new IllegalArgumentException("Wildcard string cannot contain only dividers. Make sure permission strings are properly formatted.");
            }
        } else {
            throw new IllegalArgumentException("Wildcard string cannot be null or empty. Make sure permission strings are properly formatted."); //報(bào)出此異常
        }
    }

回答
編輯回答
絯孑氣

原因找到了,一直將著力點(diǎn)找錯(cuò)了,其錯(cuò)誤的原因在獲取個(gè)人權(quán)限的地方?jīng)]有進(jìn)行權(quán)限判斷,只有在全局的權(quán)限添加進(jìn)行了判斷。

2018年9月21日 05:56