use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class UserPersistentShadowAttribute method changedAttributeHook.
/**
* ChangedAttributeHook() sets UserExtSource with following properties:
* - extSourceType is IdP
* - extSourceName is {getExtSourceName()}
* - user's extSource login is the same as his persistent attribute
*/
@Override
public void changedAttributeHook(PerunSessionImpl session, User user, Attribute attribute) {
try {
String userNamespace = attribute.getFriendlyNameParameter();
if (userNamespace.equals(getFriendlyNameParameter()) && attribute.getValue() != null) {
ExtSource extSource = session.getPerunBl().getExtSourcesManagerBl().getExtSourceByName(session, getExtSourceName());
UserExtSource userExtSource = new UserExtSource(extSource, 0, attribute.getValue().toString());
session.getPerunBl().getUsersManagerBl().addUserExtSource(session, user, userExtSource);
}
} catch (UserExtSourceExistsException ex) {
log.warn("Attribute: {}, External source already exists for the user.", getFriendlyNameParameter(), ex);
} catch (ExtSourceNotExistsException ex) {
throw new InternalErrorException("Attribute: " + getFriendlyNameParameter() + ", IdP external source doesn't exist.", ex);
}
}
use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class ResourcesManagerEntryIntegrationTest method getAdmins.
@Test
public void getAdmins() throws Exception {
System.out.println(CLASS_NAME + "getAdmins");
vo = setUpVo();
facility = setUpFacility();
resource = setUpResource();
// Set up resource admin
member = setUpMember(vo);
User user = perun.getUsersManagerBl().getUserByMember(sess, member);
resourcesManager.addAdmin(sess, resource, user);
// Set up resource admin group
group = setUpGroup(vo, member);
resourcesManager.addAdmin(sess, resource, group);
// Set up second resource admin
Candidate candidate = new Candidate();
candidate.setFirstName("Josef");
candidate.setId(4);
candidate.setMiddleName("");
candidate.setLastName("Novak");
candidate.setTitleBefore("");
candidate.setTitleAfter("");
UserExtSource userExtSource = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), Long.toHexString(Double.doubleToLongBits(Math.random())));
candidate.setUserExtSource(userExtSource);
candidate.setAttributes(new HashMap<>());
Member member2 = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
User user2 = perun.getUsersManagerBl().getUserByMember(sess, member2);
perun.getGroupsManager().addMember(sess, group, member2);
// Test all admins
List<User> admins = resourcesManager.getAdmins(sess, resource, false);
assertTrue("list shoud have 2 admins", admins.size() == 2);
assertTrue("our member as direct user should be admin", admins.contains(user));
assertTrue("our member as member of admin group should be admin", admins.contains(user2));
// Test only direct admins (without groups of admins)
admins = resourcesManager.getAdmins(sess, resource, true);
assertTrue("list should have only 1 admin", admins.size() == 1);
assertTrue("our member as direct user should be in list of admins", admins.contains(user));
assertTrue("our member as member of admin group shouldn't be in list of admins", !admins.contains(user2));
}
use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class UsersManagerEntryIntegrationTest method addUserExtSource.
@Test
public void addUserExtSource() throws Exception {
System.out.println(CLASS_NAME + "addUserExtSource");
ExtSource externalSource = perun.getExtSourcesManager().getExtSourceByName(sess, extSourceName);
UserExtSource userExtSource2 = new UserExtSource();
userExtSource2.setLogin(extLogin2);
userExtSource2.setExtSource(externalSource);
UserExtSource returnedUserExtSource = usersManager.addUserExtSource(sess, user, userExtSource2);
assertNotNull(returnedUserExtSource);
assertTrue(returnedUserExtSource.getId() > 0);
assertEquals("Both User Ext Sources should be the same", userExtSource2, returnedUserExtSource);
}
use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class UsersManagerEntryIntegrationTest method setUpUserExtSource.
private void setUpUserExtSource() throws Exception {
ExtSource externalSource = perun.getExtSourcesManager().getExtSourceByName(sess, extSourceName);
// gets real external source object from database
userExtSource.setExtSource(externalSource);
// put real external source into user's external source
userExtSource.setLogin(extLogin);
// set users login in his ext source
assertNotNull(usersManager.addUserExtSource(sess, user, userExtSource));
// create new user ext source in database
}
use of cz.metacentrum.perun.core.api.ExtSource in project perun by CESNET.
the class GroupsManagerBlImpl method synchronizeGroupStructure.
@Override
public List<String> synchronizeGroupStructure(PerunSession sess, Group baseGroup) throws AttributeNotExistsException, WrongAttributeAssignmentException, ExtSourceNotExistsException, WrongAttributeValueException, WrongReferenceAttributeValueException {
List<String> skippedGroups = new ArrayList<>();
log.info("Group structure synchronization {}: started.", baseGroup);
// get extSource for group structure
ExtSource source = getGroupExtSourceForSynchronization(sess, baseGroup);
try {
// get login attribute for structure
AttributeDefinition loginAttributeDefinition = getLoginAttributeForGroupStructure(sess, baseGroup);
// get login prefix if exists
String loginPrefix = getLoginPrefixForGroupStructure(sess, baseGroup);
List<CandidateGroup> candidateGroupsToAdd = new ArrayList<>();
Map<CandidateGroup, Group> groupsToUpdate = new HashMap<>();
List<Group> groupsToRemove = new ArrayList<>();
Map<String, Group> actualGroups = getAllSubGroupsWithLogins(sess, baseGroup, loginAttributeDefinition);
List<Map<String, String>> subjectGroups = getSubjectGroupsFromExtSource(sess, source, baseGroup);
if (isThisFlatSynchronization(sess, baseGroup)) {
for (Map<String, String> subjectGroup : subjectGroups) {
subjectGroup.put(PARENT_GROUP_LOGIN, null);
}
}
List<String> mergeAttributes = getAttributesListFromExtSource(source, MERGE_GROUP_ATTRIBUTES);
List<CandidateGroup> candidateGroups = getPerunBl().getExtSourcesManagerBl().generateCandidateGroups(sess, subjectGroups, source, loginPrefix);
categorizeGroupsForSynchronization(actualGroups, candidateGroups, candidateGroupsToAdd, groupsToUpdate, groupsToRemove);
// order of operations is important here
// removing need to go first to be able to replace groups with same name but different login
// updating need to be last to set right order of groups again
List<Integer> removedGroupsIds = removeFormerGroupsWhileSynchronization(sess, baseGroup, groupsToRemove, skippedGroups);
addMissingGroupsWhileSynchronization(sess, baseGroup, candidateGroupsToAdd, loginAttributeDefinition, skippedGroups, mergeAttributes);
updateExistingGroupsWhileSynchronization(sess, baseGroup, groupsToUpdate, removedGroupsIds, loginAttributeDefinition, skippedGroups, mergeAttributes);
setUpSynchronizationAttributesForAllSubGroups(sess, baseGroup, source, loginAttributeDefinition, loginPrefix);
syncResourcesForSynchronization(sess, baseGroup, loginAttributeDefinition, skippedGroups);
log.info("Group structure synchronization {}: ended.", baseGroup);
return skippedGroups;
} finally {
if (source instanceof ExtSourceSimpleApi) {
try {
((ExtSourceSimpleApi) source).close();
} catch (ExtSourceUnsupportedOperationException e) {
// silently skip
} catch (Exception e) {
log.error("Failed to close extsource after structure synchronization.", e);
}
}
}
}
Aggregations