public Member addMember( PerunSession sess, Group group, Member member, MembershipType type, int sourceGroupId) throws InternalErrorException, AlreadyMemberException, WrongAttributeValueException, WrongReferenceAttributeValueException { // TODO already member exception member.setMembershipType(type); try { jdbc.update( "insert into groups_members (group_id, member_id, created_by, created_at, modified_by, modified_at, created_by_uid, modified_by_uid, membership_type, source_group_id) " + "values (?,?,?," + Compatibility.getSysdate() + ",?," + Compatibility.getSysdate() + ",?,?,?,?)", group.getId(), member.getId(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), sess.getPerunPrincipal().getUserId(), type.getCode(), sourceGroupId); } catch (RuntimeException ex) { throw new InternalErrorException(ex); } return member; }
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}); }
public boolean isGroupMember(PerunSession sess, Group group, Member member) throws InternalErrorException { try { return 1 <= jdbc.queryForInt( "select count(1) from groups_members where group_id=? and member_id=?", group.getId(), member.getId()); } catch (RuntimeException e) { throw new InternalErrorException(e); } }
private static Member createMember(Map<String, String> beanAttr) { if (beanAttr == null) return null; Member member = new Member(); member.setId(Integer.valueOf(beanAttr.get("id")).intValue()); member.setUserId(Integer.valueOf(beanAttr.get("userId")).intValue()); member.setVoId(Integer.valueOf(beanAttr.get("voId")).intValue()); member.setStatus(BeansUtils.eraseEscaping(beanAttr.get("status"))); member.setMembershipType(BeansUtils.eraseEscaping(beanAttr.get("type"))); return member; }
public List<Group> getAllMemberGroups(PerunSession sess, Member member) throws InternalErrorException { try { return jdbc.query( "select distinct " + groupMappingSelectQuery + " from groups_members join groups on groups_members.group_id = groups.id " + " where groups_members.member_id=?", GROUP_MAPPER, member.getId()); } catch (EmptyResultDataAccessException e) { return new ArrayList<Group>(); } catch (RuntimeException e) { throw new InternalErrorException(e); } }
public boolean isDirectGroupMember(PerunSession sess, Group group, Member member) throws InternalErrorException { try { int count = jdbc.queryForInt( "select count(1) from groups_members where group_id=? and member_id=? and membership_type = ?", group.getId(), member.getId(), MembershipType.DIRECT.getCode()); if (1 < count) throw new ConsistencyErrorException( "There is more than one direct member in group" + group); return 1 == count; } catch (RuntimeException e) { throw new InternalErrorException(e); } }
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; }
public void removeMember(PerunSession sess, Group group, Member member) throws InternalErrorException, NotGroupMemberException { int ret; try { ret = jdbc.update( "delete from groups_members where source_group_id=? and member_id=?", group.getId(), member.getId()); } catch (RuntimeException ex) { throw new InternalErrorException(ex); } if (ret == 0) { throw new NotGroupMemberException(member); } else if (ret >= 1) { return; } else { throw new ConsistencyErrorException( member + " and " + group + " have " + ret + " rows in groups_members table"); } }
@Override public Set<Integer> send(List<PerunNotifMessageDto> dtosToSend) { Set<Integer> usedPoolIds = new HashSet<Integer>(); List<PerunNotifEmailMessageToSendDto> messagesToSend = new ArrayList<PerunNotifEmailMessageToSendDto>(); for (PerunNotifMessageDto messageDto : dtosToSend) { PoolMessage dto = messageDto.getPoolMessage(); PerunNotifTemplate template = messageDto.getTemplate(); PerunNotifReceiver receiver = messageDto.getReceiver(); try { String groupSender = dto.getKeyAttributes().get(template.getSender()); if (groupSender == null || groupSender.isEmpty()) { groupSender = template.getSender(); } logger.debug("Calculated sender : {}", groupSender); Integer groupId = Integer.valueOf(receiver.getTarget()); Group group = perun.getGroupsManagerBl().getGroupById(session, groupId); List<Member> groupMembers = perun.getGroupsManagerBl().getGroupMembers(session, group); if (groupMembers != null) { for (Member member : groupMembers) { try { PerunNotifEmailMessageToSendDto memberEmailDto = new PerunNotifEmailMessageToSendDto(); memberEmailDto.setMessage(messageDto.getMessageToSend()); memberEmailDto.setSubject(messageDto.getSubject()); memberEmailDto.setReceiver( (String) perun .getAttributesManagerBl() .getAttribute( session, perun.getUsersManager().getUserByMember(session, member), "urn:perun:user:attribute-def:def:preferredMail") .getValue()); memberEmailDto.setSender(groupSender); messagesToSend.add(memberEmailDto); } catch (Exception ex) { logger.error( "PreferredEmail cannot be retrieved, userId: {}", member.getUserId(), ex); } } } usedPoolIds.addAll(messageDto.getUsedPoolIds()); } catch (NumberFormatException ex) { logger.error("GroupId cannot be parsed: {}", receiver.getTarget()); } catch (GroupNotExistsException ex) { logger.error("Group with id: {} does not exists.", receiver.getTarget()); } catch (InternalErrorException ex) { logger.error("Error during processing messageDto.", ex); } } perunNotifEmailManager.sendMessages(messagesToSend); return usedPoolIds; }
/** * Converts Member to its Id in grouper. * * @param member member * @return grouper Id */ protected static String toGrouperId(PerunSession sess, Member member) throws InternalErrorException { log.trace("Entering toGrouperId: member='" + member + "'"); if (member == null) throw new InternalErrorRuntimeException(new NullPointerException("member")); return Integer.toString(member.getUserId()); }
@Override public void checkAttributeValue( PerunSessionImpl perunSession, Resource resource, Member member, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException { Attribute attrFilesLimit = null; Integer filesQuota = null; Integer filesLimit = null; // Get FilesLimit attribute try { attrFilesLimit = perunSession .getPerunBl() .getAttributesManagerBl() .getAttribute(perunSession, resource, member, A_MR_filesLimit); } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException( attribute + " from member " + member.getId() + " and resource " + resource.getId() + " could not obtained.", ex); } // Get FilesQuota value if (attribute.getValue() != null) { filesQuota = (Integer) attribute.getValue(); } else { try { attribute = perunSession .getPerunBl() .getAttributesManagerBl() .getAttribute(perunSession, resource, A_R_defaultFilesQuota); } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException( "Attribute with defaultFilesQuota from resource " + resource.getId() + " could not obtained.", ex); } if (attribute != null && attribute.getValue() != null) { filesQuota = (Integer) attribute.getValue(); } } if (filesQuota != null && filesQuota < 0) throw new WrongAttributeValueException(attribute, attribute + " cannot be less than 0."); // Get FilesLimit value if (attrFilesLimit != null && attrFilesLimit.getValue() != null) { filesLimit = (Integer) attrFilesLimit.getValue(); } else if (attrFilesLimit == null || attrFilesLimit.getValue() == null) { try { attrFilesLimit = perunSession .getPerunBl() .getAttributesManagerBl() .getAttribute(perunSession, resource, A_R_defaultFilesLimit); } catch (AttributeNotExistsException ex) { throw new ConsistencyErrorException( "Attribute with defaultFilesLimit from resource " + resource.getId() + " could not obtained.", ex); } if (attrFilesLimit != null || attrFilesLimit.getValue() != null) { filesLimit = (Integer) attrFilesLimit.getValue(); } } if (filesLimit != null && filesLimit < 0) throw new ConsistencyErrorException(attrFilesLimit + " cannot be less than 0."); // Compare filesQuota with filesLimit if (filesQuota == null || filesQuota == 0) { if (filesLimit != null && filesLimit != 0) throw new WrongReferenceAttributeValueException( attribute, attrFilesLimit, "Try to set unlimited quota, but limit is still " + filesLimit); } else if (filesLimit != null && filesLimit != 0) { if (filesLimit < filesQuota) throw new WrongReferenceAttributeValueException( attribute, attrFilesLimit, attribute + " must be less than or equal to " + attrFilesLimit); } }