Search in sources :

Example 1 with AbstractAccessMethod

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

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

the class ACMethodDAO method enableMethod.

public void enableMethod(Class<? extends AccessMethod> type, boolean enable) {
    StringBuilder sb = new StringBuilder();
    sb.append("select method from ").append(type.getName()).append(" method");
    List<AccessMethod> methods = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), AccessMethod.class).getResultList();
    if (methods.isEmpty() && enable) {
        try {
            AccessMethod method = type.newInstance();
            Date now = new Date();
            ((AbstractAccessMethod) method).setCreationDate(now);
            ((AbstractAccessMethod) method).setLastModified(now);
            dbInstance.getCurrentEntityManager().persist(method);
        } catch (InstantiationException e) {
            log.error("Failed to instantiate an access method", e);
        } catch (IllegalAccessException e) {
            log.error("Failed to instantiate an access method", e);
        }
    } 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) Date(java.util.Date)

Example 3 with AbstractAccessMethod

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

the class ACMethodDAO method enableMethod.

public void enableMethod(Class<? extends AccessMethod> type, boolean enable) {
    StringBuilder sb = new StringBuilder();
    sb.append("select method from ").append(type.getName()).append(" method");
    List<AccessMethod> methods = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), AccessMethod.class).getResultList();
    if (methods.isEmpty() && enable) {
        try {
            AccessMethod method = type.newInstance();
            Date now = new Date();
            ((AbstractAccessMethod) method).setCreationDate(now);
            ((AbstractAccessMethod) method).setLastModified(now);
            dbInstance.getCurrentEntityManager().persist(method);
        } catch (InstantiationException e) {
            log.error("Failed to instantiate an access method", e);
        } catch (IllegalAccessException e) {
            log.error("Failed to instantiate an access method", e);
        }
    } 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) Date(java.util.Date)

Example 4 with AbstractAccessMethod

use of org.olat.resource.accesscontrol.model.AbstractAccessMethod 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);
            }
        }
    }
}
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 5 with AbstractAccessMethod

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

Aggregations

Date (java.util.Date)6 AbstractAccessMethod (org.olat.resource.accesscontrol.model.AbstractAccessMethod)6 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)6 FreeAccessMethod (org.olat.resource.accesscontrol.model.FreeAccessMethod)6 TokenAccessMethod (org.olat.resource.accesscontrol.model.TokenAccessMethod)6 ShibbolethAutoAccessMethod (org.olat.shibboleth.manager.ShibbolethAutoAccessMethod)6