use of cz.metacentrum.perun.core.bl.GroupsManagerBl in project perun by CESNET.
the class RegistrarBaseIntegrationTest method testRejectApplicationsAfterMemberRemoval.
@Test
public void testRejectApplicationsAfterMemberRemoval() throws PerunException {
GroupsManagerBl groupsManager = perun.getGroupsManagerBl();
MembersManagerBl membersManager = perun.getMembersManagerBl();
// create group in VO, generate group application form
Group group1 = new Group("GroupA", "Cool folks");
groupsManager.createGroup(session, vo, group1);
registrarManager.createApplicationFormInGroup(session, group1);
// create user
User user = new User(-1, "Jo", "Doe", "", "", "");
user = perun.getUsersManagerBl().createUser(session, user);
Member member = membersManager.createMember(session, vo, user);
Application groupApplication = prepareApplicationToGroup(user, group1);
List<ApplicationFormItemData> appItemsData = new ArrayList<>();
registrarManager.submitApplication(session, groupApplication, appItemsData);
membersManager.deleteMember(session, member);
List<Application> group1Apps = registrarManager.getApplicationsForGroup(session, group1, List.of("REJECTED"));
assertEquals(1, group1Apps.size());
}
use of cz.metacentrum.perun.core.bl.GroupsManagerBl in project perun by CESNET.
the class GroupSynchronizer method synchronizeGroups.
public void synchronizeGroups() {
PerunBl perun = (PerunBl) ldapcManager.getPerunBl();
boolean shouldWriteExceptionLog = true;
try {
log.debug("Group synchronization - getting list of VOs");
List<Vo> vos = perun.getVosManagerBl().getVos(ldapcManager.getPerunSession());
Set<Name> presentGroups = new HashSet<Name>();
for (Vo vo : vos) {
try {
log.debug("Getting list of groups for VO {}", vo);
List<Group> groups = perun.getGroupsManagerBl().getAllGroups(ldapcManager.getPerunSession(), vo);
for (Group group : groups) {
presentGroups.add(perunGroup.getEntryDN(String.valueOf(vo.getId()), String.valueOf(group.getId())));
log.debug("Synchronizing group {}", group);
log.debug("Getting list of attributes for group {}", group.getId());
List<Attribute> attrs = new ArrayList<Attribute>();
List<String> attrNames = fillPerunAttributeNames(perunGroup.getPerunAttributeNames());
try {
attrs.addAll(perun.getAttributesManagerBl().getAttributes(ldapcManager.getPerunSession(), group, attrNames));
} catch (PerunRuntimeException e) {
log.warn("Couldn't get attributes {} for group {}: {}", attrNames, group.getId(), e.getMessage());
shouldWriteExceptionLog = false;
throw new InternalErrorException(e);
}
log.debug("Got attributes {}", attrNames.toString());
try {
log.debug("Getting list of members for group {}", group.getId());
// List<Member> members = ldapcManager.getRpcCaller().call("groupsManager", "getGroupMembers", params).readList(Member.class);
List<Member> members = perun.getGroupsManagerBl().getActiveGroupMembers(ldapcManager.getPerunSession(), group, Status.VALID);
log.debug("Synchronizing {} members of group {}", members.size(), group.getId());
// perunGroup.synchronizeMembers(group, members);
log.debug("Getting list of resources assigned to group {}", group.getId());
// List<Resource> resources = Rpc.ResourcesManager.getAssignedResources(ldapcManager.getRpcCaller(), group);
List<Resource> resources = perun.getResourcesManagerBl().getAssignedResources(ldapcManager.getPerunSession(), group);
log.debug("Synchronizing {} resources assigned to group {}", resources.size(), group.getId());
// perunGroup.synchronizeResources(group, resources);
GroupsManagerBl groupsManager = perun.getGroupsManagerBl();
List<Group> admin_groups = groupsManager.getGroupsWhereGroupIsAdmin(ldapcManager.getPerunSession(), group);
List<Vo> admin_vos = groupsManager.getVosWhereGroupIsAdmin(ldapcManager.getPerunSession(), group);
List<Facility> admin_facilities = groupsManager.getFacilitiesWhereGroupIsAdmin(ldapcManager.getPerunSession(), group);
log.debug("Synchronizing group {} as admin of {} groups, {} VOs and {} facilities", group.getId(), admin_groups.size(), admin_vos.size(), admin_facilities.size());
perunGroup.synchronizeGroup(group, attrs, members, resources, admin_groups, admin_vos, admin_facilities);
} catch (PerunRuntimeException e) {
log.error("Error synchronizing group", e);
shouldWriteExceptionLog = false;
throw new InternalErrorException(e);
}
}
} catch (PerunRuntimeException e) {
if (shouldWriteExceptionLog) {
log.error("Error synchronizing groups", e);
}
shouldWriteExceptionLog = false;
throw new InternalErrorException(e);
}
}
try {
removeOldEntries(perunGroup, presentGroups, log);
} catch (InternalErrorException e) {
log.error("Error removing old group entries", e);
shouldWriteExceptionLog = false;
throw new InternalErrorException(e);
}
} catch (InternalErrorException e) {
if (shouldWriteExceptionLog) {
log.error("Error reading list of VOs", e);
}
throw new InternalErrorException(e);
}
}
use of cz.metacentrum.perun.core.bl.GroupsManagerBl in project perun by CESNET.
the class urn_perun_user_attribute_def_virt_eduPersonScopedAffiliations method getAffiliationsFromGroups.
/**
* Collect affiliations from perun Groups
* @param sess Perun session
* @param user User for whom the values should be collected
* @return Set of collected affiliations
* @throws InternalErrorException When some error occurs, see exception cause for details.
*/
private Set<String> getAffiliationsFromGroups(PerunSessionImpl sess, User user) {
Set<String> result = new HashSet<>();
List<Member> validVoMembers = sess.getPerunBl().getMembersManagerBl().getMembersByUserWithStatus(sess, user, Status.VALID);
GroupsManagerBl groupsManagerBl = sess.getPerunBl().getGroupsManagerBl();
Set<Group> groupsForAttrCheck = new HashSet<>();
for (Member member : validVoMembers) {
groupsForAttrCheck.addAll(groupsManagerBl.getGroupsWhereMemberIsActive(sess, member));
}
if (!groupsForAttrCheck.isEmpty()) {
try {
// check, if attribute exists
sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, getTertiarySourceAttributeName());
} catch (AttributeNotExistsException e) {
log.debug("Attribute " + getTertiarySourceAttributeFriendlyName() + " does not exist", e);
return result;
}
}
for (Group group : groupsForAttrCheck) {
try {
Attribute groupAffiliations = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, getTertiarySourceAttributeName());
if (groupAffiliations != null && groupAffiliations.valueAsList() != null) {
result.addAll(groupAffiliations.valueAsList());
}
} catch (WrongAttributeAssignmentException e) {
throw new InternalErrorException("Wrong assignment of " + getTertiarySourceAttributeFriendlyName() + " for user " + user.getId(), e);
} catch (AttributeNotExistsException e) {
log.debug("Attribute " + getTertiarySourceAttributeFriendlyName() + " of group " + group.getId() + " does not exist, values will be skipped", e);
}
}
return result;
}
use of cz.metacentrum.perun.core.bl.GroupsManagerBl in project perun by CESNET.
the class urn_perun_group_attribute_def_virt_adDisplayName_o365muTest method setUp.
@Before
public void setUp() throws Exception {
// prepare mocks
sess = mock(PerunSessionImpl.class);
PerunBl perunBl = mock(PerunBl.class);
AttributesManagerBl am = mock(AttributesManagerBl.class);
GroupsManagerBl gm = mock(GroupsManagerBl.class);
when(sess.getPerunBl()).thenReturn(perunBl);
when(perunBl.getAttributesManagerBl()).thenReturn(am);
when(perunBl.getGroupsManagerBl()).thenReturn(gm);
when(sess.getPerunBl().getGroupsManagerBl().getParentGroup(sess, groupB)).thenReturn(groupA);
when(sess.getPerunBl().getGroupsManagerBl().getParentGroup(sess, groupC)).thenReturn(groupB);
when(sess.getPerunBl().getGroupsManagerBl().getParentGroup(sess, groupD)).thenReturn(groupC);
when(sess.getPerunBl().getGroupsManagerBl().getParentGroup(sess, groupE)).thenReturn(groupD);
when(sess.getPerunBl().getGroupsManagerBl().getParentGroup(sess, groupF)).thenReturn(groupA);
// group A is the main group with cispr 000000, it has no default display name
setWhenClauseByParametersForGroup(sess, groupA, null, "000000", groupA.getName(), groupA.getDescription(), typeOfWorkplacesA);
// group B is special group which should return null on display name
setWhenClauseByParametersForGroup(sess, groupB, null, "000001", groupB.getName(), groupB.getDescription(), typeOfWorkplacesA);
// group C is other part of university, it has no default display name
setWhenClauseByParametersForGroup(sess, groupC, null, "110000", groupC.getName(), groupC.getDescription(), typeOfWorkplacesB);
// group D is special group with predefined display name
setWhenClauseByParametersForGroup(sess, groupD, predefinedDisplayName, null, null, null, null);
// group E is other type of group, it has no default display name
setWhenClauseByParametersForGroup(sess, groupE, null, "123456", groupE.getName(), groupE.getDescription(), typeOfWorkplacesC);
// group E is other type of group, it has no default display name, but displayName is missing
setWhenClauseByParametersForGroup(sess, groupF, null, "654321", groupF.getName(), groupF.getDescription(), typeOfWorkplacesB);
when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, groupWithoutAttributes, defaultAdDisplayNameAttrDef.getName())).thenThrow(AttributeNotExistsException.class);
when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, groupWithoutAttributes, inetCisprAttrDef.getName())).thenThrow(AttributeNotExistsException.class);
when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, groupWithoutAttributes, inetWorkplacesTypeCSAttrDef.getName())).thenThrow(AttributeNotExistsException.class);
}
use of cz.metacentrum.perun.core.bl.GroupsManagerBl in project perun by CESNET.
the class urn_perun_group_attribute_def_def_groupExtSourceTest method setUp.
@Before
public void setUp() throws Exception {
classInstance = new urn_perun_group_attribute_def_def_groupExtSource();
attributeToCheck = new Attribute(classInstance.getAttributeDefinition());
sess = mock(PerunSessionImpl.class);
PerunBl perunBl = mock(PerunBl.class);
when(sess.getPerunBl()).thenReturn(perunBl);
GroupsManagerBl groupsManagerBl = mock(GroupsManagerBl.class);
when(perunBl.getGroupsManagerBl()).thenReturn(groupsManagerBl);
Vo groupVo = mock(Vo.class);
VosManagerBl vosManagerBl = mock(VosManagerBl.class);
when(perunBl.getVosManagerBl()).thenReturn(vosManagerBl);
when(sess.getPerunBl().getVosManagerBl().getVoById(sess, group.getVoId())).thenReturn(groupVo);
ExtSource extSource = new ExtSource(1, "my_example", "type");
ExtSourcesManagerBl extSourcesManagerBl = mock(ExtSourcesManagerBl.class);
when(sess.getPerunBl().getExtSourcesManagerBl()).thenReturn(extSourcesManagerBl);
when(sess.getPerunBl().getExtSourcesManagerBl().getVoExtSources(sess, groupVo)).thenReturn(Collections.singletonList(extSource));
}
Aggregations