Search in sources :

Example 71 with AccessMethod

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

the class ACFrontendManager method getAvailableMethods.

@Override
public List<AccessMethod> getAvailableMethods(Identity identity, Roles roles) {
    List<AccessMethod> methods = methodManager.getAvailableMethods();
    List<AccessMethod> allowedMethods = new ArrayList<>();
    for (AccessMethod method : methods) {
        AccessMethodHandler handler = accessModule.getAccessMethodHandler(method.getType());
        AccessMethodSecurityCallback secCallback = handler.getSecurityCallback(identity, roles);
        if (secCallback.canUse()) {
            allowedMethods.add(method);
        }
    }
    return methods;
}
Also used : AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) AccessMethodSecurityCallback(org.olat.resource.accesscontrol.model.AccessMethodSecurityCallback) ArrayList(java.util.ArrayList) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Example 72 with AccessMethod

use of org.olat.resource.accesscontrol.model.AccessMethod 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);
            }
        }
    }
}
Also used : 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) FreeAccessMethod(org.olat.resource.accesscontrol.model.FreeAccessMethod) Date(java.util.Date)

Example 73 with AccessMethod

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

Example 74 with AccessMethod

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

the class ACMethodDAO method isValidMethodAvailable.

public boolean isValidMethodAvailable(OLATResource resource, Date atDate) {
    StringBuilder sb = new StringBuilder();
    sb.append("select access.method from acofferaccess access ").append(" inner join access.offer offer").append(" inner join offer.resource oResource").append(" where access.valid=true").append(" and offer.valid=true").append(" and oResource.key=:resourceKey");
    if (atDate != null) {
        sb.append(" and (offer.validFrom is null or offer.validFrom<=:atDate)").append(" and (offer.validTo is null or offer.validTo>=:atDate)");
    }
    TypedQuery<AccessMethod> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), AccessMethod.class);
    query.setParameter("resourceKey", resource.getKey());
    if (atDate != null) {
        query.setParameter("atDate", atDate, TemporalType.TIMESTAMP);
    }
    List<AccessMethod> methods = query.getResultList();
    List<AccessMethod> guiMethods = new ArrayList<>();
    for (AccessMethod method : methods) {
        if (method.isVisibleInGui()) {
            guiMethods.add(method);
        }
    }
    return !guiMethods.isEmpty();
}
Also used : 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) ArrayList(java.util.ArrayList)

Example 75 with AccessMethod

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

the class ACFrontendManagerTest method testPaiedAccesToBusinessGroupWithWaitingList_enoughPlaceButAdmin.

/**
 * Test paypal scenario where a user begin the process to pay an access
 * to a group while an administrator is filling the group,
 */
@Test
public void testPaiedAccesToBusinessGroupWithWaitingList_enoughPlaceButAdmin() {
    // 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), true, 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();
    // id1 start payment process
    boolean reserved = acService.reserveAccessToResource(id1, offerAccess);
    Assert.assertTrue(reserved);
    dbInstance.commitAndCloseSession();
    // admin fill the group
    businessGroupRelationDao.addRole(id2, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(id3, group, GroupRoles.participant.name());
    dbInstance.commitAndCloseSession();
    // id1 finish the process
    AccessResult result = acService.accessResource(id1, offerAccess, null);
    Assert.assertNotNull(result);
    Assert.assertTrue(result.isAccessible());
    dbInstance.commitAndCloseSession();
    // is id a waiting?
    boolean participant = businessGroupRelationDao.hasRole(id1, group, GroupRoles.participant.name());
    Assert.assertTrue(participant);
    boolean waiting = businessGroupRelationDao.hasRole(id1, group, GroupRoles.waiting.name());
    Assert.assertFalse(waiting);
    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)

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