1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.workflow;
16  
17  import com.liferay.portal.security.auth.PrincipalException;
18  import com.liferay.portal.security.permission.PermissionChecker;
19  import com.liferay.portal.security.permission.PermissionThreadLocal;
20  
21  import org.aspectj.lang.ProceedingJoinPoint;
22  
23  /**
24   * <a href="WorkflowPermissionAdvice.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
28  public class WorkflowPermissionAdvice {
29  
30      public Object invoke(ProceedingJoinPoint proceedingJoinPoint)
31          throws Throwable {
32  
33          String methodName = proceedingJoinPoint.getSignature().getName();
34          Object[] arguments = proceedingJoinPoint.getArgs();
35  
36          if (methodName.equals(_ASSIGN_WORKFLOW_TASK_TO_USER_METHOD_NAME)) {
37              long userId = (Long)arguments[1];
38  
39              PermissionChecker permissionChecker =
40                  PermissionThreadLocal.getPermissionChecker();
41  
42              if (permissionChecker.getUserId() != userId) {
43                  throw new PrincipalException();
44              }
45          }
46  
47          return proceedingJoinPoint.proceed();
48      }
49  
50      private static final String _ASSIGN_WORKFLOW_TASK_TO_USER_METHOD_NAME =
51          "assignWorkflowTaskToUser";
52  
53  }