/**
   * @param group
   * @throws org.apache.directory.fortress.core.CreateException
   */
  Group create(Group group) throws CreateException {
    LdapConnection ld = null;
    String nodeDn = getDn(group.getName(), group.getContextId());

    try {
      LOG.debug("create group dn [{}]", nodeDn);
      Entry myEntry = new DefaultEntry(nodeDn);
      myEntry.add(SchemaConstants.OBJECT_CLASS_AT, GROUP_OBJ_CLASS);
      myEntry.add(SchemaConstants.CN_AT, group.getName());
      // protocol is required:
      myEntry.add(GROUP_PROTOCOL_ATTR_IMPL, group.getProtocol());
      // type is required:
      myEntry.add(GlobalIds.TYPE, group.getType().toString());

      loadAttrs(group.getMembers(), myEntry, SchemaConstants.MEMBER_AT);
      loadProperties(group.getProperties(), myEntry, GROUP_PROPERTY_ATTR_IMPL, '=');

      if (StringUtils.isNotEmpty(group.getDescription())) {
        myEntry.add(SchemaConstants.DESCRIPTION_AT, group.getDescription());
      }

      ld = getAdminConnection();
      add(ld, myEntry);
    } catch (LdapException e) {
      String error = "create group node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
      throw new CreateException(GlobalErrIds.GROUP_ADD_FAILED, error, e);
    } finally {
      closeAdminConnection(ld);
    }

    return group;
  }
Exemple #2
0
 public void withRealmGroupTest() {
   Group g = new Group(1L, "g1", "group description", true, "ldap", "dn=o");
   assertEquals(g.getGroupId(), 1L);
   assertEquals(g.getGroupName(), "g1");
   assertEquals(g.getDescription(), "group description");
   assertTrue(g.isNewUserDefault());
   assertEquals(g.getRealm(), "ldap");
   assertEquals(g.getRealmAttributes(), "dn=o");
 }
Exemple #3
0
 public void simpleGroupTest() {
   Group g = new Group(1L, "g1", null, false, null, null);
   assertEquals(g.getGroupId(), 1L);
   assertEquals(g.getGroupName(), "g1");
   assertNull(g.getDescription());
   assertFalse(g.isNewUserDefault());
   assertNull(g.getRealm());
   assertNull(g.getRealmAttributes());
 }
  private void setTexts() {
    mTxtGroupName.setText(mGroup.getName());
    mTxtGroupCreated.setText(mGroup.getCreatedString());
    mTxtGroupDescription.setText(mGroup.getDescription());

    mTxtGroupOwnerName.setText(mGroup.getOwner().getName());
    mTxtGroupUsersCount.setText(Integer.toString(mGroup.getUsersCount()));
    mTxtGroupVideosCount.setText(Integer.toString(mGroup.getVideosCount()));
  }
Exemple #5
0
  public void addGroup(Group group) throws InternalErrorException {
    // Create a set of attributes
    Attributes attributes = new BasicAttributes();

    // Create the objectclass to add
    Attribute objClasses = new BasicAttribute("objectClass");
    objClasses.add("top");
    objClasses.add("perunGroup");

    // Add attributes
    attributes.put(objClasses);
    attributes.put("cn", group.getName());
    attributes.put("perunGroupId", String.valueOf(group.getId()));
    attributes.put(
        "perunUniqueGroupName",
        new String(this.getVoShortName(group.getVoId()) + ":" + group.getName()));
    attributes.put("perunVoId", String.valueOf(group.getVoId()));
    if (group.getDescription() != null && !group.getDescription().isEmpty())
      attributes.put("description", group.getDescription());
    if (group.getParentGroupId() != null) {
      attributes.put(
          "perunParentGroup",
          "perunGroupId="
              + group.getParentGroupId().toString()
              + ",perunVoId="
              + group.getVoId()
              + ","
              + ldapProperties.getLdapBase());
      attributes.put("perunParentGroupId", group.getParentGroupId().toString());
    }

    // Create the entry
    try {
      ldapTemplate.bind(
          getGroupDN(String.valueOf(group.getVoId()), String.valueOf(group.getId())),
          null,
          attributes);
      log.debug(
          "New entry created in LDAP: Group {} in Vo with Id=" + group.getVoId() + ".", group);
    } catch (NameNotFoundException e) {
      throw new InternalErrorException(e);
    }
  }
  /**
   * @param group
   * @return
   * @throws org.apache.directory.fortress.core.CreateException
   */
  Group update(Group group) throws FinderException, UpdateException {
    LdapConnection ld = null;
    String nodeDn = getDn(group.getName(), group.getContextId());

    try {
      LOG.debug("update group dn [{}]", nodeDn);
      List<Modification> mods = new ArrayList<Modification>();

      if (StringUtils.isNotEmpty(group.getDescription())) {
        mods.add(
            new DefaultModification(
                ModificationOperation.REPLACE_ATTRIBUTE,
                SchemaConstants.DESCRIPTION_AT,
                group.getDescription()));
      }

      if (StringUtils.isNotEmpty(group.getProtocol())) {
        mods.add(
            new DefaultModification(
                ModificationOperation.REPLACE_ATTRIBUTE,
                GROUP_PROTOCOL_ATTR_IMPL,
                group.getProtocol()));
      }

      loadAttrs(group.getMembers(), mods, SchemaConstants.MEMBER_AT);
      loadProperties(group.getProperties(), mods, GROUP_PROPERTY_ATTR_IMPL, true, '=');

      if (mods.size() > 0) {
        ld = getAdminConnection();
        modify(ld, nodeDn, mods, group);
      }
    } catch (LdapException e) {
      String error = "update group node dn [" + nodeDn + "] caught LDAPException=" + e.getMessage();
      throw new UpdateException(GlobalErrIds.GROUP_UPDATE_FAILED, error, e);
    } finally {
      closeAdminConnection(ld);
    }
    return get(group);
  }
  /**
   * tm_usergroup에 그룹을 인서트한다.
   *
   * @param group
   * @return
   * @throws DataAccessException
   */
  public int insertGroup(Group group) throws DataAccessException {

    String sql =
        QueryUtil.getStringQuery(
            "admin_sql", "admin.usergroup.insertgroup"); // 쿼리 프로퍼티파일의 키값에 해당되는 sql문을 읽어온다.
    // 넘겨받은 파라미터를 세팅한다.

    Map<String, Object> param = new HashMap<String, Object>();
    param.put("groupID", group.getGroupID());
    param.put("groupName", group.getGroupName());
    param.put("description", group.getDescription());

    return getSimpleJdbcTemplate().update(sql, param);
  }