use of cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException in project perun by CESNET.
the class GroupsManagerBlImpl method updateExistingMemberWhileSynchronization.
/**
* Get candidate and corresponding memberToUpdate and update his attributes, extSources, expiration and status.
*
* For Member - updateAttributes
* For User - updateAttributes if exists in list of overwriteUserAttributesList,
* in other case just mergeAttributes.
*
* updateAttributes = store new values
* mergeAttributes = for List and Map add new values, do not remove old one,
* for other cases store new values (like String, Integer etc.)
*
* This method runs in separate transaction.
*
* @param sess perun session
* @param group to be synchronized
* @param candidate candidate to update by
* @param memberToUpdate richMember for updating in Perun by information from extSource
* @param overwriteUserAttributesList list of user attributes to be updated instead of merged
* @param mergeMemberAttributesList list of member attributes to be merged instead of updated
* @param attrDefs list of attribute definitions to update from candidate, if null the list is filled in process
*
* @throws AttributeNotExistsException if some attributes not exists and for this reason can't be updated
* @throws WrongAttributeAssignmentException if some attribute is updated in bad way (bad assignment)
*/
public void updateExistingMemberWhileSynchronization(PerunSession sess, Group group, Candidate candidate, RichMember memberToUpdate, List<String> overwriteUserAttributesList, List<String> mergeMemberAttributesList, List<AttributeDefinition> attrDefs) {
// If member does not exists in this moment (somebody removed him before updating process), skip him and log it
try {
getPerunBl().getMembersManagerBl().checkMemberExists(sess, memberToUpdate);
} catch (MemberNotExistsException ex) {
// log it and skip this member
log.debug("Someone removed member {} from group {} before updating process. Skip him.", memberToUpdate, group);
return;
}
// load attrDefinitions if not received
if (!candidate.getAttributes().isEmpty() && attrDefs.isEmpty()) {
attrDefs = getAttributesToSynchronizeFromCandidates(sess, group, candidate);
}
// get RichMember with attributes
memberToUpdate = getPerunBl().getMembersManagerBl().convertMembersToRichMembersWithAttributes(sess, Collections.singletonList(memberToUpdate), attrDefs).get(0);
// try to find user core attributes and update user -> update name and titles
updateUserCoreAttributes(sess, candidate, memberToUpdate, overwriteUserAttributesList);
for (AttributeDefinition attributeDefinition : attrDefs) {
// update member attribute
if (attributeDefinition.getNamespace().startsWith(AttributesManager.NS_MEMBER_ATTR)) {
updateMemberAttribute(sess, group, candidate, memberToUpdate, attributeDefinition, mergeMemberAttributesList);
// update user attribute
} else if (attributeDefinition.getNamespace().startsWith(AttributesManager.NS_USER_ATTR)) {
updateUserAttribute(sess, group, candidate, memberToUpdate, attributeDefinition, overwriteUserAttributesList);
} else {
// we are not supporting other attributes than member or user so skip it without error, but log it
log.warn("Attribute {} can't be set, because it is not member or user attribute.", attributeDefinition.getName());
}
}
// Synchronize userExtSources (add not existing)
addUserExtSources(sess, candidate, memberToUpdate);
// Set correct member Status
updateMemberStatus(sess, memberToUpdate);
}
use of cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException in project perun by CESNET.
the class GroupsManagerBlImpl method addMissingMemberWhileSynchronization.
/**
* Get new candidate and add him to the Group.
*
* If Candidate can't be added to Group, skip him and add this information to skippedMembers list.
*
* When creating new member from Candidate, if user already exists, merge his attributes,
* if attribute exists in list of overwriteUserAttributesList, update it instead of merging.
*
* This method runs in separate transaction.
*
* @param sess perun session
* @param group to be synchronized
* @param candidate new member (candidate)
* @param overwriteUserAttributesList list of attributes to be updated for user if found
* @param mergeMemberAttributesList list of attributes to be merged for member if found
* @param skippedMembers list of not successfully synchronized members
*/
public void addMissingMemberWhileSynchronization(PerunSession sess, Group group, Candidate candidate, List<String> overwriteUserAttributesList, List<String> mergeMemberAttributesList, List<String> skippedMembers) {
Member member;
try {
// Check if the member is already in the VO (just not in the group)
member = getPerunBl().getMembersManagerBl().getMemberByUserExtSources(sess, getPerunBl().getGroupsManagerBl().getVo(sess, group), candidate.getUserExtSources());
// member exists - update attributes
RichMember memberToUpdate = getPerunBl().getMembersManagerBl().getRichMember(sess, member);
updateExistingMemberWhileSynchronization(sess, group, candidate, memberToUpdate, overwriteUserAttributesList, mergeMemberAttributesList, new ArrayList<>());
} catch (MemberNotExistsException e) {
try {
// We have new member (candidate), so create him using synchronous createMember (and overwrite chosen user attributes)
member = getPerunBl().getMembersManagerBl().createMemberSync(sess, getPerunBl().getGroupsManagerBl().getVo(sess, group), candidate, null, overwriteUserAttributesList);
log.info("Group synchronization {}: New member id {} created during synchronization.", group, member.getId());
} catch (AlreadyMemberException e1) {
// Check if the member is already in the VO (just not in the group)
try {
member = getPerunBl().getMembersManagerBl().getMemberByUserExtSources(sess, getPerunBl().getGroupsManagerBl().getVo(sess, group), candidate.getUserExtSources());
// member exists - update attribute
RichMember memberToUpdate = getPerunBl().getMembersManagerBl().getRichMember(sess, member);
updateExistingMemberWhileSynchronization(sess, group, candidate, memberToUpdate, overwriteUserAttributesList, mergeMemberAttributesList, new ArrayList<>());
} catch (Exception e2) {
// Something is still wrong, thrown consistency exception
throw new ConsistencyErrorException("Trying to add existing member (it is not possible to get him by userExtSource even if is also not possible to create him in DB)!");
}
} catch (AttributeValueException e1) {
log.warn("Can't create member from candidate {} due to attribute value exception {}.", candidate, e1);
skippedMembers.add("MemberEntry:[" + candidate + "] was skipped because there was problem when createing member from candidate: Exception: " + e1.getName() + " => '" + e1.getMessage() + "'");
return;
} catch (ExtendMembershipException e1) {
log.warn("Can't create member from candidate {} due to membership expiration exception {}.", candidate, e1);
skippedMembers.add("MemberEntry:[" + candidate + "] was skipped because membership expiration: Exception: " + e1.getName() + " => " + e1.getMessage() + "]");
return;
}
}
try {
// Add the member to the group
if (!group.getName().equals(VosManager.MEMBERS_GROUP)) {
// Do not add members to the generic members group
try {
getPerunBl().getGroupsManagerBl().addMember(sess, group, member);
} catch (GroupNotExistsException ex) {
// Shouldn't happen, group should always exist
throw new ConsistencyErrorException(ex);
}
}
log.info("Group synchronization {}: New member id {} added.", group, member.getId());
} catch (AlreadyMemberException e) {
// This part is ok, it means someone add member before synchronization ends, log it and skip this member
log.debug("Member {} was added to group {} before adding process. Skip this member.", member, group);
return;
} catch (AttributeValueException e) {
// There is a problem with attribute value, so set INVALID status of the member
getPerunBl().getMembersManagerBl().invalidateMember(sess, member);
}
// Try to validate member
updateMemberStatus(sess, member);
}
use of cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException in project perun by CESNET.
the class GroupEventProcessor method processMemberValidated.
public void processMemberValidated(String msg, MessageBeans beans) {
if (beans.getMember() == null) {
return;
}
List<Group> memberGroups = new ArrayList<Group>();
Perun perun = ldapcManager.getPerunBl();
try {
log.debug("Getting list of groups for member {}", beans.getMember().getId());
// memberGroups = Rpc.GroupsManager.getAllMemberGroups(ldapcManager.getRpcCaller(), beans.getMember());
memberGroups = perun.getGroupsManager().getAllGroupsWhereMemberIsActive(ldapcManager.getPerunSession(), beans.getMember());
for (Group g : memberGroups) {
log.debug("Adding validated member {} to group {}", beans.getMember(), g);
perunGroup.addMemberToGroup(beans.getMember(), g);
}
} catch (MemberNotExistsException e) {
// IMPORTANT this is not problem, if member not exist, we expected that will be deleted in some message after that, in DB is deleted
} catch (PrivilegeException e) {
log.warn("There are no privileges for getting member's groups", e);
} catch (NamingException | InternalErrorException e) {
log.error("Error adding validated member to group", e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException in project perun by CESNET.
the class BBMRICollections method approveApplication.
/**
* Find groups representing collections by input. Groups are looked for in subgroups
* of group the module is assigned to. Add user as a member to the groups.
*
* @param session who approves the application
* @param app application
* @return unchanged application
* @throws PerunException in case of internal error in Perun
*/
@Override
public Application approveApplication(PerunSession session, Application app) throws VoNotExistsException, UserNotExistsException, PrivilegeException, MemberNotExistsException, RegistrarException, GroupNotExistsException, AttributeNotExistsException, WrongAttributeAssignmentException, ExternallyManagedException, WrongAttributeValueException, WrongReferenceAttributeValueException, NotGroupMemberException {
// get perun and beans from session
PerunBl perun = (PerunBl) session.getPerun();
Vo vo = app.getVo();
User user = app.getUser();
Member member = perun.getMembersManagerBl().getMemberByUser(session, vo, user);
// get the field of application with the collections
Set<String> collectionIDsInApplication = getCollectionIDsFromApplication(session, app);
// get map of collection IDs to group from Perun
String directoryGroupName = this.getDirectoryGroupNameFromApplication(session, app);
Group directoryGroup;
try {
directoryGroup = perun.getGroupsManager().getGroupByName(session, vo, directoryGroupName);
} catch (GroupNotExistsException e) {
throw new InternalErrorException("Target group does not exist");
}
Map<String, Group> collectionIDsToGroupsMap = getCollectionIDsToGroupsMap(session, perun, directoryGroup);
// add user to all groups from the field on application
for (String collectionID : collectionIDsInApplication) {
Group collection = collectionIDsToGroupsMap.get(collectionID);
if (collection == null) {
log.debug("There are no groups for collectionID: {}", collectionID);
} else {
try {
perun.getGroupsManager().addMember(session, collection, member);
} catch (AlreadyMemberException ex) {
// ignore
}
}
}
try {
perun.getGroupsManager().removeMember(session, app.getGroup(), member);
} catch (MemberNotExistsException | NotGroupMemberException e) {
// we can ignore these exceptions
}
return app;
}
use of cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException in project perun by CESNET.
the class GroupsManagerBlImpl method reactivateMember.
@Override
public void reactivateMember(PerunSession sess, Member member, Group group) throws MemberNotExistsException {
// only direct membership has own status and expiration, indirect membership get it's status and expiration from origin group
if (!isDirectGroupMember(sess, group, member))
throw new MemberNotExistsException("Member does not belong to this group");
validateMemberInGroup(sess, member, group);
// Get current membershipExpiration date attribute
Attribute membershipExpirationAttribute = getMemberExpiration(sess, member, group);
// Set new value of the membershipExpiration for the member
membershipExpirationAttribute.setValue(null);
try {
getPerunBl().getAttributesManagerBl().setAttribute(sess, member, group, membershipExpirationAttribute);
} catch (WrongAttributeValueException e) {
throw new InternalErrorException("Wrong value: " + membershipExpirationAttribute.getValue(), e);
} catch (WrongReferenceAttributeValueException | WrongAttributeAssignmentException e) {
throw new InternalErrorException(e);
} catch (MemberGroupMismatchException e) {
throw new ConsistencyErrorException(e);
}
try {
extendMembershipInGroup(sess, member, group);
} catch (ExtendMembershipException ex) {
// This exception should not be thrown for null membershipExpiration attribute
throw new InternalErrorException(ex);
}
}
Aggregations