Esempio n. 1
0
 public void removeMemberFromGroup(Member member, Group group) throws InternalErrorException {
   // Remove member from group
   Attribute uniqueMember =
       new BasicAttribute(
           "uniqueMember",
           "perunUserId=" + member.getUserId() + ",ou=People," + ldapProperties.getLdapBase());
   ModificationItem uniqueMemberItem =
       new ModificationItem(DirContext.REMOVE_ATTRIBUTE, uniqueMember);
   this.updateGroup(group, new ModificationItem[] {uniqueMemberItem});
   // Remove member from vo if this group is membersGroup
   if (group.getName().equals(VosManager.MEMBERS_GROUP) && group.getParentGroupId() == null) {
     // Remove info from vo
     this.updateVo(group.getVoId(), new ModificationItem[] {uniqueMemberItem});
     // Remove also information from user
     Attribute memberOfPerunVo =
         new BasicAttribute("memberOfPerunVo", String.valueOf(group.getVoId()));
     ModificationItem memberOfPerunVoItem =
         new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOfPerunVo);
     this.updateUserWithUserId(
         String.valueOf(member.getUserId()), new ModificationItem[] {memberOfPerunVoItem});
   }
   // Remove group info from member
   Attribute memberOf =
       new BasicAttribute(
           "memberOf",
           "perunGroupId="
               + group.getId()
               + ",perunVoId="
               + group.getVoId()
               + ","
               + ldapProperties.getLdapBase());
   ModificationItem memberOfItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOf);
   this.updateUserWithUserId(
       String.valueOf(member.getUserId()), new ModificationItem[] {memberOfItem});
 }
Esempio n. 2
0
  public void removeGroup(Group group) throws InternalErrorException {

    List<String> uniqueUsersIds = new ArrayList<String>();
    uniqueUsersIds = this.getAllUniqueMembersInGroup(group.getId(), group.getVoId());
    for (String s : uniqueUsersIds) {
      Attribute memberOf =
          new BasicAttribute(
              "memberOf",
              "perunGroupId="
                  + group.getId()
                  + ",perunVoId="
                  + group.getVoId()
                  + ","
                  + ldapProperties.getLdapBase());
      ModificationItem memberOfItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOf);
      this.updateUserWithUserId(s, new ModificationItem[] {memberOfItem});
    }

    try {
      ldapTemplate.unbind(
          getGroupDN(String.valueOf(group.getVoId()), String.valueOf(group.getId())));
      log.debug(
          "Entry deleted from LDAP: Group {} from Vo with ID=" + group.getVoId() + ".", group);
    } catch (NameNotFoundException e) {
      throw new InternalErrorException(e);
    }
  }
Esempio n. 3
0
 public boolean isAlreadyMember(Member member, Group group) {
   Object o =
       ldapTemplate.lookup(
           getUserDN(String.valueOf(member.getUserId())), new UserMemberOfContextMapper());
   String[] memberOfInformation = (String[]) o;
   if (memberOfInformation != null) {
     for (String s : memberOfInformation) {
       if (s.equals(
           "perunGroupId="
               + group.getId()
               + ",perunVoId="
               + group.getVoId()
               + ","
               + ldapProperties.getLdapBase())) return true;
     }
   }
   return false;
 }
Esempio n. 4
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);
    }
  }