use of cz.metacentrum.perun.core.api.CandidateSync in project perun by CESNET.
the class ExtSourcesManagerBlImpl method getCandidate.
@Override
public CandidateSync getCandidate(PerunSession perunSession, Map<String, String> subjectData, ExtSource source, String login) {
if (login == null || login.isEmpty())
throw new InternalErrorException("Login can't be empty or null.");
if (subjectData == null || subjectData.isEmpty())
throw new InternalErrorException("Subject data can't be null or empty, at least login there must exists.");
// New Canddate
CandidateSync candidateSync = new CandidateSync();
// Prepare userExtSource object
UserExtSource userExtSource = new UserExtSource();
userExtSource.setExtSource(source);
userExtSource.setLogin(login);
// If first name of candidate is not in format of name, set null instead
candidateSync.setFirstName(subjectData.get("firstName"));
if (candidateSync.getFirstName() != null) {
Matcher name = namePattern.matcher(candidateSync.getFirstName());
if (!name.matches())
candidateSync.setFirstName(null);
}
// If last name of candidate is not in format of name, set null instead
candidateSync.setLastName(subjectData.get("lastName"));
if (candidateSync.getLastName() != null) {
Matcher name = namePattern.matcher(candidateSync.getLastName());
if (!name.matches())
candidateSync.setLastName(null);
}
candidateSync.setMiddleName(subjectData.get("middleName"));
candidateSync.setTitleAfter(subjectData.get("titleAfter"));
candidateSync.setTitleBefore(subjectData.get("titleBefore"));
// Set service user
if (subjectData.get("isServiceUser") == null) {
candidateSync.setServiceUser(false);
} else {
String isServiceUser = subjectData.get("isServiceUser");
candidateSync.setServiceUser(isServiceUser.equals("true"));
}
// Set sponsored user
if (subjectData.get("isSponsoredUser") == null) {
candidateSync.setSponsoredUser(false);
} else {
String isSponsoredUser = subjectData.get("isSponsoredUser");
candidateSync.setSponsoredUser(isSponsoredUser.equals("true"));
}
// Filter attributes
Map<String, String> attributes = new HashMap<>();
for (String attrName : subjectData.keySet()) {
// FIXME volat metody z attributesManagera nez kontrolovat na zacatek jmena
if (attrName.startsWith(AttributesManager.NS_MEMBER_ATTR) || attrName.startsWith(AttributesManager.NS_USER_ATTR)) {
attributes.put(attrName, subjectData.get(attrName));
}
}
candidateSync.setRichUserExtSource(new RichUserExtSource(userExtSource, new ArrayList<>()));
candidateSync.setAdditionalRichUserExtSources(Utils.extractAdditionalUserExtSources(perunSession, subjectData));
candidateSync.setAttributes(attributes);
return candidateSync;
}
use of cz.metacentrum.perun.core.api.CandidateSync in project perun by CESNET.
the class GroupAndGroupStructureSynchronizationIntegrationTest method synchronizeGroupUpdateExistingMemberStatus.
@Test
public void synchronizeGroupUpdateExistingMemberStatus() throws Exception {
System.out.println(CLASS_NAME + "synchronizeGroupUpdateExistingMemberStatus");
when(extSourceManagerBl.getExtSourceByName(sess, ExtSourcesManager.EXTSOURCE_NAME_PERUN)).thenReturn(extSourceForUserCreation);
Attribute attr = attributesManagerBl.getAttribute(sess, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME);
attr.setValue(extSource.getName());
attributesManagerBl.setAttribute(sess, group, attr);
List<Map<String, String>> subjects = new ArrayList<>();
Map<String, String> attributes = new HashMap<>();
attributes.put("login", "metodej");
subjects.add(attributes);
Candidate candidate = setUpCandidate();
member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
perun.getMembersManagerBl().setStatus(sess, member, Status.DISABLED);
groupsManagerBl.addMember(sess, group, member);
when(extSourceManagerBl.getCandidate(sess, attributes, (ExtSourceLdap) essa, "metodej")).thenReturn(new CandidateSync(candidate));
when(essa.getGroupSubjects(anyMap())).thenReturn(subjects);
assertEquals(Status.DISABLED, groupsManagerBl.getGroupMembers(sess, group).get(0).getStatus());
groupsManagerBl.synchronizeGroup(sess, group);
assertEquals(Status.VALID, groupsManagerBl.getGroupMembers(sess, group).get(0).getStatus());
}
use of cz.metacentrum.perun.core.api.CandidateSync in project perun by CESNET.
the class GroupAndGroupStructureSynchronizationIntegrationTest method synchronizeGroupUpdateFirstNameOfMember.
@Test
public void synchronizeGroupUpdateFirstNameOfMember() throws Exception {
System.out.println(CLASS_NAME + "synchronizeGroupUpdateFirstNameOfMember");
when(extSourceManagerBl.getExtSourceByName(sess, ExtSourcesManager.EXTSOURCE_NAME_PERUN)).thenReturn(extSourceForUserCreation);
Attribute attr = attributesManagerBl.getAttribute(sess, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME);
attr.setValue(extSource.getName());
attributesManagerBl.setAttribute(sess, group, attr);
List<Map<String, String>> subjects = new ArrayList<>();
Map<String, String> attributes = new HashMap<>();
attributes.put("login", "metodej");
subjects.add(attributes);
Candidate candidate = setUpCandidate();
member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
groupsManagerBl.addMember(sess, group, member);
candidate.setFirstName("metodej");
Attribute attribute = perun.getAttributesManagerBl().getAttribute(sess, perun.getUsersManagerBl().getUserByMember(sess, member), AttributesManager.NS_USER_ATTR_CORE + ":firstName");
Map<String, String> candidateAttrs = new HashMap<>();
candidateAttrs.put(attribute.getName(), attribute.valueAsString());
candidate.setAttributes(candidateAttrs);
Map<String, String> map = new HashMap<>();
map.put("overwriteUserAttributes", attribute.getName());
when(extSourceManagerBl.getCandidate(sess, attributes, (ExtSourceLdap) essa, "metodej")).thenReturn(new CandidateSync(candidate));
when(essa.getGroupSubjects(anyMap())).thenReturn(subjects);
doReturn(map).when(extSourceManagerBl).getAttributes((ExtSourceLdap) essa);
assertNotEquals(candidate.getFirstName(), perun.getUsersManagerBl().getUserByMember(sess, member).getFirstName());
groupsManagerBl.synchronizeGroup(sess, group);
assertEquals(candidate.getFirstName(), perun.getUsersManagerBl().getUserByMember(sess, member).getFirstName());
}
use of cz.metacentrum.perun.core.api.CandidateSync in project perun by CESNET.
the class GroupAndGroupStructureSynchronizationIntegrationTest method synchronizeGroupMergeMemberAttributeValue.
@Test
public void synchronizeGroupMergeMemberAttributeValue() throws Exception {
System.out.println(CLASS_NAME + "synchronizeGroupMergeMemberAttributeValue");
when(extSourceManagerBl.getExtSourceByName(sess, ExtSourcesManager.EXTSOURCE_NAME_PERUN)).thenReturn(extSourceForUserCreation);
Attribute attr = attributesManagerBl.getAttribute(sess, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME);
attr.setValue(extSource.getName());
attributesManagerBl.setAttribute(sess, group, attr);
List<Map<String, String>> subjects = new ArrayList<>();
Map<String, String> attributes = new HashMap<>();
attributes.put("login", "metodej");
subjects.add(attributes);
Candidate candidate = setUpCandidate();
member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
groupsManagerBl.addMember(sess, group, member);
candidate.setFirstName("metodej");
Attribute attribute = new Attribute();
String namespace = "member-test-unique-attribute:specialNamespace";
attribute.setNamespace(AttributesManager.NS_MEMBER_ATTR_DEF);
attribute.setFriendlyName(namespace + "1");
attribute.setType(ArrayList.class.getName());
attribute.setValue(Stream.of("value1", "value2").collect(Collectors.toList()));
assertNotNull("unable to create member attribute", attributesManagerBl.createAttribute(sess, attribute));
Map<String, String> candidateAttrs = new HashMap<>();
candidateAttrs.put(attribute.getName(), "value2,value3");
candidate.setAttributes(candidateAttrs);
attributesManagerBl.setAttribute(sess, member, attribute);
Map<String, String> map = new HashMap<>();
map.put("mergeMemberAttributes", attribute.getName());
when(extSourceManagerBl.getCandidate(sess, attributes, (ExtSourceLdap) essa, "metodej")).thenReturn(new CandidateSync(candidate));
when(essa.getGroupSubjects(anyMap())).thenReturn(subjects);
doReturn(map).when(extSourceManagerBl).getAttributes((ExtSourceLdap) essa);
assertEquals(2, attributesManagerBl.getAttribute(sess, member, attribute.getName()).valueAsList().size());
groupsManagerBl.synchronizeGroup(sess, group);
assertEquals(3, attributesManagerBl.getAttribute(sess, member, attribute.getName()).valueAsList().size());
}
use of cz.metacentrum.perun.core.api.CandidateSync in project perun by CESNET.
the class GroupAndGroupStructureSynchronizationIntegrationTest method synchronizeGroupAddMissingMemberWhileCandidateAlreadyMember.
@Test
public void synchronizeGroupAddMissingMemberWhileCandidateAlreadyMember() throws Exception {
System.out.println(CLASS_NAME + "synchronizeGroupAddMissingMemberWhileCandidateAlreadyMember");
when(extSourceManagerBl.getExtSourceByName(sess, ExtSourcesManager.EXTSOURCE_NAME_PERUN)).thenReturn(extSourceForUserCreation);
Attribute attr = attributesManagerBl.getAttribute(sess, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME);
attr.setValue(extSource.getName());
attributesManagerBl.setAttribute(sess, group, attr);
List<Map<String, String>> subjects = new ArrayList<>();
Map<String, String> attributes = new HashMap<>();
attributes.put("login", "metodej");
subjects.add(attributes);
Candidate candidate = setUpCandidate();
member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
when(extSourceManagerBl.getCandidate(sess, attributes, (ExtSourceLdap) essa, "metodej")).thenReturn(new CandidateSync(candidate));
when(essa.getGroupSubjects(anyMap())).thenReturn(subjects);
assertEquals(0, groupsManagerBl.getGroupMembers(sess, group).size());
groupsManagerBl.synchronizeGroup(sess, group);
assertEquals(1, groupsManagerBl.getGroupMembers(sess, group).size());
}
Aggregations