NutzCN Logo
问答 NutShiroProcessor 抛异常是为啥
发布于 2860天前 作者 qq_a6702539 2144 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

在方法上插入下面的注解后保存的

@At("/delete")
    @RequiresPermissions("user.delete")
java.lang.IllegalArgumentException: org.apache.shiro.aop.MethodInvocation parameter incorrectly constructed.  getMethod() returned null
[2017-02-22 15:40:59]DEBUG org.nutz.mvc.impl.UrlMappingImpl : Found mapping for [GET] path=/login/logout : LoginController.logout(LoginController.java:87)
	at org.apache.shiro.aop.DefaultAnnotationResolver.getAnnotation(DefaultAnnotationResolver.java:58)
	at org.apache.shiro.aop.AnnotationMethodInterceptor.getAnnotation(AnnotationMethodInterceptor.java:148)
	at org.apache.shiro.aop.AnnotationMethodInterceptor.supports(AnnotationMethodInterceptor.java:134)
	at org.apache.shiro.authz.aop.AnnotationsAuthorizingMethodInterceptor.assertAuthorized(AnnotationsAuthorizingMethodInterceptor.java:99)
	at org.nutz.integration.shiro.NutShiroMethodInterceptor.assertAuthorized(NutShiroMethodInterceptor.java:40)
	at com.yling.common.processor.NutShiroProcessor.process(NutShiroProcessor.java:49)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
11 回复

为啥贴的的login/logout的报错?

我是测试的 只要加上shiro 的注解都会报这个错误

如下

2017-02-22 15:45:57]DEBUG org.nutz.mvc.impl.UrlMappingImpl : Found mapping for [GET] path=/user/delete : UserController.delete(UserController.java:58)
java.lang.IllegalArgumentException: org.apache.shiro.aop.MethodInvocation parameter incorrectly constructed.  getMethod() returned null
	at org.apache.shiro.aop.DefaultAnnotationResolver.getAnnotation(DefaultAnnotationResolver.java:58)
	at org.apache.shiro.aop.AnnotationMethodInterceptor.getAnnotation(AnnotationMethodInterceptor.java:148)
	at org.apache.shiro.aop.AnnotationMethodInterceptor.supports(AnnotationMethodInterceptor.java:134)
	at org.apache.shiro.authz.aop.AnnotationsAuthorizingMethodInterceptor.assertAuthorized(AnnotationsAuthorizingMethodInterceptor.java:99)
	at org.nutz.integration.shiro.NutShiroMethodInterceptor.assertAuthorized(NutShiroMethodInterceptor.java:40)
	at com.yling.common.processor.NutShiroProcessor.process(NutShiroProcessor.java:49)

是最新的插件吗?

是的 1.r.60
不过 NutShiroProcessor 是自己参照写的 不知道问题出在哪里
代码如下

public class NutShiroProcessor extends AbstractProcessor
{
    protected NutShiroMethodInterceptor interceptor;
    protected String loginUri = "/login";
    protected String noAuthUri = "/noPermission";
    protected boolean match;
    protected boolean init;

    public NutShiroProcessor()
    {
        this.interceptor = new NutShiroMethodInterceptor();
    }

    public void init(NutConfig config, ActionInfo ai) throws Throwable {
        if (init) // 禁止重复初始化,常见于ioc注入且使用了单例
            throw new IllegalStateException("this Processor have bean inited!!");
        super.init(config, ai);
        match = NutShiro.match(ai.getMethod());
        init = true;
    }

    @Override
    public void process(ActionContext ac) throws Throwable
    {
        if (match) {
            try {
                interceptor.assertAuthorized(new NutShiroInterceptor(ac));
            } catch (Exception e) {
                e.printStackTrace();
                whenException(ac, e);
                return;
            }
        }
        doNext(ac);
    }

    protected void whenException(ActionContext ac, Exception e) throws Throwable {
        Object val = ac.getRequest().getAttribute("shiro_auth_error");
        if (val != null && val instanceof View) {
            ((View) val).render(ac.getRequest(), ac.getResponse(), null);
            return;
        }
        if (e instanceof UnauthenticatedException) {
            whenUnauthenticated(ac, (UnauthenticatedException) e);
        } else if (e instanceof UnauthorizedException) {
            whenUnauthorized(ac, (UnauthorizedException) e);
        } else {
            whenOtherException(ac, e);
        }
    }

    protected void whenUnauthenticated(ActionContext ac, UnauthenticatedException e) throws Exception {
        if (NutShiro.isAjax(ac.getRequest())) {
            ac.getResponse().addHeader("loginStatus", "accessDenied");
            NutShiro.rendAjaxResp(ac.getRequest(), ac.getResponse(), Result.error("登录失效"));
        } else {
            new ServerRedirectView(loginUri).render(ac.getRequest(), ac.getResponse(), null);
        }
    }

    protected void whenUnauthorized(ActionContext ac, UnauthorizedException e) throws Exception {
        if (NutShiro.isAjax(ac.getRequest())) {
            ac.getResponse().addHeader("loginStatus", "unauthorized");
            NutShiro.rendAjaxResp(ac.getRequest(), ac.getResponse(), Result.error("没有权限"));
        } else {
            new ServerRedirectView(noAuthUri).render(ac.getRequest(), ac.getResponse(), null);
        }
    }

    protected void whenOtherException(ActionContext ac, Exception e) throws Exception {
        if (NutShiro.isAjax(ac.getRequest())) {
            ac.getResponse().addHeader("loginStatus", "accessDenied");
            NutShiro.rendAjaxResp(ac.getRequest(), ac.getResponse(), Result.error("登录失效"));
        } else {
            new ServerRedirectView(loginUri).render(ac.getRequest(), ac.getResponse(), null);
        }
    }
}

要不先用原版测试一下?

换成原版的后,加上断点也是这里抛一样的异常

var chain = {
    "default": {
        "ps": [
            "org.nutz.integration.shiro.NutShiroProcessor",
            "org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor",
            "org.nutz.mvc.impl.processor.EncodingProcessor",
            "org.nutz.mvc.impl.processor.ModuleProcessor",
            "org.nutz.mvc.impl.processor.ActionFiltersProcessor",
            "org.nutz.mvc.impl.processor.AdaptorProcessor",
            "org.nutz.mvc.impl.processor.MethodInvokeProcessor",
            "org.nutz.mvc.impl.processor.ViewProcessor"
        ],
        "error": 'com.yling.common.processor.FailProcessor'
    }
};

shiro 配置

[main]
# Session
sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager

# cacheManager
cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
cacheManager.cacheManagerConfigFile=classpath:ehcache.xml

# Session Cache
sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
sessionDAO.cacheManager=$cacheManager
sessionManager.sessionDAO = $sessionDAO
securityManager.sessionManager = $sessionManager

# use R.UU32()
sessionIdGenerator = org.nutz.integration.shiro.UU32SessionIdGenerator
securityManager.sessionManager.sessionDAO.sessionIdGenerator = $sessionIdGenerator

# cookie
sessionIdCookie=org.apache.shiro.web.servlet.SimpleCookie
sessionIdCookie.name=sid
sessionIdCookie.maxAge=946080000
sessionIdCookie.httpOnly=true
sessionManager.sessionIdCookie=$sessionIdCookie
sessionManager.sessionIdCookieEnabled=true
sessionManager.globalSessionTimeout=3600000

sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
sha256Matcher.storedCredentialsHexEncoded = false
sha256Matcher.hashIterations = 1024
sha256Matcher.hashSalted = true

daoAuthRealm = com.yling.common.shiro.realm.DaoAuthRealm
daoAuthRealm.credentialsMatcher = $sha256Matcher
securityManager.realms = $daoAuthRealm
securityManager.cacheManager = $cacheManager

authc = org.nutz.integration.shiro.SimpleAuthenticationFilter
authc.loginUrl  = /login

[urls]
/assets/** = anon
/index.html = anon
/login/doLogin = anon
/login/regist = anon
/sysError = anon
/userError = anon
/noPermission = anon
/** = authc

动作链内的位置错了啊

放在ActionFiltersProcessor之前就好了

牛,你一说我才看出来。。。 灰常感谢

添加回复
请先登陆
回到顶部