use of cz.metacentrum.perun.core.api.BanOnResource in project perun by CESNET.
the class urn_perun_member_resource_attribute_def_virt_isBannedTest method setUp.
@Before
public void setUp() throws Exception {
classInstance = new urn_perun_member_resource_attribute_def_virt_isBanned();
session = mock(PerunSessionImpl.class, RETURNS_DEEP_STUBS);
facility = new Facility(1, "testFacility");
resource = new Resource(1, "testResource", "desc", 1, 1);
vo = new Vo(1, "testVo", "desc");
user = new User(1, "name", "surname", "middlename", "title", "title");
member = new Member(1, 1, 1, Status.VALID);
banOnResource = new BanOnResource(1, new Date(), "test", 1, 1);
banOnFacility = new BanOnFacility(1, new Date(), "test", 1, 1);
isBanned = new Attribute(classInstance.getAttributeDefinition());
isBanned.setValue(true);
message1 = "Ban " + banOnResource.serializeToString() + " was set for memberId 1 on resourceId 1";
message2 = "Ban " + banOnResource.serializeToString() + " was updated for memberId 1 on resourceId 1";
message3 = "Ban " + banOnResource.serializeToString() + " was removed for memberId 1 on resourceId 1";
message4 = "Ban " + banOnFacility.serializeToString() + " was set for userId 1 on facilityId 1";
message5 = "Ban " + banOnFacility.serializeToString() + " was updated for userId 1 on facilityId 1";
message6 = "Ban " + banOnFacility.serializeToString() + " was removed for userId 1 on facilityId 1";
wrongMessage = "Ban " + banOnFacility.serializeToString() + " was destroyed for userId 1 on facilityId 1";
}
use of cz.metacentrum.perun.core.api.BanOnResource in project perun by CESNET.
the class MembersManagerBlImpl method deleteMember.
public void deleteMember(PerunSession sess, Member member) throws InternalErrorException, MemberAlreadyRemovedException, GroupOperationsException {
Vo vo = this.getMemberVo(sess, member);
User user;
try {
user = getPerunBl().getUsersManagerBl().getUserById(sess, member.getUserId());
} catch (UserNotExistsException e1) {
throw new ConsistencyErrorException("Removing member who doesn't have corresponding user.", e1);
}
List<Facility> allowedFacilities = getPerunBl().getFacilitiesManagerBl().getAllowedFacilities(sess, user);
Map<Facility, List<Attribute>> requiredAttributesBeforeMemberRemove = new HashMap<Facility, List<Attribute>>();
for (Facility facility : allowedFacilities) {
// Get actually required attributes, they will be later compared with list of required attributes when the member will be removed from all resources in this VO
requiredAttributesBeforeMemberRemove.put(facility, getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, facility, user));
}
// Remove member from all groups
List<Group> memberGroups = getPerunBl().getGroupsManagerBl().getMemberDirectGroups(sess, member);
for (Group group : memberGroups) {
// Member must be removed from the members group using separate method
if (group.getName().equals(VosManager.MEMBERS_GROUP))
continue;
try {
getPerunBl().getGroupsManagerBl().removeMember(sess, group, member);
} catch (NotGroupMemberException e) {
throw new ConsistencyErrorException("getMemberGroups return group where the member is not member", e);
} catch (GroupNotExistsException e) {
throw new ConsistencyErrorException(e);
}
}
// Remove member from the VO members group
try {
Group g = getPerunBl().getGroupsManagerBl().getGroupByName(sess, vo, VosManager.MEMBERS_GROUP);
try {
getPerunBl().getGroupsManagerBl().removeMemberFromMembersOrAdministratorsGroup(sess, g, member);
} catch (NotGroupMemberException e) {
throw new ConsistencyErrorException("Member is not in the \"members\" group." + member + " " + g, e);
}
} catch (GroupNotExistsException e) {
throw new InternalErrorException(e);
}
// Remove member's attributes (namespaces: member and resource-member)
try {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, member);
List<Resource> resources = getPerunBl().getResourcesManagerBl().getResources(sess, vo);
for (Resource resource : resources) {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, resource, member);
}
} catch (AttributeValueException ex) {
throw new ConsistencyErrorException("Member is removed from all groups. There are no required attribute for this member. Member's attributes can be removed without problem.", ex);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
// Remove user-facility attributes which are no longer required
for (Facility facility : allowedFacilities) {
List<Attribute> requiredAttributes = requiredAttributesBeforeMemberRemove.get(facility);
//remove currently required attributes from requiredAttributesBeforeMemberRemove
requiredAttributes.removeAll(getPerunBl().getAttributesManagerBl().getRequiredAttributes(sess, facility, user));
//remove attributes which are no longer required
try {
getPerunBl().getAttributesManagerBl().removeAttributes(sess, facility, user, requiredAttributes);
} catch (AttributeValueException | WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
}
//Remove all members bans
List<BanOnResource> bansOnResource = getPerunBl().getResourcesManagerBl().getBansForMember(sess, member.getId());
for (BanOnResource banOnResource : bansOnResource) {
try {
getPerunBl().getResourcesManagerBl().removeBan(sess, banOnResource.getId());
} catch (BanNotExistsException ex) {
//it is ok, we just want to remove it anyway
}
}
/* TODO this can be used for future optimization. If the user is not asigned to the facility anymore all user-facility attributes (for this facility) can be safely removed.
for (Facility facility: facilitiesBeforeMemberRemove) {
// Remove user-facility attributes
try {
getPerunBl().getAttributesManagerBl().removeAllAttributes(sess, facility, user);
log.debug("Removing user-facility attributes for facility {}", facility);
} catch (AttributeValueException e) {
throw new ConsistencyErrorException("Member is removed from all resources. There are no required attribute for this member. User-facility attributes can be removed without problem.", e);
}
}
*/
// Remove member from the DB
getMembersManagerImpl().deleteMember(sess, member);
getPerunBl().getAuditer().log(sess, "{} deleted.", member);
}
Aggregations