public Object invoke(MethodInvocation invocation) throws Throwable {
    String userId = getUserId();

    boolean setUser = false;
    if (!StringUtils.isEmpty(userId)) {
      final PropertyLayer layer = PropertyLayerProviderInterceptor.getCurrent();

      Map loginProperties = new HashMap();
      LoginUtils.mergeDefaultCredentials(loginProperties);
      /*
               loginProperties.put(SecurityProperties.PARTITION, partitionId);
               loginProperties.put(SecurityProperties.REALM, realmId);
               loginProperties.put(SecurityProperties.DOMAIN, domainId);
      */
      IAuditTrailPartition partition =
          LoginUtils.findPartition(invocation.getParameters(), loginProperties);
      IUserDomain domain =
          LoginUtils.findUserDomain(invocation.getParameters(), partition, loginProperties);

      layer.setProperty(SecurityProperties.CURRENT_PARTITION, partition);
      layer.setProperty(SecurityProperties.CURRENT_PARTITION_OID, new Short(partition.getOID()));
      layer.setProperty(SecurityProperties.CURRENT_DOMAIN, domain);
      layer.setProperty(SecurityProperties.CURRENT_DOMAIN_OID, new Long(domain.getOID()));

      IModel model = ModelManagerFactory.getCurrent().findActiveModel();
      if (model == null) {
        model = ModelManagerFactory.getCurrent().findLastDeployedModel();
      }

      IUser user =
          SynchronizationService.synchronize(
              userId,
              model,
              invocation
                  .getParameters()
                  .getBoolean(SecurityProperties.AUTHORIZATION_SYNC_LOGIN_PROPERTY, true),
              loginProperties);

      layer.setProperty(SecurityProperties.CURRENT_USER, user);

      // clean thread, so nested calls won't reuse the user ID
      setUser = true;
      resetUserId();
    }

    try {
      return invocation.proceed();
    } finally {
      if (setUser) {
        // restore thread status
        setUserId(userId);
      }
    }
  }
  public static void performTransition(
      ActivityInstanceBean activityInstance, TransitionTarget transitionTarget, boolean complete) {
    ExecutionPlan plan = new ExecutionPlan(transitionTarget);
    plan.assertNoOtherActiveActivities();

    ModelManager mm = ModelManagerFactory.getCurrent();
    IActivity target =
        mm.findActivity(transitionTarget.getModelOid(), transitionTarget.getActivityRuntimeOid());
    if (target == null) {
      throw new ObjectNotFoundException(
          BpmRuntimeError.MDL_UNKNOWN_ACTIVITY_IN_MODEL.raise(
              transitionTarget.getActivityRuntimeOid(), transitionTarget.getModelOid()));
    }

    BpmRuntimeEnvironment rtEnv = PropertyLayerProviderInterceptor.getCurrent();
    ExecutionPlan oldPlan = rtEnv.getExecutionPlan();
    try {
      rtEnv.setExecutionPlan(plan);
      if (complete) {
        ActivityInstanceUtils.complete(activityInstance, null, null, true);
      } else {
        long rootOid = plan.getRootActivityInstanceOid();
        if (rootOid != activityInstance.getOID()) {
          activityInstance = ActivityInstanceUtils.lock(rootOid);
        }
        ActivityInstanceUtils.abortActivityInstance(activityInstance);
      }
    } finally {
      rtEnv.setExecutionPlan(oldPlan);
    }
  }