use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class LDAPLoginTest method testCreateChangedAttrMap.
@Test
@Ignore
public void testCreateChangedAttrMap() {
Assume.assumeTrue(ldapLoginModule.isLDAPEnabled());
// simulate closed session (user adding from startup job)
DBFactory.getInstance().intermediateCommit();
String uid = "kmeier";
String pwd = "olat";
LDAPError errors = new LDAPError();
boolean usersSyncedAtStartup = ldapLoginModule.isLdapSyncOnStartup();
if (usersSyncedAtStartup) {
try {
// create user but with different attributes - must fail since user already exists
User user = UserManager.getInstance().createUser("klaus", "Meier", "klaus@meier.ch");
Identity identity = securityManager.createAndPersistIdentityAndUser("kmeier", null, user, "LDAP", "kmeier");
SecurityGroup secGroup = securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP);
securityManager.addIdentityToSecurityGroup(identity, secGroup);
// simulate closed session (user adding from startup job)
DBFactory.getInstance().intermediateCommit();
fail("Expected constrant violation becaus of doupliate entry");
} catch (Exception e) {
// success, this is what we expected
}
// changedAttrMap empty since already synchronized
Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
Identity identitys = securityManager.findIdentityByName(uid);
Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
// map is empty - no attributes to sync
assertNull(changedAttrMap);
} else {
// create user but with different attributes - must fail since user already exists
User user = UserManager.getInstance().createUser("klaus", "Meier", "klaus@meier.ch");
Identity identity = securityManager.createAndPersistIdentityAndUser("kmeier", null, user, "LDAP", "kmeier");
SecurityGroup secGroup = securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP);
securityManager.addIdentityToSecurityGroup(identity, secGroup);
// simulate closed session (user adding from startup job)
DBFactory.getInstance().intermediateCommit();
// changedAttrMap has 2 changes and uid as entrys (Klaus!=klaus, klaus@olat.org!=klaus@meier.ch)
Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
Identity identitys = securityManager.findIdentityByName(uid);
Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
// result must be 3: 2 changed plus the user ID which is always in the map
assertEquals(3, changedAttrMap.keySet().size());
}
// nothing to change for this user
uid = "mrohrer";
Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
Identity identitys = securityManager.findIdentityByName(uid);
Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
assertEquals(true, (changedAttrMap == null));
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class EPFrontendManagerTest method deleteMap_withOldPolicy.
@Test
public void deleteMap_withOldPolicy() {
// create map
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("frtuse-7");
PortfolioStructureMap map = epFrontendManager.createAndPersistPortfolioDefaultMap(id, "Delete map", "Description");
PortfolioStructure page = epFrontendManager.createAndPersistPortfolioPage(map, "Page while be deleted", "Page description");
AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(id, "Forum");
epFrontendManager.addArtefactToStructure(id, artefact, page);
dbInstance.commit();
// create an old policy manually
SecurityGroup secGroup = securityManager.createAndPersistSecurityGroup();
Policy policy = securityManager.createAndPersistPolicy(secGroup, "allusers_" + Constants.PERMISSION_READ, map.getOlatResource());
Assert.assertNotNull(policy);
dbInstance.commitAndCloseSession();
// delete the map
PortfolioStructure reloadedMap = epFrontendManager.loadPortfolioStructureByKey(map.getKey());
epFrontendManager.deletePortfolioStructure(reloadedMap);
dbInstance.commit();
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class CourseTest method removeAuthor.
@Test
public void removeAuthor() throws IOException, URISyntaxException {
// make auth1 and auth2 authors
SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
if (!securityManager.isIdentityInSecurityGroup(auth1, authorGroup)) {
securityManager.addIdentityToSecurityGroup(auth1, authorGroup);
}
if (!securityManager.isIdentityInSecurityGroup(auth2, authorGroup)) {
securityManager.addIdentityToSecurityGroup(auth2, authorGroup);
}
dbInstance.intermediateCommit();
// make auth1 and auth2 owner
RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
List<Identity> authors = new ArrayList<>();
authors.add(auth1);
authors.add(auth2);
IdentitiesAddEvent identitiesAddedEvent = new IdentitiesAddEvent(authors);
repositoryManager.addOwners(admin, identitiesAddedEvent, repositoryEntry, null);
dbInstance.intermediateCommit();
// end setup
// test
assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/authors/" + auth1.getKey()).build();
HttpDelete method = conn.createDelete(request, MediaType.APPLICATION_JSON);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
URI request2 = UriBuilder.fromUri(getContextURI()).path("/repo/courses/" + course1.getResourceableId() + "/authors/" + auth2.getKey()).build();
HttpDelete method2 = conn.createDelete(request2, MediaType.APPLICATION_JSON);
HttpResponse response2 = conn.execute(method2);
assertEquals(200, response2.getStatusLine().getStatusCode());
EntityUtils.consume(response2.getEntity());
// control
repositoryEntry = repositoryManager.lookupRepositoryEntry(course1, true);
assertFalse(repositoryService.hasRole(auth1, repositoryEntry, GroupRoles.owner.name()));
assertFalse(repositoryService.hasRole(auth2, repositoryEntry, GroupRoles.owner.name()));
dbInstance.intermediateCommit();
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class CourseTest method addAuthors.
@Test
public void addAuthors() throws IOException, URISyntaxException {
Assert.assertTrue(conn.login("administrator", "openolat"));
ICourse course = CoursesWebService.createEmptyCourse(admin, "course1", "course1 long name", null);
Identity author1 = JunitTestHelper.createAndPersistIdentityAsRndUser("rest-auth-1");
Identity author2 = JunitTestHelper.createAndPersistIdentityAsRndUser("rest-auth-2");
dbInstance.commitAndCloseSession();
UserVO[] newAuthors = new UserVO[2];
newAuthors[0] = UserVOFactory.get(author1);
newAuthors[1] = UserVOFactory.get(author2);
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course.getResourceableId().toString()).path("authors").build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(method, newAuthors);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
// is auth0 author
SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
boolean isAuthor1 = securityManager.isIdentityInSecurityGroup(author1, authorGroup);
boolean isAuthor2 = securityManager.isIdentityInSecurityGroup(author2, authorGroup);
dbInstance.commit();
Assert.assertTrue(isAuthor1);
Assert.assertTrue(isAuthor2);
// is auth0 owner
RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(course, true);
boolean isOwner1 = repositoryService.hasRole(author1, repositoryEntry, GroupRoles.owner.name());
boolean isOwner2 = repositoryService.hasRole(author2, repositoryEntry, GroupRoles.owner.name());
dbInstance.commit();
Assert.assertTrue(isOwner1);
Assert.assertTrue(isOwner2);
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class EPShareListController method createContainerForInvitation.
private void createContainerForInvitation(Invitation invitation, EPSharePolicyWrapper policyWrapper, String cmpName, FormLayoutContainer container) {
FormLayoutContainer invitationContainer = FormLayoutContainer.createDefaultFormLayout("map.share.with." + cmpName, getTranslator());
invitationContainer.contextPut("wrapper", policyWrapper);
invitationContainer.setRootForm(mainForm);
container.add("map.share.with." + cmpName, invitationContainer);
TextElement firstNameEl = uifactory.addTextElement("map.share.with.firstName." + cmpName, "map.share.with.firstName", 64, invitation.getFirstName(), invitationContainer);
firstNameEl.setMandatory(true);
firstNameEl.setNotEmptyCheck("map.share.empty.warn");
TextElement lastNameEl = uifactory.addTextElement("map.share.with.lastName." + cmpName, "map.share.with.lastName", 64, invitation.getLastName(), invitationContainer);
lastNameEl.setMandatory(true);
lastNameEl.setNotEmptyCheck("map.share.empty.warn");
TextElement mailEl = uifactory.addTextElement("map.share.with.mail." + cmpName, "map.share.with.mail", 128, invitation.getMail(), invitationContainer);
mailEl.setMandatory(true);
mailEl.setNotEmptyCheck("map.share.empty.warn");
if (StringHelper.containsNonWhitespace(invitation.getMail()) && MailHelper.isValidEmailAddress(invitation.getMail())) {
SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
List<Identity> shareWithIdentities = userManager.findIdentitiesByEmail(Collections.singletonList(invitation.getMail()));
if (isAtLeastOneInSecurityGroup(shareWithIdentities, allUsers)) {
mailEl.setErrorKey("map.share.with.mail.error.olatUser", new String[] { invitation.getMail() });
}
}
policyWrapper.setFirstNameEl(firstNameEl);
policyWrapper.setLastNameEl(lastNameEl);
policyWrapper.setMailEl(mailEl);
String link = getInvitationLink(invitation, map);
StaticTextElement linkEl = uifactory.addStaticTextElement("map.share.with.link." + cmpName, link, invitationContainer);
linkEl.setLabel("map.share.with.link", null);
}
Aggregations