securityinterceptor.java

来自「一个很好的开源项目管理系统源代码」· Java 代码 · 共 60 行

JAVA
60
字号
package net.java.workeffort.service.security;import net.java.workeffort.infrastructure.context.RequestContextHolder;import net.java.workeffort.infrastructure.security.AuthorizationException;import org.aopalliance.intercept.MethodInterceptor;import org.aopalliance.intercept.MethodInvocation;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/** * The service security interceptor. * <p> * The sequence of events is: * <ul> * <li>invoke preMethodInvocation()</li> * <li>Proceed to the next interceptor in chain by invoking * <code>proceed()</code> which will generally invoke the actual method on the * target object</li> * <li>invoke postMethodInvocation()</li> * </ul> * @author Antony Joseph */public class SecurityInterceptor implements MethodInterceptor {    private static final Log logger = LogFactory            .getLog(SecurityInterceptor.class);    private IServiceAuthorizer serviceAuthorizer;    public Object invoke(MethodInvocation methodInvocation) throws Throwable {        if (logger.isInfoEnabled()) {            logger.info("method:" + methodInvocation.getMethod().getName()                    + ", target:"                    + methodInvocation.getThis().getClass().getName());        }        try {            serviceAuthorizer                    .preMethodInvocation(RequestContextHolder                            .getRequestContext().getSecurityProfile(),                            methodInvocation);            // proceed to the next interceptor in chain.            Object resultObject = methodInvocation.proceed();            serviceAuthorizer.postMethodInvocation(RequestContextHolder                    .getRequestContext().getSecurityProfile(),                    methodInvocation, resultObject);            return resultObject;        }        catch (AuthorizationException ae) {            logger.error(ae);            throw ae;        }    }    /**     * @param serviceAuthorizer The serviceAuthorizer to set.     */    public void setServiceAuthorizer(IServiceAuthorizer serviceAuthorizer) {        this.serviceAuthorizer = serviceAuthorizer;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?