Exemplo n.º 1
0
 /**
  * Checks permissions on a variable number of targets.This is provided as an extension to Seam's
  * single target permission capabilities.
  *
  * @param action The permission action.
  * @param targets Targets for permissions.
  * @throws NotLoggedInException if not authorised and not logged in
  * @throws org.zanata.exception.AuthorizationException if logged in but not authorised
  */
 public void checkPermission(String action, Object... targets) {
   try {
     internalCheckPermission(MultiTargetList.fromTargets(targets), action);
   } catch (AuthorizationException exception) {
     // try to produce a better than default error message
     List<String> meaningfulTargets = Lists.newArrayList();
     for (Object target : targets) {
       if (target instanceof HasUserFriendlyToString) {
         String targetString = ((HasUserFriendlyToString) target).userFriendlyToString();
         meaningfulTargets.add(targetString);
       } else {
         log.warn(
             "target [{}] may not have user friendly string representation", target.getClass());
         meaningfulTargets.add(target.toString());
       }
     }
     throw new AuthorizationException(
         String.format(
             "Failed to obtain permission('%s') with following facts(%s)",
             action, meaningfulTargets));
   }
 }
Exemplo n.º 2
0
 /**
  * Indicates if the user has permission to perform an action on a variable number of targets. This
  * is provided as an extension to Seam's single target permission capabilities.
  *
  * @param action The permission action.
  * @param targets Targets for permissions.
  */
 public boolean hasPermissionWithAnyTargets(String action, Object... targets) {
   return hasPermission(MultiTargetList.fromTargets(targets), action);
 }