Esempio n. 1
0
  @Override
  public void inject(HashMap<String, String> params) throws Exception {
    int number = getIntParam(params, NUMBER);
    String prefix = getStringValueParam(params, PREFIX, DEFAULT_GROUP_PREFIX);
    init(prefix, null, null, null, null);

    for (int i = 1; i <= number; i++) {
      //
      String groupName = groupName();
      Group group = groupHandler.createGroupInstance();
      group.setGroupName(groupName);
      group.setLabel(groupName);
      group.setDescription(groupName);
      try {
        // Save group
        groupHandler.addChild(null, group, true);
        //
        ++groupNumber;

      } catch (Exception e) {
        getLog().error(e);
      }

      //
      getLog().info("Group '" + groupName + "' generated");
    }
  }
Esempio n. 2
0
 public static List<String> getAllGroupId() throws Exception {
   List<String> grIds = new ArrayList<String>();
   for (Group gr : getAllGroup()) {
     grIds.add(gr.getId());
   }
   return grIds;
 }
 /**
  * Get path of the group in tree.
  *
  * @param list
  * @param id
  * @return
  * @throws Exception
  */
 private List<LocalPath> getPath(List<LocalPath> list, String id) throws Exception {
   if (list == null) list = new ArrayList<LocalPath>(5);
   if (id == null) return list;
   OrganizationService service = getApplicationComponent(OrganizationService.class);
   Group group = service.getGroupHandler().findGroupById(id);
   if (group == null) return list;
   list.add(0, new LocalPath(group.getId(), group.getGroupName()));
   getPath(list, group.getParentId());
   return list;
 }
Esempio n. 4
0
 private List<SelectItemOption<String>> getGroups() throws Exception {
   List<SelectItemOption<String>> options = new ArrayList<SelectItemOption<String>>();
   OrganizationService orgService = CalendarUtils.getOrganizationService();
   options.add(new SelectItemOption<String>("all", "all"));
   for (Object g : orgService.getGroupHandler().getAllGroups()) {
     Group cg = (Group) g;
     options.add(new SelectItemOption<String>(cg.getGroupName(), cg.getId()));
   }
   return options;
 }
Esempio n. 5
0
  /** {@inheritDoc} */
  public ListAccess<Membership> findAllMembershipsByGroup(Group group) throws Exception {
    String findQuery =
        "select m from m in class org.exoplatform.services.organization.impl.MembershipImpl where m.groupId = '"
            + group.getId()
            + "'";

    String countQuery =
        "select count(m) from m in class org.exoplatform.services.organization.impl.MembershipImpl where m.groupId = '"
            + group.getId()
            + "'";

    return new HibernateListAccess<Membership>(service_, findQuery, countQuery);
  }
Esempio n. 6
0
  public void setValues(Group group) throws Exception {
    PageList pageList = null;
    if (group == null) {
      pageList = EmptySerializablePageList.get();
    } else {
      OrganizationService service = getApplicationComponent(OrganizationService.class);
      MembershipHandler handler = service.getMembershipHandler();
      ListAccess<?> list = handler.findAllMembershipsByGroup(group);
      pageList =
          new FindMembershipByGroupPageList(
              group.getId(), list.getSize() > 10 ? list.getSize() : 10);
    }
    UIGridUser uiGrid = getChild(UIGridUser.class);
    pageList.setPageSize(5);

    UIPageIterator pageIterator = uiGrid.getUIPageIterator();
    /** We keep the currently selected page index * */
    int backupPageIndex = pageIterator.getCurrentPage();
    pageIterator.setPageList(pageList);

    if (group != null) {
      String groupId = group.getId();
      String currentUser = Util.getPortalRequestContext().getRemoteUser();

      // show action if user is administrator or manager of current group
      boolean showAction =
          GroupManagement.isAdministrator(currentUser)
              || GroupManagement.isManagerOfGroup(currentUser, groupId);

      if (!showAction) {
        pageList.setPageSize(10);
        if (getChild(UIGroupMembershipForm.class) != null) removeChild(UIGroupMembershipForm.class);
        uiGrid.configure("id", USER_BEAN_FIELD, null);
      } else {
        pageList.setPageSize(5);
        uiGrid.configure("id", USER_BEAN_FIELD, USER_ACTION);
        if (getChild(UIGroupMembershipForm.class) == null)
          addChild(UIGroupMembershipForm.class, null, null);
      }
    } else {
      pageList.setPageSize(10);
      if (getChild(UIGroupMembershipForm.class) != null) removeChild(UIGroupMembershipForm.class);
    }

    /** Reset the selected page index * */
    if (backupPageIndex > pageIterator.getAvailablePage()) {
      backupPageIndex = pageIterator.getAvailablePage();
    }
    pageIterator.setCurrentPage(backupPageIndex);
  }
Esempio n. 7
0
 @SuppressWarnings("unchecked")
 public List<String> getListGroup() throws Exception {
   OrganizationService service = WCMCoreUtils.getService(OrganizationService.class);
   List<String> listGroup = new ArrayList<String>();
   if (getCurrentGroup() == null) return null;
   Collection<Object> groups = service.getGroupHandler().findGroups(getCurrentGroup());
   if (groups.size() > 0) {
     for (Object child : groups) {
       Group childGroup = (Group) child;
       listGroup.add(childGroup.getId());
     }
   }
   return listGroup;
 }
Esempio n. 8
0
  public void changeGroup(String groupId) throws Exception {
    OrganizationService service = WCMCoreUtils.getService(OrganizationService.class);
    UIBreadcumbs uiBreadcumb = getChild(UIBreadcumbs.class);
    uiBreadcumb.setPath(getPath(null, groupId));

    UITree tree = getChild(UITree.class);
    Collection<?> sibblingGroup;

    if (groupId == null) {
      sibblingGroup = service.getGroupHandler().findGroups(null);
      tree.setSibbling((List) sibblingGroup);
      tree.setChildren(null);
      tree.setSelected(null);
      selectGroup_ = null;
      return;
    }

    selectGroup_ = service.getGroupHandler().findGroupById(groupId);
    String parentGroupId = null;
    if (selectGroup_ != null) parentGroupId = selectGroup_.getParentId();
    Group parentGroup = null;
    if (parentGroupId != null) parentGroup = service.getGroupHandler().findGroupById(parentGroupId);

    Collection childrenGroup = service.getGroupHandler().findGroups(selectGroup_);
    sibblingGroup = service.getGroupHandler().findGroups(parentGroup);

    tree.setSibbling((List) sibblingGroup);
    tree.setChildren((List) childrenGroup);
    tree.setSelected(selectGroup_);
    tree.setParentSelected(parentGroup);
  }
Esempio n. 9
0
  /** {@inheritDoc} */
  public void linkMembership(User user, Group g, MembershipType mt, boolean broadcast)
      throws Exception {
    if (user == null) {
      throw new InvalidNameException("Can not create membership record because user is null");
    }

    if (g == null) {
      throw new InvalidNameException(
          "Can not create membership record for " + user.getUserName() + " because group is null");
    }

    if (mt == null) {
      throw new InvalidNameException(
          "Can not create membership record for "
              + user.getUserName()
              + " because membership type is null");
    }

    MembershipImpl membership = new MembershipImpl();
    membership.setUserName(user.getUserName());
    membership.setMembershipType(mt.getName());
    membership.setGroupId(g.getId());
    membership.setId(IdentifierUtil.generateUUID(membership));
    createMembership(membership, broadcast);
  }
  /**
   * Reset tree into the current selected group.
   *
   * @param groupId
   * @throws Exception
   */
  @SuppressWarnings("unchecked")
  private void changeGroup(String groupId) throws Exception {
    OrganizationService service = getApplicationComponent(OrganizationService.class);
    UIBreadcumbs uiBreadcumb = getChild(UIBreadcumbs.class);
    uiBreadcumb.setPath(getPath(null, groupId));

    UITree tree = getChild(UIFilterableTree.class);
    Collection<?> sibblingGroup;

    if (groupId == null) {
      sibblingGroup = service.getGroupHandler().findGroups(null);
      tree.setSibbling((List) sibblingGroup);
      tree.setChildren(null);
      tree.setSelected(null);
      selectGroup_ = null;
      return;
    }

    selectGroup_ = service.getGroupHandler().findGroupById(groupId);
    String parentGroupId = null;
    if (selectGroup_ != null) parentGroupId = selectGroup_.getParentId();
    Group parentGroup = null;
    if (parentGroupId != null) parentGroup = service.getGroupHandler().findGroupById(parentGroupId);

    Collection childrenGroup = service.getGroupHandler().findGroups(selectGroup_);
    sibblingGroup = service.getGroupHandler().findGroups(parentGroup);

    tree.setSibbling((List) sibblingGroup);
    tree.setChildren((List) childrenGroup);
    tree.setSelected(selectGroup_);
    tree.setParentSelected(parentGroup);
  }
  public ListAccess<Membership> findAllMembershipsByGroup(Group group) throws Exception {
    String plGroupName = getPLIDMGroupName(getGroupNameFromId(group.getId()));

    String gid =
        getIdentitySession()
            .getPersistenceManager()
            .createGroupKey(plGroupName, getGroupTypeFromId(group.getId()));

    org.picketlink.idm.api.Group gtnGroup =
        service_.getIdentitySession().getPersistenceManager().findGroupByKey(gid);

    if (gtnGroup == null) {
      log.log(LogLevel.ERROR, "Internal ERROR. Cannot obtain group: " + group.getId());
      return new ListAccessImpl(Membership.class, Collections.emptyList());
    }
    return new IDMMembershipListAccess(
        gtnGroup, !orgService.getConfiguration().isSkipPaginationInMembershipQuery());
  }
  public List<String> getListGroup() throws Exception {
    OrganizationService service = getApplicationComponent(OrganizationService.class);
    List<String> listGroup = new ArrayList<String>();
    RequestContext reqCtx = RequestContext.getCurrentInstance();
    String remoteUser = reqCtx.getRemoteUser();
    if (getCurrentGroup() == null) return null;
    Collection<Group> groups = service.getGroupHandler().findGroups(getCurrentGroup());
    if (groups.size() > 0) {
      for (Object child : groups) {
        Group childGroup = (Group) child;
        Membership membership = getMemberShip(remoteUser, childGroup.getId());

        if (membership != null) {
          listGroup.add(childGroup.getId());
        }
      }
    }
    return listGroup;
  }
Esempio n. 13
0
 @SuppressWarnings("unchecked")
 private boolean isMandatory(GroupHandler groupHandler, Group group, List<String> mandatories)
     throws Exception {
   if (mandatories.contains(group.getId())) return true;
   Collection<Group> children = groupHandler.findGroups(group);
   for (Group g : children) {
     if (isMandatory(groupHandler, g, mandatories)) return true;
   }
   return false;
 }
Esempio n. 14
0
  @Override
  protected String loadConfirmMesssage(
      org.exoplatform.webui.config.Event event, WebuiRequestContext context, String beanId) {

    String confirm = event.getConfirm();
    if (confirm.length() < 1) return confirm;
    UIGridUser uiGrid = getChild(UIGridUser.class);
    try {
      confirm = context.getApplicationResourceBundle().getString(confirm);
      MembershipUser membershipUser = uiGrid.searchMembershipUser(beanId);
      if (membershipUser == null) return confirm;
      Group selectGroup = getSelectedGroup();
      if (selectGroup == null) return confirm;
      confirm = confirm.replaceAll("\\{0\\}", membershipUser.getUserName());
      confirm = confirm.replaceAll("\\{1\\}", selectGroup.getId().substring(1));
    } catch (Exception e) {

    }
    return confirm;
  }
  public Collection removeMembershipByUser(String userName, boolean broadcast) throws Exception {

    if (log.isTraceEnabled()) {
      Tools.logMethodIn(
          log,
          LogLevel.TRACE,
          "removeMembershipByUser",
          new Object[] {"userName", userName, "broadcast", broadcast});
    }

    orgService.flush();

    Collection<Role> roles = new HashSet();

    try {
      roles = getIdentitySession().getRoleManager().findRoles(userName, null);
    } catch (Exception e) {
      // TODO:
      handleException("Identity operation error: ", e);
    }

    HashSet<MembershipImpl> memberships = new HashSet<MembershipImpl>();

    for (Role role : roles) {
      MembershipImpl m = new MembershipImpl();
      Group g = ((GroupDAOImpl) orgService.getGroupHandler()).convertGroup(role.getGroup());
      m.setGroupId(g.getId());
      m.setUserName(role.getUser().getId());
      m.setMembershipType(role.getRoleType().getName());
      memberships.add(m);

      if (broadcast) {
        preDelete(m);
      }

      getIdentitySession().getRoleManager().removeRole(role);

      if (broadcast) {
        postDelete(m);
      }
    }

    if (isAssociationMapped()) {

      Collection<org.picketlink.idm.api.Group> groups = new HashSet();

      try {
        groups = getIdentitySession().getRelationshipManager().findAssociatedGroups(userName, null);
      } catch (Exception e) {
        // TODO:
        handleException("Identity operation error: ", e);
      }

      Set<String> keys = new HashSet<String>();
      keys.add(userName);

      for (org.picketlink.idm.api.Group group : groups) {
        try {
          getIdentitySession()
              .getRelationshipManager()
              .disassociateUsersByKeys(group.getKey(), keys);
        } catch (Exception e) {
          // TODO:
          handleException("Identity operation error: ", e);
        }
      }
    }

    // TODO: Exo UI has hardcoded casts to List
    return new LinkedList(memberships);
  }
Esempio n. 16
0
 /** {@inheritDoc} */
 public Collection<?> findMembershipsByGroup(Group group) throws Exception {
   Session session = service_.openSession();
   List<?> memberships =
       session.createQuery(queryFindMembershipsByGroup).setString("groupid", group.getId()).list();
   return memberships;
 }
Esempio n. 17
0
 static void removeMembershipEntriesOfGroup(Group group, Session session) throws Exception {
   List<?> entries =
       session.createQuery(queryFindMembershipsByGroup).setString("groupid", group.getId()).list();
   for (int i = 0; i < entries.size(); i++) session.delete(entries.get(i));
 }
  public Collection findMembershipsByUser(String userName) throws Exception {
    if (log.isTraceEnabled()) {
      Tools.logMethodIn(
          log, LogLevel.TRACE, "findMembershipsByUser", new Object[] {"userName", userName});
    }

    orgService.flush();

    Collection<Role> roles = new HashSet();

    try {
      roles = getIdentitySession().getRoleManager().findRoles(userName, null);
    } catch (Exception e) {
      // TODO:
      handleException("Identity operation error: ", e);
    }

    HashSet<MembershipImpl> memberships = new HashSet<MembershipImpl>();

    for (Role role : roles) {
      Group g = ((GroupDAOImpl) orgService.getGroupHandler()).convertGroup(role.getGroup());
      if (isCreateMembership(role.getRoleType().getName(), g.getId())) {
        MembershipImpl m = new MembershipImpl();
        m.setGroupId(g.getId());
        m.setUserName(role.getUser().getId());

        // LDAP store may return raw membership type as role type
        if (role.getRoleType().getName().equals("JBOSS_IDENTITY_MEMBERSHIP")) {
          m.setMembershipType(orgService.getConfiguration().getAssociationMembershipType());
        } else {
          m.setMembershipType(role.getRoleType().getName());
        }

        memberships.add(m);
      }
    }

    if (isAssociationMapped()) {

      Collection<org.picketlink.idm.api.Group> groups = new HashSet();

      try {
        groups = getIdentitySession().getRelationshipManager().findAssociatedGroups(userName, null);
      } catch (Exception e) {
        // TODO:
        handleException("Identity operation error: ", e);
      }

      for (org.picketlink.idm.api.Group group : groups) {
        MembershipImpl m = new MembershipImpl();
        Group g = ((GroupDAOImpl) orgService.getGroupHandler()).convertGroup(group);
        m.setGroupId(g.getId());
        m.setUserName(userName);
        m.setMembershipType(getAssociationMapping());
        memberships.add(m);
      }
    }

    Collection result = new LinkedList(memberships);

    if (log.isTraceEnabled()) {
      Tools.logMethodOut(log, LogLevel.TRACE, "findMembershipsByUser", result);
    }

    return result;
  }
 public Collection findMembershipsByGroup(Group group) throws Exception {
   return findMembershipsByGroupId(group.getId());
 }
Esempio n. 20
0
    public void execute(Event<UISpaceInfo> event) throws Exception {
      UISpaceInfo uiSpaceInfo = event.getSource();
      SpaceService spaceService = uiSpaceInfo.getSpaceService();
      UIPortal uiPortal = Util.getUIPortal();

      String id = uiSpaceInfo.getUIStringInput(SPACE_ID).getValue();
      String name = uiSpaceInfo.getUIStringInput(SPACE_DISPLAY_NAME).getValue();
      Space space = spaceService.getSpaceById(id);
      String oldDisplayName = space.getDisplayName();
      String existingDescription = space.getDescription();

      if (space == null) {
        // redirect to spaces
        event.getRequestContext().sendRedirect(Utils.getURI("all-spaces"));
        return;
      }

      UserNode selectedNode = uiPortal.getSelectedUserNode();
      UserNode renamedNode = null;

      boolean nameChanged = (!space.getDisplayName().equals(name));
      UIPortletApplication uiApp = uiSpaceInfo.getAncestorOfType(UIPortletApplication.class);
      if (nameChanged) {

        String cleanedString = SpaceUtils.cleanString(name);
        if (spaceService.getSpaceByUrl(cleanedString) != null) {
          // reset to origin values
          uiSpaceInfo.getUIStringInput(SPACE_DISPLAY_NAME).setValue(oldDisplayName);
          uiSpaceInfo.getUIFormTextAreaInput(SPACE_DESCRIPTION).setValue(existingDescription);

          //
          uiApp.addMessage(
              new ApplicationMessage(
                  "UISpaceInfo.msg.current-name-exist", null, ApplicationMessage.INFO));
          return;
        }

        renamedNode = uiSpaceInfo.renamePageNode(name, space);
        if (renamedNode == null) {
          return;
        }
      }
      uiSpaceInfo.invokeSetBindingBean(space);

      String spaceDescription = space.getDescription();
      if (spaceDescription == null || spaceDescription.trim().length() == 0) {
        ResourceBundle resourceBundle = event.getRequestContext().getApplicationResourceBundle();
        space.setDescription(resourceBundle.getString(MSG_DEFAULT_SPACE_DESCRIPTION));
        uiSpaceInfo.getUIFormTextAreaInput(SPACE_DESCRIPTION).setValue(space.getDescription());
      } else {
        space.setDescription(StringEscapeUtils.escapeHtml(space.getDescription()));
        if (!existingDescription.equals(spaceDescription)) {
          space.setField(UpdatedField.DESCRIPTION);
        }
      }

      space.setEditor(Utils.getViewerRemoteId());

      if (nameChanged) {
        space.setDisplayName(oldDisplayName);
        String remoteId = Utils.getViewerRemoteId();
        spaceService.renameSpace(remoteId, space, name);

        // rename group label
        OrganizationService organizationService =
            (OrganizationService)
                ExoContainerContext.getCurrentContainer()
                    .getComponentInstanceOfType(OrganizationService.class);
        GroupHandler groupHandler = organizationService.getGroupHandler();
        Group group = groupHandler.findGroupById(space.getGroupId());
        group.setLabel(space.getDisplayName());
        groupHandler.saveGroup(group, true);
      } else {
        spaceService.updateSpace(space);
      }

      if (nameChanged) {
        if (renamedNode != null) {
          // update space navigation (change name).
          selectedNode = renamedNode;
          PortalRequestContext prContext = Util.getPortalRequestContext();
          prContext.createURL(NodeURL.TYPE).setNode(selectedNode);
          event.getRequestContext().sendRedirect(Utils.getSpaceURL(selectedNode));
          return;
        }
      } else {
        uiApp.addMessage(
            new ApplicationMessage(
                "UISpaceInfo.msg.update-success", null, ApplicationMessage.INFO));
      }
    }
  public void linkMembership(User user, Group g, MembershipType mt, boolean broadcast)
      throws Exception {
    if (log.isTraceEnabled()) {
      Tools.logMethodIn(
          log,
          LogLevel.TRACE,
          "linkMembership",
          new Object[] {"user", user, "group", g, "membershipType", mt, "broadcast", broadcast});
    }

    orgService.flush();

    if (user == null) {
      throw new InvalidNameException("Can not create membership record because user is null");
    }
    if (orgService.getUserHandler().findUserByName(user.getUserName()) == null) {
      throw new InvalidNameException(
          "Can not create membership record because user "
              + user.getUserName()
              + " does not exist.");
    }

    if (g == null) {
      throw new InvalidNameException(
          "Can not create membership record for " + user.getUserName() + " because group is null");
    }
    // Check group exist
    Group g1 = this.orgService.getGroupHandler().findGroupById(g.getId());
    if (g1 == null) {
      throw new InvalidNameException(
          "Can not create membership record for "
              + user.getUserName()
              + " because group "
              + g.getGroupName()
              + " is not exist");
    }

    if (mt == null) {
      throw new InvalidNameException(
          "Can not create membership record for "
              + user.getUserName()
              + " because membership type is null");
    }

    if (orgService.getMembershipTypeHandler().findMembershipType(mt.getName()) == null) {
      throw new InvalidNameException("MembershipType doesn't exist: " + mt.getName());
    }

    String plGroupName = getPLIDMGroupName(g.getGroupName());

    String groupId =
        getIdentitySession()
            .getPersistenceManager()
            .createGroupKey(
                plGroupName, orgService.getConfiguration().getGroupType(g.getParentId()));

    if (isCreateMembership(mt.getName(), g.getId())) {
      if (getIdentitySession().getRoleManager().getRoleType(mt.getName()) == null) {
        getIdentitySession().getRoleManager().createRoleType(mt.getName());
      }

      if (getIdentitySession()
          .getRoleManager()
          .hasRole(user.getUserName(), groupId, mt.getName())) {
        return;
      }
    }

    if (isAssociationMapped() && getAssociationMapping().equals(mt.getName())) {
      getIdentitySession()
          .getRelationshipManager()
          .associateUserByKeys(groupId, user.getUserName());
    }

    MembershipImpl membership = new MembershipImpl();
    membership.setMembershipType(mt.getName());
    membership.setUserName(user.getUserName());
    membership.setGroupId(g.getId());

    if (broadcast) {
      preSave(membership, true);
    }

    if (isCreateMembership(mt.getName(), g.getId())) {
      getIdentitySession().getRoleManager().createRole(mt.getName(), user.getUserName(), groupId);
    }

    if (broadcast) {
      postSave(membership, true);
    }
  }
  public Collection findMembershipsByGroupId(String groupId) throws Exception {
    if (log.isTraceEnabled()) {
      Tools.logMethodIn(
          log, LogLevel.TRACE, "findMembershipsByGroup", new Object[] {"groupId", groupId});
    }

    orgService.flush();

    String plGroupName = getPLIDMGroupName(getGroupNameFromId(groupId));

    String gid =
        getIdentitySession()
            .getPersistenceManager()
            .createGroupKey(plGroupName, getGroupTypeFromId(groupId));

    Collection<Role> roles = new HashSet();

    try {
      roles = getIdentitySession().getRoleManager().findRoles(gid, null);
    } catch (Exception e) {
      // TODO:
      handleException("Identity operation error: ", e);
    }

    HashSet<MembershipImpl> memberships = new HashSet<MembershipImpl>();

    Group g = orgService.getGroupHandler().findGroupById(groupId);

    for (Role role : roles) {
      if (isCreateMembership(role.getRoleType().getName(), g.getId())) {
        MembershipImpl m = new MembershipImpl();
        m.setGroupId(g.getId());
        m.setUserName(role.getUser().getId());
        m.setMembershipType(role.getRoleType().getName());
        memberships.add(m);
      }
    }

    if (isAssociationMapped()) {

      Collection<org.picketlink.idm.api.User> users = new HashSet();

      try {
        users = getIdentitySession().getRelationshipManager().findAssociatedUsers(gid, false, null);
      } catch (Exception e) {
        // TODO:
        handleException("Identity operation error: ", e);
      }

      for (org.picketlink.idm.api.User user : users) {
        MembershipImpl m = new MembershipImpl();
        m.setGroupId(groupId);
        m.setUserName(user.getId());
        m.setMembershipType(getAssociationMapping());
        memberships.add(m);
      }
    }

    // TODO: Exo UI has harcoded casts to List
    List<MembershipImpl> results = new LinkedList<MembershipImpl>(memberships);

    if (orgService.getConfiguration().isSortMemberships()) {
      Collections.sort(results);
    }

    if (log.isTraceEnabled()) {
      Tools.logMethodOut(log, LogLevel.TRACE, "findMembershipsByGroupId", results);
    }

    return results;
  }