001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.workflow;
016    
017    import com.liferay.portal.security.auth.PrincipalException;
018    import com.liferay.portal.security.permission.PermissionChecker;
019    import com.liferay.portal.security.permission.PermissionThreadLocal;
020    
021    import org.aspectj.lang.ProceedingJoinPoint;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class WorkflowPermissionAdvice {
027    
028            public Object invoke(ProceedingJoinPoint proceedingJoinPoint)
029                    throws Throwable {
030    
031                    String methodName = proceedingJoinPoint.getSignature().getName();
032                    Object[] arguments = proceedingJoinPoint.getArgs();
033    
034                    if (methodName.equals(_ASSIGN_WORKFLOW_TASK_TO_USER_METHOD_NAME)) {
035                            long userId = (Long)arguments[1];
036    
037                            PermissionChecker permissionChecker =
038                                    PermissionThreadLocal.getPermissionChecker();
039    
040                            if (permissionChecker.getUserId() != userId) {
041                                    throw new PrincipalException();
042                            }
043                    }
044    
045                    return proceedingJoinPoint.proceed();
046            }
047    
048            private static final String _ASSIGN_WORKFLOW_TASK_TO_USER_METHOD_NAME =
049                    "assignWorkflowTaskToUser";
050    
051    }