use of org.olat.resource.accesscontrol.model.FreeAccessMethod in project OpenOLAT by OpenOLAT.
the class ACMethodManagerTest method testStandardMethods.
@Test
public void testStandardMethods() {
List<AccessMethod> methods = acMethodManager.getAvailableMethods();
assertNotNull(methods);
assertTrue(methods.size() >= 2);
Set<String> duplicateTypes = new HashSet<>();
boolean foundFree = false;
boolean foundToken = false;
for (AccessMethod method : methods) {
Assert.assertFalse(duplicateTypes.contains(method.getType()));
if (method instanceof FreeAccessMethod) {
foundFree = true;
} else if (method instanceof TokenAccessMethod) {
foundToken = true;
}
assertTrue(method.isEnabled());
assertTrue(method.isValid());
duplicateTypes.add(method.getType());
}
assertTrue(foundFree);
assertTrue(foundToken);
}
use of org.olat.resource.accesscontrol.model.FreeAccessMethod in project OpenOLAT by OpenOLAT.
the class ACFrontendManagerTest method testStandardMethods.
@Test
public void testStandardMethods() {
Identity ident = JunitTestHelper.createAndPersistIdentityAsRndUser("ac-method-mgr");
Roles roles = new Roles(false, false, false, true, false, false, false);
List<AccessMethod> methods = acService.getAvailableMethods(ident, roles);
assertNotNull(methods);
assertTrue(methods.size() >= 2);
Set<String> duplicateTypes = new HashSet<>();
boolean foundFree = false;
boolean foundToken = false;
for (AccessMethod method : methods) {
Assert.assertFalse(duplicateTypes.contains(method.getType()));
if (method instanceof FreeAccessMethod) {
foundFree = true;
} else if (method instanceof TokenAccessMethod) {
foundToken = true;
}
assertTrue(method.isEnabled());
assertTrue(method.isValid());
duplicateTypes.add(method.getType());
}
assertTrue(foundFree);
assertTrue(foundToken);
}
use of org.olat.resource.accesscontrol.model.FreeAccessMethod in project openolat by klemens.
the class ACFrontendManagerTest method testStandardMethods.
@Test
public void testStandardMethods() {
Identity ident = JunitTestHelper.createAndPersistIdentityAsRndUser("ac-method-mgr");
Roles roles = new Roles(false, false, false, true, false, false, false);
List<AccessMethod> methods = acService.getAvailableMethods(ident, roles);
assertNotNull(methods);
assertTrue(methods.size() >= 2);
Set<String> duplicateTypes = new HashSet<>();
boolean foundFree = false;
boolean foundToken = false;
for (AccessMethod method : methods) {
Assert.assertFalse(duplicateTypes.contains(method.getType()));
if (method instanceof FreeAccessMethod) {
foundFree = true;
} else if (method instanceof TokenAccessMethod) {
foundToken = true;
}
assertTrue(method.isEnabled());
assertTrue(method.isValid());
duplicateTypes.add(method.getType());
}
assertTrue(foundFree);
assertTrue(foundToken);
}
use of org.olat.resource.accesscontrol.model.FreeAccessMethod in project OpenOLAT by OpenOLAT.
the class ACMethodDAO method activateFreeMethod.
protected void activateFreeMethod(boolean enable) {
StringBuilder sb = new StringBuilder();
sb.append("select method from ").append(AbstractAccessMethod.class.getName()).append(" method where type(method) =").append(FreeAccessMethod.class.getName());
TypedQuery<AccessMethod> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), AccessMethod.class);
List<AccessMethod> methods = query.getResultList();
if (methods.isEmpty() && enable) {
FreeAccessMethod method = new FreeAccessMethod();
method.setCreationDate(new Date());
method.setLastModified(method.getCreationDate());
dbInstance.getCurrentEntityManager().persist(method);
} else {
for (AccessMethod method : methods) {
if (method.isEnabled() != enable) {
((AbstractAccessMethod) method).setEnabled(enable);
((AbstractAccessMethod) method).setLastModified(new Date());
dbInstance.getCurrentEntityManager().merge(method);
}
}
}
}
use of org.olat.resource.accesscontrol.model.FreeAccessMethod in project openolat by klemens.
the class ACMethodDAO method activateFreeMethod.
protected void activateFreeMethod(boolean enable) {
StringBuilder sb = new StringBuilder();
sb.append("select method from ").append(AbstractAccessMethod.class.getName()).append(" method where type(method) =").append(FreeAccessMethod.class.getName());
TypedQuery<AccessMethod> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), AccessMethod.class);
List<AccessMethod> methods = query.getResultList();
if (methods.isEmpty() && enable) {
FreeAccessMethod method = new FreeAccessMethod();
method.setCreationDate(new Date());
method.setLastModified(method.getCreationDate());
dbInstance.getCurrentEntityManager().persist(method);
} else {
for (AccessMethod method : methods) {
if (method.isEnabled() != enable) {
((AbstractAccessMethod) method).setEnabled(enable);
((AbstractAccessMethod) method).setLastModified(new Date());
dbInstance.getCurrentEntityManager().merge(method);
}
}
}
}
Aggregations