Search in sources :

Example 1 with TokenAccessMethod

use of org.olat.resource.accesscontrol.model.TokenAccessMethod 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);
}
Also used : TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) ShibbolethAutoAccessMethod(org.olat.shibboleth.manager.ShibbolethAutoAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with TokenAccessMethod

use of org.olat.resource.accesscontrol.model.TokenAccessMethod in project OpenOLAT by OpenOLAT.

the class ACMethodDAO method activateTokenMethod.

/**
 * Activate the token method if not already configured.
 */
protected void activateTokenMethod(boolean enable) {
    StringBuilder sb = new StringBuilder();
    sb.append("select method from actokenmethod method");
    List<AccessMethod> methods = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), AccessMethod.class).getResultList();
    if (methods.isEmpty() && enable) {
        TokenAccessMethod method = new TokenAccessMethod();
        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);
            }
        }
    }
}
Also used : TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) ShibbolethAutoAccessMethod(org.olat.shibboleth.manager.ShibbolethAutoAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) AbstractAccessMethod(org.olat.resource.accesscontrol.model.AbstractAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) AbstractAccessMethod(org.olat.resource.accesscontrol.model.AbstractAccessMethod) Date(java.util.Date)

Example 3 with TokenAccessMethod

use of org.olat.resource.accesscontrol.model.TokenAccessMethod 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);
}
Also used : TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) PaypalAccessMethod(org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with TokenAccessMethod

use of org.olat.resource.accesscontrol.model.TokenAccessMethod 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);
}
Also used : TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) PaypalAccessMethod(org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) GroupRoles(org.olat.basesecurity.GroupRoles) Roles(org.olat.core.id.Roles) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with TokenAccessMethod

use of org.olat.resource.accesscontrol.model.TokenAccessMethod in project openolat by klemens.

the class ACMethodDAO method activateTokenMethod.

/**
 * Activate the token method if not already configured.
 */
protected void activateTokenMethod(boolean enable) {
    StringBuilder sb = new StringBuilder();
    sb.append("select method from actokenmethod method");
    List<AccessMethod> methods = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), AccessMethod.class).getResultList();
    if (methods.isEmpty() && enable) {
        TokenAccessMethod method = new TokenAccessMethod();
        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);
            }
        }
    }
}
Also used : TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) ShibbolethAutoAccessMethod(org.olat.shibboleth.manager.ShibbolethAutoAccessMethod) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) AbstractAccessMethod(org.olat.resource.accesscontrol.model.AbstractAccessMethod) TokenAccessMethod(org.olat.resource.accesscontrol.model.TokenAccessMethod) AbstractAccessMethod(org.olat.resource.accesscontrol.model.AbstractAccessMethod) Date(java.util.Date)

Aggregations

AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)6 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)6 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)6 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 ShibbolethAutoAccessMethod (org.olat.shibboleth.manager.ShibbolethAutoAccessMethod)4 Date (java.util.Date)2 GroupRoles (org.olat.basesecurity.GroupRoles)2 Identity (org.olat.core.id.Identity)2 Roles (org.olat.core.id.Roles)2 AbstractAccessMethod (org.olat.resource.accesscontrol.model.AbstractAccessMethod)2 PaypalAccessMethod (org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod)2