@Override public String serializeToString() { StringBuilder str = new StringBuilder(); return str.append(this.getClass().getSimpleName()).append(":[").append( "id=<").append(getId()).append(">").append( ", parentGroupId=<").append(getParentGroupId() == null ? "\\0" : getParentGroupId()).append(">").append( ", name=<").append(getName() == null ? "\\0" : BeansUtils.createEscaping(getName())).append(">").append( ", shortName=<").append(getShortName() == null ? "\\0" : BeansUtils.createEscaping(getShortName())).append(">").append( ", description=<").append(getDescription() == null ? "\\0" : BeansUtils.createEscaping(getDescription())).append(">").append( ", voId=<").append(getVoId()).append(">").append( ']').toString(); }
private static Group createGroup(Map<String, String> beanAttr) { if(beanAttr==null) return null; Group group = new Group(); if(beanAttr.get("parentGroupId").equals("\\0")) group.setParentGroupId(null); else group.setParentGroupId(Integer.valueOf(beanAttr.get("parentGroupId"))); group.setId(Integer.valueOf(beanAttr.get("id"))); group.setName(BeansUtils.eraseEscaping(beanAttr.get("name"))); group.setDescription(BeansUtils.eraseEscaping(beanAttr.get("description"))); group.setVoId(Integer.valueOf(beanAttr.get("voId"))); return group; }
public RichGroup(Group group, List<Attribute> attrs) { super(group.getId(), group.getName(), group.getDescription(), group.getCreatedAt(), group.getCreatedBy(), group.getModifiedAt(), group.getModifiedBy(), group.getParentGroupId(), group.getCreatedByUid(), group.getModifiedByUid()); this.setVoId(group.getVoId()); this.groupAttributes = attrs; }
@Override public int compareTo(PerunBean perunBean) { if(perunBean == null) throw new NullPointerException("PerunBean to compare with is null."); if(perunBean instanceof Group) { Group group = (Group) perunBean; if (this.getName() == null && group.getName() != null) return -1; if (group.getName() == null && this.getName() != null) return 1; if (this.getName() == null && group.getName() == null) return 0; return this.getName().compareToIgnoreCase(group.getName()); } else { return (this.getId() - perunBean.getId()); } }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final Group other = (Group) obj; if (this.getId() != other.getId()) { return false; } if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) { return false; } return true; } }
@Override public ApplicationForm getFormForGroup(final Group group) throws PerunException { if (group == null) throw new InternalErrorException("Group can't be null"); try { return jdbc.queryForObject(FORM_SELECT + " where vo_id=? and group_id=?", new RowMapper<ApplicationForm>() { @Override public ApplicationForm mapRow(ResultSet rs, int arg1) throws SQLException { ApplicationForm form = new ApplicationForm(); form.setId(rs.getInt("id")); form.setAutomaticApproval(rs.getBoolean("automatic_approval")); form.setAutomaticApprovalExtension(rs.getBoolean("automatic_approval_extension")); form.setModuleClassName(rs.getString("module_name")); form.setGroup(group); try { form.setVo(vosManager.getVoById(registrarSession, group.getVoId())); } catch (Exception ex) { // we don't care, shouldn't happen for internal identity. } return form; } }, group.getVoId(), group.getId()); } catch (EmptyResultDataAccessException ex) { throw new FormNotExistsException("Form for Group: "+group.getName()+" doesn't exists."); } }
/** * Update basic group attributes (name and description) in LDAP * * @param group group after update * * @throws InternalErrorException */ private void updateGroup(Group group) throws InternalErrorException { Map<LdapOperation, List<Pair<String,String>>> attributes = new HashMap<>(); List<Pair<String,String>> listAttributesToBeRemoved = new ArrayList<>(); List<Pair<String,String>> listAttributesToBeReplaced = new ArrayList<>(); //change name listAttributesToBeReplaced.add(new Pair(ldapAttrCommonName,this.group.getName())); listAttributesToBeReplaced.add(new Pair(ldapAttrPerunUniqueGroupName, ldapConnector.getVoShortName(this.group.getVoId()) + ":" + this.group.getName())); //change description (or remove it if there is none) if(group.getDescription() != null && !group.getDescription().isEmpty()) { listAttributesToBeReplaced.add(new Pair(ldapAttrDescription, this.group.getDescription())); } else { if(ldapConnector.groupAttributeExist(group, ldapAttrDescription)) { listAttributesToBeRemoved.add(new Pair(ldapAttrDescription, null)); } } //Add all attributes which will be replaced for the group (that also mean added if not exists yet) attributes.put(LdapOperation.REPLACE_ATTRIBUTE, listAttributesToBeReplaced); //Add all attributes (if any) which will be removed for group if(!listAttributesToBeReplaced.isEmpty()) attributes.put(LdapOperation.REMOVE_ATTRIBUTE, listAttributesToBeRemoved); //update attributes in LDAP for group updateGroupAttributes(attributes, group); }
List<Pair<String,String>> listAttributesToBeReplaced = new ArrayList<>(); listAttributesToBeReplaced.add(new Pair(ldapAttrCommonName,group.getName())); listAttributesToBeReplaced.add(new Pair(ldapAttrPerunUniqueGroupName, ldapConnector.getVoShortName(group.getVoId()) + ":" + group.getName())); if(group.getName().contains(":")) { listAttributesToBeReplaced.add(new Pair(ldapAttrPerunParentGroup, ldapAttrPerunGroupId + "=" + group.getParentGroupId().toString() + "," + ldapAttrPerunVoId + "=" + group.getVoId() + "," + ldapProperties.getLdapBase())); listAttributesToBeReplaced.add(new Pair(ldapAttrPerunParentGroupId, group.getParentGroupId().toString())); } else {
/** * Check members states in groups from given Vos. * * @param vos vos * @throws InternalErrorException internal error */ private void checkGroupMembersState(List<Vo> vos) throws InternalErrorException { List<Group> allGroups = new ArrayList<>(); for (Vo vo : vos) { allGroups.addAll(perun.getGroupsManagerBl().getGroups(sess, vo)); } Calendar today = Calendar.getInstance(); // remove member groups allGroups = allGroups.stream() .filter(group -> !group.getName().equals("members")) .collect(Collectors.toList()); for (Group group : allGroups) { // check members which should expire today checkGroupMemberExpiration(group, today); // check members which should be validated today checkGroupMemberValidation(group, today); } }
/** * VOOTGroup represents group encoded according to the OpenSocial Social Data Specification using in VOOT protocol. * * @param group group * @param voShortName short name of vo * @param voot_membership_role membership role of person in group */ public VOOTGroup(Group group, String voShortName, String voot_membership_role) throws VOOTException{ //group must be in vo if(voShortName == null) throw new VOOTException("internal_error_exception"); this.id = voShortName.concat(":").concat(group.getName()); this.title = group.getName(); this.description = group.getDescription(); this.voot_membership_role = voot_membership_role; }
@Override public String toString() { StringBuilder ret = new StringBuilder(); ret.append(getClass().getSimpleName()); ret.append(":["); ret.append("id='"); ret.append(this.getId()); ret.append("', parentGroupId='"); ret.append(parentGroupId); ret.append("', name='"); ret.append(name); ret.append("', shortName='"); ret.append(this.getShortName()); ret.append("', description='"); ret.append(description); ret.append("', voId='"); ret.append(voId); ret.append("']"); return ret.toString(); }
result.add(user); Group group = new Group(); group.setId(0); group.setName("members"); group.setDescription("Group test"); result.add(group);
@Override public ApplicationForm mapRow(ResultSet rs, int arg1) throws SQLException { ApplicationForm form = new ApplicationForm(); form.setId(rs.getInt("id")); form.setAutomaticApproval(rs.getBoolean("automatic_approval")); form.setAutomaticApprovalExtension(rs.getBoolean("automatic_approval_extension")); form.setModuleClassName(rs.getString("module_name")); form.setGroup(group); try { form.setVo(vosManager.getVoById(registrarSession, group.getVoId())); } catch (Exception ex) { // we don't care, shouldn't happen for internal identity. } return form; } }, group.getVoId(), group.getId());
app.setGroup(new Group(rs.getInt("group_id"), rs.getString("group_name"), rs.getString("group_description"), rs.getString("group_created_at"), rs.getString("group_created_by"), rs.getString("group_modified_at"), rs.getString("group_modified_by"), rs.getInt("group_created_by_uid"), rs.getInt("group_modified_by_uid"))); app.getGroup().setVoId(rs.getInt("vo_id")); app.getGroup().setParentGroupId(rs.getInt("group_parent_group_id"));
/** * Gets collections as map of collectionID => Group. * * @return Map of collection IDs to group. */ private Map<String, Group> getCollectionIDsToGroupsMap (PerunSession session, Perun perun, Group collectionsGroup) throws GroupNotExistsException, WrongAttributeAssignmentException, InternalErrorException, AttributeNotExistsException, PrivilegeException { Map<String, Group> collectionIDsToGroupMap = new HashMap<>(); for (Group group : perun.getGroupsManager().getSubGroups(session, collectionsGroup)) { for (Group subgroup : perun.getGroupsManager().getSubGroups(session, group)) { if (REPRESENTATIVES_GROUP_NAME.equals(subgroup.getShortName())) { Attribute collectionID = perun.getAttributesManager().getAttribute(session, subgroup, COLLECTION_ID_ATTR_NAME); collectionIDsToGroupMap.put(collectionID.valueAsString(), subgroup); } } } return collectionIDsToGroupMap; }
public GroupContactsRemovedForFacility(Group group, ContactGroup contactGroup) { this.group = group; this.contactGroup = contactGroup; this.message = formatMessage("Group (%d) successfully removed from contact groups %s.", group.getId(), contactGroup); }
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(EventProcessorImpl.ldapAttrMemberOf, EventProcessorImpl.ldapAttrPerunGroupId + "=" + group.getId() + "," + EventProcessorImpl.ldapAttrPerunVoId + "=" + 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); } }
private GroupSCIM mapPerunGroupToScimGroup(Group perunGroup) { List<String> schemas = new ArrayList<>(); schemas.add(URN_GROUP); GroupSCIM result = new GroupSCIM(); result.setSchemas(schemas); result.setDisplayName(perunGroup.getName()); result.setId(new Long(perunGroup.getId())); try { List<Member> perunGroupMembers = perunBl.getGroupsManagerBl().getGroupMembers(session, perunGroup); result.setMembers(mapPerunMembersToScimMembers(perunGroupMembers)); } catch (InternalErrorException ex) { log.error("Cannot obtain members of group " + perunGroup.getId() + " in VO " + perunGroup.getVoId(), ex); } return result; }
throw new AlreadyRegisteredException("You are already member of group "+group.getName()+"."); } else { regs.addAll(jdbc.query("select id from application where apptype=? and vo_id=? and group_id=? and state=? and (user_id=? or (created_by=? and extSourceName=?))", new SingleColumnRowMapper<Integer>(Integer.class), AppType.INITIAL.toString(), vo.getId(), group.getId(), AppState.NEW.toString(), user.getId(), actor, extSourceName)); regs.addAll(jdbc.query("select id from application where apptype=? and vo_id=? and group_id=? and state=? and (user_id=? or (created_by=? and extSourceName=?))", new SingleColumnRowMapper<Integer>(Integer.class), AppType.INITIAL.toString(), vo.getId(), group.getId(), AppState.VERIFIED.toString(), user.getId(), actor, extSourceName)); if (!regs.isEmpty()) { throw new DuplicateRegistrationAttemptException("Initial application for Group: "+group.getName()+" already exists.", actor, extSourceName, regs.get(0)); regs.addAll(jdbc.query("select id from application where apptype=? and vo_id=? and group_id=? and state=? and (user_id=? or (created_by=? and extSourceName=?))", new SingleColumnRowMapper<Integer>(Integer.class), AppType.INITIAL.toString(), vo.getId(), group.getId(), AppState.NEW.toString(), user.getId(), actor, extSourceName)); regs.addAll(jdbc.query("select id from application where apptype=? and vo_id=? and group_id=? and state=? and (user_id=? or (created_by=? and extSourceName=?))", new SingleColumnRowMapper<Integer>(Integer.class), AppType.INITIAL.toString(), vo.getId(), group.getId(), AppState.VERIFIED.toString(), user.getId(), actor, extSourceName)); if (!regs.isEmpty()) { throw new DuplicateRegistrationAttemptException("Initial application for Group: "+group.getName()+" already exists.", actor, extSourceName, regs.get(0)); AppType.INITIAL.toString(), vo.getId(), group.getId(), actor, extSourceName, AppState.APPROVED.toString(), AppState.REJECTED.toString())); throw new DuplicateRegistrationAttemptException("Initial application for Group: "+group.getName()+" already exists.", actor, extSourceName, regs.get(0)); AppType.EXTENSION.toString(), vo.getId(), group.getId(), user.getId(), AppState.NEW.toString())); regs.addAll(jdbc.query("select id from application where apptype=? and vo_id=? and group_id=? and user_id=? and state=?",