Search in sources :

Example 16 with AccessMethod

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

the class ACFrontendManagerTest method testRepoWorkflow.

@Test
public void testRepoWorkflow() {
    // create a repository entry
    RepositoryEntry re = createRepositoryEntry();
    assertNotNull(re);
    // create and save an offer
    Offer offer = acService.createOffer(re.getOlatResource(), "TestRepoWorkflow");
    assertNotNull(offer);
    offer = acService.save(offer);
    dbInstance.commitAndCloseSession();
    // create a link offer to method
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(TokenAccessMethod.class);
    AccessMethod method = methods.get(0);
    OfferAccess access = acMethodManager.createOfferAccess(offer, method);
    acMethodManager.save(access);
    dbInstance.commitAndCloseSession();
    // retrieve the offer
    List<Offer> offers = acService.findOfferByResource(re.getOlatResource(), true, null);
    assertEquals(1, offers.size());
    Offer savedOffer = offers.get(0);
    assertNotNull(savedOffer);
    assertNotNull(savedOffer.getResource());
    assertTrue(re.getOlatResource().equalsByPersistableKey(savedOffer.getResource()));
}
Also used : 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) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Example 17 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod 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 18 with AccessMethod

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

the class ACFrontendManagerTest method testFreeAccesToBusinessGroup_full.

/**
 * Test free access to a group without waiting list and which is full
 */
@Test
public void testFreeAccesToBusinessGroup_full() {
    // create a group with a free offer, fill 2 places on 2
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "Free group", "But you must wait", new Integer(0), new Integer(2), false, false, null);
    businessGroupRelationDao.addRole(id1, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name());
    Offer offer = acService.createOffer(group.getResource(), "Free group (waiting)");
    offer = acService.save(offer);
    List<AccessMethod> freeMethods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
    OfferAccess offerAccess = acService.createOfferAccess(offer, freeMethods.get(0));
    Assert.assertNotNull(offerAccess);
    dbInstance.commitAndCloseSession();
    // access it
    AccessResult result = acService.accessResource(id3, offerAccess, null);
    Assert.assertNotNull(result);
    Assert.assertFalse(result.isAccessible());
    dbInstance.commitAndCloseSession();
    // is id a waiting?
    boolean participant = businessGroupRelationDao.hasRole(id3, group, GroupRoles.participant.name());
    Assert.assertFalse(participant);
    boolean waiting = businessGroupRelationDao.hasRole(id3, group, GroupRoles.waiting.name());
    Assert.assertFalse(waiting);
}
Also used : 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) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 19 with AccessMethod

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

the class ACFrontendManagerTest method testPaiedAccesToBusinessGroup_full.

@Test
public void testPaiedAccesToBusinessGroup_full() {
    // enable paypal
    boolean enabled = acModule.isPaypalEnabled();
    if (!enabled) {
        acModule.setPaypalEnabled(true);
    }
    // create a group with a free offer
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("pay-1-" + UUID.randomUUID().toString());
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
    Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("agp-" + UUID.randomUUID().toString());
    BusinessGroup group = businessGroupService.createBusinessGroup(null, "Free group", "But you must wait", new Integer(0), new Integer(2), false, false, null);
    Offer offer = acService.createOffer(group.getResource(), "Free group (waiting)");
    offer = acService.save(offer);
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(PaypalAccessMethod.class);
    Assert.assertFalse(methods.isEmpty());
    OfferAccess offerAccess = acService.createOfferAccess(offer, methods.get(0));
    Assert.assertNotNull(offerAccess);
    dbInstance.commitAndCloseSession();
    // admin fill the group
    businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id3, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // id1 try to reserve a place before the payment process
    boolean reserved = acService.reserveAccessToResource(id1, offerAccess);
    Assert.assertFalse(reserved);
    if (!enabled) {
        acModule.setPaypalEnabled(false);
    }
}
Also used : 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) BusinessGroup(org.olat.group.BusinessGroup) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 20 with AccessMethod

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

the class ACFrontendManagerTest method makeAccessible.

@Test
public void makeAccessible() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("acc-" + UUID.randomUUID());
    List<AccessMethod> methods = acMethodManager.getAvailableMethodsByType(FreeAccessMethod.class);
    AccessMethod method = methods.get(0);
    RepositoryEntry re = createRepositoryEntry();
    Assert.assertNotNull(re);
    // create an offer to buy
    OLATResource randomOres = re.getOlatResource();
    Offer offer = acService.createOffer(randomOres, "Test auto access");
    offer.setAutoBooking(true);
    OfferAccess link = acService.createOfferAccess(offer, method);
    offer = acService.save(offer);
    acService.saveOfferAccess(link);
    dbInstance.commit();
    long start = System.nanoTime();
    AccessResult acResult = acService.isAccessible(re, id, false, true);
    Assert.assertNotNull(acResult);
    Assert.assertTrue(acResult.isAccessible());
    dbInstance.commit();
    CodeHelper.printNanoTime(start, "One click");
}
Also used : 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) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)92 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)62 Test (org.junit.Test)56 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)54 OLATResource (org.olat.resource.OLATResource)40 Identity (org.olat.core.id.Identity)22 ShibbolethAutoAccessMethod (org.olat.shibboleth.manager.ShibbolethAutoAccessMethod)22 BusinessGroup (org.olat.group.BusinessGroup)18 PaypalAccessMethod (org.olat.resource.accesscontrol.provider.paypal.model.PaypalAccessMethod)18 ArrayList (java.util.ArrayList)16 Date (java.util.Date)12 Offer (org.olat.resource.accesscontrol.Offer)12 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)10 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)10 AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)10 AbstractAccessMethod (org.olat.resource.accesscontrol.model.AbstractAccessMethod)10 HashSet (java.util.HashSet)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 OLATResourceable (org.olat.core.id.OLATResourceable)6