Package org.nutz.integration.shiro

Source Code of org.nutz.integration.shiro.ShiroMethodInterceptor

package org.nutz.integration.shiro;

import java.lang.reflect.Method;

import org.apache.shiro.aop.MethodInvocation;
import org.apache.shiro.authz.AuthorizationException;
import org.nutz.aop.InterceptorChain;
import org.nutz.aop.MethodInterceptor;
import org.nutz.lang.Lang;

/**
* 将Shiro注解,映射为NutAop的拦截器
* @author wendal
*
*/
public class ShiroMethodInterceptor implements MethodInterceptor {

    public void filter(final InterceptorChain chain) throws Throwable {
       
      try {
            ShiroAnnotationsAuthorizingMethodInterceptor.defaultAuth.assertAuthorized(new MethodInvocation() {
             
                //这个方法不会被执行的.
              public Object proceed() throws Throwable {
                throw Lang.noImplement();
              }
             
              public Object getThis() {
                return chain.getCallingObj();
              }
             
              public Method getMethod() {
                return chain.getCallingMethod();
              }
             
              public Object[] getArguments() {
                return chain.getArgs();
              }
            });
        }
        catch (AuthorizationException e) {
            // TODO 该如何处理呢? 交给用户自定义?
            throw Lang.wrapThrow(e);
        }
      chain.doChain(); //继续下一个拦截器
  }

}
TOP

Related Classes of org.nutz.integration.shiro.ShiroMethodInterceptor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.