public boolean hasPermission(Page page) {
   Identity identity = getIdentity();
   if (PortalConfig.USER_TYPE.equals(page.getOwnerType())) {
     if (page.getOwnerId().equals(identity.getUserId())) {
       page.setModifiable(true);
       return true;
     }
   }
   if (superUser_.equals(identity.getUserId())) {
     page.setModifiable(true);
     return true;
   }
   if (hasEditPermission(page)) {
     page.setModifiable(true);
     return true;
   }
   page.setModifiable(false);
   String[] accessPerms = page.getAccessPermissions();
   if (accessPerms != null) {
     for (String per : accessPerms) {
       if (hasPermission(identity, per)) {
         return true;
       }
     }
   }
   return false;
 }
    @Override
    public void execute(Event<UIMeetingDetail> event) throws Exception {
      UIMeetingDetail detail = event.getSource();
      UIApplication uiApp = event.getRequestContext().getUIApplication();
      if (detail.selectedOptions.isEmpty()) {
        uiApp.addMessage(
            new ApplicationMessage(
                "You need to select at least one option",
                new Object[0],
                AbstractApplicationMessage.ERROR));
        return;
      }

      Identity identity = ConversationState.getCurrent().getIdentity();
      if (!identity.getUserId().equals(detail.getMeeting().getOwner())) {
        uiApp.addMessage(
            new ApplicationMessage(
                "Only owner can make plan for this meeting",
                new Object[0],
                AbstractApplicationMessage.ERROR));
        return;
      }

      MeetingService service = detail.getApplicationComponent(MeetingService.class);
      Meeting m =
          service.finalMeeting(detail.meeting, new ArrayList<String>(detail.selectedOptions));
      detail.setMeeting(m);
    }
 public ImpersonatedIdentity(
     Identity impersonatedIdentity, ConversationState parentConversationState) {
   super(
       impersonatedIdentity.getUserId(),
       impersonatedIdentity.getMemberships(),
       impersonatedIdentity.getRoles());
   this.parentConversationState = parentConversationState;
 }
 public boolean hasEditPermission(PageContext page) {
   PageKey key = page.getKey();
   Identity identity = getIdentity();
   if (SiteType.USER == key.getSite().getType()) {
     return key.getSite().getName().equals(identity.getUserId());
   } else {
     return hasPermission(identity, page.getState().getEditPermission());
   }
 }
 public static final String[] getUserGroups(String username) throws Exception {
   ConversationState conversationState = ConversationState.getCurrent();
   Identity identity = conversationState.getIdentity();
   Set<String> objs = identity.getGroups();
   String[] groups = new String[objs.size()];
   int i = 0;
   for (String obj : objs) {
     groups[i++] = obj;
   }
   return groups;
 }
 @Override
 public void execute(Event<UIMeetingDetail> event) throws Exception {
   String optionId = event.getRequestContext().getRequestParameter(OBJECTID);
   UIMeetingDetail detail = event.getSource();
   Identity identity = ConversationState.getCurrent().getIdentity();
   boolean isVoted = detail.meeting.isVotedOption(identity.getUserId(), optionId);
   MeetingService service = detail.getApplicationComponent(MeetingService.class);
   Map<String, String> voted = new HashMap<String, String>();
   voted.put(optionId, isVoted ? "0" : "1");
   Meeting meeting1 = service.updateVote(detail.meeting, identity.getUserId(), voted);
   detail.setMeeting(meeting1);
 }
Exemple #7
0
 /**
  * Can edit current portal.
  *
  * @param remoteUser the remote user
  * @return true, if successful
  * @throws Exception the exception
  */
 public static boolean canEditCurrentPortal(String remoteUser) throws Exception {
   if (remoteUser == null) return false;
   IdentityRegistry identityRegistry =
       Util.getUIPortalApplication().getApplicationComponent(IdentityRegistry.class);
   Identity identity = identityRegistry.getIdentity(remoteUser);
   if (identity == null) return false;
   UIPortal uiPortal = Util.getUIPortal();
   // this code only work for single edit permission
   String editPermission = uiPortal.getEditPermission();
   MembershipEntry membershipEntry = MembershipEntry.parse(editPermission);
   return identity.isMemberOf(membershipEntry);
 }
  @Override
  public List<org.exoplatform.calendar.model.Calendar> findCalendars(CalendarQuery query) {
    List<org.exoplatform.calendar.model.Calendar> calendars =
        new LinkedList<org.exoplatform.calendar.model.Calendar>();
    List<String> excludes = Collections.emptyList();
    String[] excludesId = query.getExclusions();
    if (excludesId != null) {
      excludes = Arrays.asList(excludesId);
    }

    try {
      Identity identity = query.getIdentity();
      List<Calendar> cals = dataStorage.getUserCalendars(identity.getUserId(), true);
      if (cals != null && cals.size() > 0) {
        for (Calendar c : cals) {
          if (!excludes.contains(c.getId())) {
            calendars.add(c);
          }
        }
      }

      GroupCalendarData data = dataStorage.getSharedCalendars(identity.getUserId(), true);
      if (data != null && data.getCalendars().size() > 0) {
        for (Calendar c : data.getCalendars()) {
          if (!excludes.contains(c.getId())) {
            calendars.add(c);
          }
        }
      }

      List<GroupCalendarData> datas =
          dataStorage.getGroupCalendars(
              identity.getGroups().toArray(new String[0]), true, identity.getUserId());
      if (datas != null && datas.size() > 0) {
        for (GroupCalendarData d : datas) {
          for (Calendar c : d.getCalendars()) {
            if (!excludes.contains(c.getId())) {
              calendars.add(c);
            }
          }
        }
      }

      for (org.exoplatform.calendar.model.Calendar cal : calendars) {
        cal.setDS(JCRStorage.JCR_STORAGE);
      }

      return calendars;
    } catch (Exception ex) {
      LOG.error(ex);
    }
    return null;
  }
  /**
   * Minh Hoang TO - This method is equivalent to <code>hasEditPermission(Page)</code>. It allows us
   * to check edit permission with a UIPage, without converting UIPage into Page via
   * PortalDataMapper
   */
  public boolean hasEditPermissionOnPage(
      String ownerType, String ownerId, String editPermExpression) {
    Identity identity = this.getIdentity();

    if (PortalConfig.USER_TYPE.equals(ownerType)) {
      if (ownerId.equals(identity.getUserId())) {
        return true;
      }
      return false;
    }

    return hasPermission(identity, editPermExpression);
  }
 /**
  * Decide if current user has permission to impersonate as another user
  *
  * @param userToImpersonate user, which we want to impersonate (Actually not used for this impl)
  * @return true if current user has permission to impersonate as userToImpersonate
  */
 public boolean hasImpersonateUserPermission(User userToImpersonate) {
   Identity identity = getIdentity();
   if (superUser_.equals(identity.getUserId())) {
     return true;
   }
   if (userImpersonateGroups_ == null || userImpersonateGroups_.size() < 1) {
     return false;
   }
   for (String ele : userImpersonateGroups_) {
     if (hasPermission(identity, ele)) {
       return true;
     }
   }
   return false;
 }
 public boolean hasCreatePortalPermission() {
   Identity identity = getIdentity();
   if (superUser_.equals(identity.getUserId())) {
     return true;
   }
   if (portalCreatorGroups_ == null || portalCreatorGroups_.size() < 1) {
     return false;
   }
   for (String ele : portalCreatorGroups_) {
     if (hasPermission(identity, ele)) {
       return true;
     }
   }
   return false;
 }
 public boolean hasPermission(String[] permissions) {
   Identity identity = this.getIdentity();
   String currentUser = identity.getUserId();
   if (superUser_.equals(currentUser)) {
     return true;
   } else if (permissions == null || permissions.length == 0) {
     return false;
   } else {
     for (String per : permissions) {
       if (hasPermission(identity, per)) {
         return true;
       }
     }
     return false;
   }
 }
 public boolean hasEditPermission(Page page) {
   Identity identity = getIdentity();
   if (PortalConfig.USER_TYPE.equals(page.getOwnerType())) {
     if (page.getOwnerId().equals(identity.getUserId())) {
       page.setModifiable(true);
       return true;
     }
     return false;
   }
   if (hasPermission(identity, page.getEditPermission())) {
     page.setModifiable(true);
     return true;
   }
   page.setModifiable(false);
   return false;
 }
 private void initDatas() {
   String str = "/:*.*";
   rand = new Random();
   Identity identity = ConversationState.getCurrent().getIdentity();
   currentUser = identity.getUserId();
   Set<String> set = new HashSet<String>(identity.getGroups());
   groupShare = new String[set.size() + 1];
   int i = 0;
   for (String string : set) {
     groupShare[i] = string + str;
     i++;
   }
   groupShare[i] = currentUser;
   set.add(currentUser);
   groups = set.toArray(new String[set.size()]);
 }
 private boolean hasPermission(String userName, Value[] roles) throws Exception {
   IdentityRegistry identityRegistry = getApplicationComponent(IdentityRegistry.class);
   if (IdentityConstants.SYSTEM.equalsIgnoreCase(userName)) {
     return true;
   }
   Identity identity = identityRegistry.getIdentity(userName);
   if (identity == null) {
     return false;
   }
   for (int i = 0; i < roles.length; i++) {
     String role = roles[i].getString();
     if ("*".equalsIgnoreCase(role)) return true;
     MembershipEntry membershipEntry = MembershipEntry.parse(role);
     if (membershipEntry == null) return false;
     if (identity.isMemberOf(membershipEntry)) {
       return true;
     }
   }
   return false;
 }
 public boolean hasPermission(Identity identity, String expPerm) {
   String currentUser = identity.getUserId();
   if (superUser_.equals(currentUser)) {
     return true;
   }
   if (expPerm == null) {
     return false;
   }
   if (EVERYONE.equals(expPerm)) {
     return true;
   }
   Permission permission = new Permission();
   permission.setPermissionExpression(expPerm);
   String groupId = permission.getGroupId();
   if ((currentUser == null || currentUser.equals(IdentityConstants.ANONIM))
       && groupId.equals(guestGroup_)) {
     return true;
   }
   String membership = permission.getMembership();
   return identity.isMemberOf(groupId, membership);
 }
  /**
   * @param group
   * @return
   */
  public boolean isUserInGroup(String group) {
    ConversationState conv = ConversationState.getCurrent();
    Identity id = null;
    if (conv != null) {
      id = conv.getIdentity();
    }

    if (id == null) {
      return false;
    }

    Iterator<String> iter = id.getGroups().iterator();

    while (iter.hasNext()) {
      if (iter.next().equals(group)) {
        return true;
      }
    }

    return false;
  }
  // copied from @link{#hasEditPermission}
  public boolean hasEditPermissionOnNavigation(SiteKey siteKey) {
    Identity identity = getIdentity();
    if (superUser_.equals(identity.getUserId())) {
      return true;
    }

    //
    switch (siteKey.getType()) {
      case PORTAL:
        // TODO: We should also take care of Portal's navigation
        return false;
      case GROUP:
        String temp = siteKey.getName().trim();
        String expAdminGroup = getAdminGroups();
        String expPerm = null;

        // Check to see whether current user is member of admin group or not,
        // if so grant
        // edit permission for group navigation for that user.
        if (expAdminGroup != null) {
          expAdminGroup = expAdminGroup.startsWith("/") ? expAdminGroup : "/" + expAdminGroup;
          expPerm = temp.startsWith("/") ? temp : "/" + temp;
          if (isUserInGroup(expPerm) && isUserInGroup(expAdminGroup)) {
            return true;
          }
        }

        expPerm =
            navigationCreatorMembershipType_ + (temp.startsWith("/") ? ":" + temp : ":/" + temp);
        return hasPermission(identity, expPerm);
      case USER:
        return siteKey.getName().equals(identity.getUserId());
      default:
        return false;
    }
  }
 public boolean hasPermission(PageContext page) {
   PageKey key = page.getKey();
   Identity identity = getIdentity();
   if (SiteType.USER == key.getSite().getType()) {
     if (key.getSite().getName().equals(identity.getUserId())) {
       return true;
     }
   }
   if (superUser_.equals(identity.getUserId())) {
     return true;
   }
   if (hasEditPermission(page)) {
     return true;
   }
   List<String> accessPerms = page.getState().getAccessPermissions();
   if (accessPerms != null) {
     for (String per : accessPerms) {
       if (hasPermission(identity, per)) {
         return true;
       }
     }
   }
   return false;
 }
 public boolean isSuperUser() {
   Identity identity = getIdentity();
   return superUser_.equals(identity.getUserId());
 }
Exemple #21
0
 public static List<String> getGroups() throws Exception {
   ConversationState conversationState = ConversationState.getCurrent();
   Identity identity = conversationState.getIdentity();
   Set<String> groups = identity.getGroups();
   return new ArrayList<String>(groups);
 }