use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class LDAPLoginTest method testCronSync.
@Test
@Ignore
public void testCronSync() throws Exception {
Assume.assumeTrue(ldapLoginModule.isLDAPEnabled());
LdapContext ctx;
List<LDAPUser> ldapUserList;
List<Attributes> newLdapUserList;
Map<Identity, Map<String, String>> changedMapIdenityMap;
List<Identity> deletedUserList;
LDAPError errors = new LDAPError();
// find user changed after 2010,01,09,00,00
ctx = ldapManager.bindSystem();
Calendar cal = Calendar.getInstance();
cal.set(2010, 0, 10, 0, 0, 0);
Date syncDate = cal.getTime();
ldapUserList = ldapDao.getUserAttributesModifiedSince(syncDate, ctx);
assertEquals(1, ldapUserList.size());
// find all users
syncDate = null;
ldapUserList = ldapDao.getUserAttributesModifiedSince(syncDate, ctx);
assertEquals(6, ldapUserList.size());
// prepare create- and sync-Lists for each user from defined syncTime
Identity idenity;
Map<String, String> changedAttrMap;
newLdapUserList = new LinkedList<Attributes>();
changedMapIdenityMap = new HashMap<Identity, Map<String, String>>();
for (int i = 0; i < ldapUserList.size(); i++) {
Attributes userAttrs = ldapUserList.get(i).getAttributes();
String user = getAttributeValue(userAttrs.get(syncConfiguration.getOlatPropertyToLdapAttribute("userID")));
idenity = ldapManager.findIdentityByLdapAuthentication(userAttrs, errors);
if (idenity != null) {
changedAttrMap = ldapManager.prepareUserPropertyForSync(userAttrs, idenity);
if (changedAttrMap != null)
changedMapIdenityMap.put(idenity, changedAttrMap);
} else {
if (errors.isEmpty()) {
String[] reqAttrs = syncConfiguration.checkRequestAttributes(userAttrs);
if (reqAttrs == null)
newLdapUserList.add(userAttrs);
else
System.out.println("Cannot create User " + user + " required Attributes are missing");
} else
System.out.println(errors.get());
}
}
// create Users in LDAP Group only existing in OLAT
User user1 = UserManager.getInstance().createUser("hansi", "hürlima", "hansi@hansli.com");
Identity identity1 = securityManager.createAndPersistIdentityAndUser("hansi", null, user1, "LDAP", "hansi");
SecurityGroup secGroup1 = securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP);
securityManager.addIdentityToSecurityGroup(identity1, secGroup1);
user1 = UserManager.getInstance().createUser("chaspi", "meier", "chaspi@hansli.com");
identity1 = securityManager.createAndPersistIdentityAndUser("chaspi", null, user1, "LDAP", "chaspi");
securityManager.addIdentityToSecurityGroup(identity1, secGroup1);
// create User to Delete List
deletedUserList = ldapManager.getIdentitysDeletedInLdap(ctx);
assertEquals(4, (deletedUserList.size()));
// sync users
Iterator<Identity> itrIdent = changedMapIdenityMap.keySet().iterator();
while (itrIdent.hasNext()) {
Identity ident = itrIdent.next();
ldapManager.syncUser(changedMapIdenityMap.get(ident), ident);
}
// create all users
for (int i = 0; i < newLdapUserList.size(); i++) {
ldapManager.createAndPersistUser(newLdapUserList.get(i));
}
// delete all users
ldapManager.deletIdentities(deletedUserList);
// check if users are deleted
deletedUserList = ldapManager.getIdentitysDeletedInLdap(ctx);
assertEquals(0, (deletedUserList.size()));
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class LDAPLoginTest method testIdentityDeletedInLDAP.
@Test
@Ignore
public void testIdentityDeletedInLDAP() {
Assume.assumeTrue(ldapLoginModule.isLDAPEnabled());
List<Identity> deletList;
// should be empty
LdapContext ctx = ldapManager.bindSystem();
deletList = ldapManager.getIdentitysDeletedInLdap(ctx);
assertEquals(0, (deletList.size()));
// simulate closed session (user adding from startup job)
DBFactory.getInstance().intermediateCommit();
// create some users in LDAPSecurityGroup
User user = UserManager.getInstance().createUser("grollia", "wa", "gorrila@olat.org");
Identity identity = securityManager.createAndPersistIdentityAndUser("gorilla", null, user, "LDAP", "gorrila");
SecurityGroup secGroup1 = securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP);
securityManager.addIdentityToSecurityGroup(identity, secGroup1);
user = UserManager.getInstance().createUser("wer", "immer", "immer@olat.org");
identity = securityManager.createAndPersistIdentityAndUser("der", null, user, "LDAP", "der");
securityManager.addIdentityToSecurityGroup(identity, secGroup1);
user = UserManager.getInstance().createUser("die", "da", "chaspi@olat.org");
identity = securityManager.createAndPersistIdentityAndUser("das", null, user, "LDAP", "das");
securityManager.addIdentityToSecurityGroup(identity, secGroup1);
// simulate closed session
DBFactory.getInstance().intermediateCommit();
// 3 members in LDAP group but not existing in OLAT
deletList = ldapManager.getIdentitysDeletedInLdap(ctx);
assertEquals(3, (deletList.size()));
// delete user in OLAT
securityManager.removeIdentityFromSecurityGroup(identity, secGroup1);
UserDeletionManager.getInstance().deleteIdentity(identity);
// simulate closed session
DBFactory.getInstance().intermediateCommit();
// 2 members in LDAP group but not existing in OLAT
deletList = ldapManager.getIdentitysDeletedInLdap(ctx);
assertEquals(2, (deletList.size()));
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class OAuthRegistrationController method formOK.
@Override
protected void formOK(UserRequest ureq) {
String lang = langEl.getSelectedKey();
String username = usernameEl.getValue();
OAuthUser oauthUser = registration.getOauthUser();
User newUser = userManager.createUser(null, null, null);
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
FormItem propertyItem = this.flc.getFormComponent(userPropertyHandler.getName());
userPropertyHandler.updateUserFromFormItem(newUser, propertyItem);
}
// Init preferences
newUser.getPreferences().setLanguage(lang);
newUser.getPreferences().setInformSessionTimeout(true);
String id;
if (StringHelper.containsNonWhitespace(oauthUser.getId())) {
id = oauthUser.getId();
} else if (StringHelper.containsNonWhitespace(oauthUser.getEmail())) {
id = oauthUser.getEmail();
} else {
id = username;
}
authenticatedIdentity = securityManager.createAndPersistIdentityAndUser(username, null, newUser, registration.getAuthProvider(), id, null);
// Add user to system users group
SecurityGroup olatuserGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
securityManager.addIdentityToSecurityGroup(authenticatedIdentity, olatuserGroup);
// open disclaimer
removeAsListenerAndDispose(disclaimerController);
disclaimerController = new DisclaimerController(ureq, getWindowControl());
listenTo(disclaimerController);
cmc = new CloseableModalController(getWindowControl(), translate("close"), disclaimerController.getInitialComponent(), true, translate("disclaimer.title"));
cmc.activate();
listenTo(cmc);
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class PLockTest method testSync.
@Test
public void testSync() {
log.info("testing enrollment");
// ------------------ now check with lock -------------------
// create a group
// create users
final List<Identity> identities = new ArrayList<Identity>();
for (int i = 0; i < MAX_COUNT + MAX_USERS_MORE; i++) {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("u-" + i + "-" + UUID.randomUUID().toString());
identities.add(id);
log.info("testSync: Identity=" + id.getName() + " created");
}
dbInstance.closeSession();
final SecurityGroup group2 = BaseSecurityManager.getInstance().createAndPersistSecurityGroup();
// make sure the lock has been written to the disk (tests for createOrFind see other methods)
dbInstance.closeSession();
// prepare threads
int numOfThreads = MAX_COUNT + MAX_USERS_MORE;
final CountDownLatch finishCount = new CountDownLatch(numOfThreads);
// try to enrol all in the same group
for (int i = 0; i < numOfThreads; i++) {
final int j = i;
new Thread(new Runnable() {
public void run() {
try {
log.info("testSync: thread started j=" + j);
Identity id = identities.get(j);
//
PLock p2 = pessimisticLockManager.findOrPersistPLock("befinsert");
assertNotNull(p2);
doNoLockingEnrol(id, group2);
dbInstance.commit();
dbInstance.closeSession();
} catch (Exception e) {
e.printStackTrace();
} finally {
finishCount.countDown();
}
}
}).start();
}
try {
finishCount.await(120, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.error("", e);
}
// now count
dbInstance.closeSession();
int cnt2 = BaseSecurityManager.getInstance().countIdentitiesOfSecurityGroup(group2);
assertTrue("cnt should be smaller or eq than allowed since synced with select for update. cnt:" + cnt2 + ", max " + MAX_COUNT, cnt2 <= MAX_COUNT);
assertTrue("cnt should be eq to allowed since synced with select for update. cnt:" + cnt2 + ", max " + MAX_COUNT, cnt2 == MAX_COUNT);
log.info("cnt lock " + cnt2);
}
use of org.olat.basesecurity.SecurityGroup in project OpenOLAT by OpenOLAT.
the class EPStructureManagerTest method testGetStructureElementsForUser.
@Test
public void testGetStructureElementsForUser() {
Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("EP-1-");
PortfolioStructure el = epFrontendManager.createAndPersistPortfolioDefaultMap(user, "users-test-map", "a-map-to-test-get-afterwards");
Assert.assertNotNull(el);
dbInstance.commitAndCloseSession();
List<SecurityGroup> secGroups = securityManager.getSecurityGroupsForIdentity(user);
Assert.assertNotNull(secGroups);
Assert.assertTrue(secGroups.size() >= 1);
List<PortfolioStructure> elRes = epStructureManager.getStructureElementsForUser(user, ElementType.DEFAULT_MAP);
Assert.assertNotNull(elRes);
Assert.assertEquals(1, elRes.size());
Assert.assertEquals("users-test-map", elRes.get(0).getTitle());
// get another map
PortfolioStructure el2 = epFrontendManager.createAndPersistPortfolioDefaultMap(user, "users-test-map-2", "2-a-map-to-test-get-afterwards");
Assert.assertNotNull(el2);
dbInstance.commitAndCloseSession();
List<PortfolioStructure> elRes2 = epStructureManager.getStructureElementsForUser(user);
Assert.assertNotNull(elRes2);
Assert.assertEquals(2, elRes2.size());
}
Aggregations