Search in sources :

Example 6 with DisclaimerController

use of org.olat.registration.DisclaimerController in project OpenOLAT by OpenOLAT.

the class OLATAuthenticationController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == loginForm && event == Event.DONE_EVENT) {
        String login = loginForm.getLogin();
        String pass = loginForm.getPass();
        if (loginModule.isLoginBlocked(login)) {
            // do not proceed when blocked
            showError("login.blocked", loginModule.getAttackPreventionTimeoutMin().toString());
            getLogger().audit("Login attempt on already blocked login for " + login + ". IP::" + ureq.getHttpReq().getRemoteAddr(), null);
            return;
        }
        authenticatedIdentity = olatAuthenticationSpi.authenticate(null, login, pass);
        if (authenticatedIdentity == null) {
            if (loginModule.registerFailedLoginAttempt(login)) {
                getLogger().audit("Too many failed login attempts for " + login + ". Login blocked. IP::" + ureq.getHttpReq().getRemoteAddr(), null);
                showError("login.blocked", loginModule.getAttackPreventionTimeoutMin().toString());
                return;
            } else {
                showError("login.error", WebappHelper.getMailConfig("mailReplyTo"));
                return;
            }
        } else {
            try {
                String language = authenticatedIdentity.getUser().getPreferences().getLanguage();
                UserSession usess = ureq.getUserSession();
                if (StringHelper.containsNonWhitespace(language)) {
                    usess.setLocale(I18nManager.getInstance().getLocaleOrDefault(language));
                }
            } catch (Exception e) {
                logError("Cannot set the user language", e);
            }
        }
        loginModule.clearFailedLoginAttempts(login);
        // Check if disclaimer has been accepted
        if (registrationManager.needsToConfirmDisclaimer(authenticatedIdentity)) {
            // accept disclaimer first
            removeAsListenerAndDispose(disclaimerCtr);
            disclaimerCtr = new DisclaimerController(ureq, getWindowControl());
            listenTo(disclaimerCtr);
            removeAsListenerAndDispose(cmc);
            cmc = new CloseableModalController(getWindowControl(), translate("close"), disclaimerCtr.getInitialComponent());
            listenTo(cmc);
            cmc.activate();
        } else {
            // disclaimer acceptance not required
            authenticated(ureq, authenticatedIdentity);
        }
    } else if (source == disclaimerCtr) {
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            // disclaimer accepted
            registrationManager.setHasConfirmedDislaimer(authenticatedIdentity);
            authenticated(ureq, authenticatedIdentity);
        }
    } else if (cmc == source) {
        cleanUp();
    }
    if (source == subController) {
        if (event == Event.CANCELLED_EVENT) {
            cmc.deactivate();
            cleanUp();
        }
    }
}
Also used : DisclaimerController(org.olat.registration.DisclaimerController) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) UserSession(org.olat.core.util.UserSession) OLATSecurityException(org.olat.core.logging.OLATSecurityException)

Example 7 with DisclaimerController

use of org.olat.registration.DisclaimerController in project openolat by klemens.

the class LDAPAuthenticationController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    LDAPError ldapError = new LDAPError();
    if (source == loginForm && event == Event.DONE_EVENT) {
        String login = loginForm.getLogin();
        String pass = loginForm.getPass();
        if (loginModule.isLoginBlocked(login)) {
            // do not proceed when already blocked
            showError("login.blocked", loginModule.getAttackPreventionTimeoutMin().toString());
            getLogger().audit("Login attempt on already blocked login for " + login + ". IP::" + ureq.getHttpReq().getRemoteAddr(), null);
            return;
        }
        authenticatedIdentity = ldapLoginManager.authenticate(login, pass, ldapError);
        if (!ldapError.isEmpty()) {
            final String errStr = ldapError.get();
            if ("login.notauthenticated".equals(errStr)) {
                // user exists in LDAP, authentication was ok, but user
                // has not got the OLAT service or has not been created by now
                getWindowControl().setError(translate("login.notauthenticated"));
                return;
            } else {
                // tell about the error again
                ldapError.insert(errStr);
            }
        }
        if (authenticatedIdentity != null) {
            provider = LDAPAuthenticationController.PROVIDER_LDAP;
            try {
                // prevents database timeout
                dbInstance.commitAndCloseSession();
            } catch (Exception e) {
                log.error("", e);
            }
        } else {
            // try fallback to OLAT provider if configured
            if (ldapLoginModule.isCacheLDAPPwdAsOLATPwdOnLogin()) {
                authenticatedIdentity = olatAuthenticationSpi.authenticate(null, login, pass);
            }
            if (authenticatedIdentity != null) {
                provider = BaseSecurityModule.getDefaultAuthProviderIdentifier();
            }
        }
        // Still not found? register for hacking attempts
        if (authenticatedIdentity == null) {
            if (loginModule.registerFailedLoginAttempt(login)) {
                logAudit("Too many failed login attempts for " + login + ". Login blocked. IP::" + ureq.getHttpReq().getRemoteAddr(), null);
                showError("login.blocked", loginModule.getAttackPreventionTimeoutMin().toString());
            } else {
                showError("login.error", ldapError.get());
            }
            return;
        } else {
            try {
                String language = authenticatedIdentity.getUser().getPreferences().getLanguage();
                UserSession usess = ureq.getUserSession();
                if (StringHelper.containsNonWhitespace(language)) {
                    usess.setLocale(I18nManager.getInstance().getLocaleOrDefault(language));
                }
            } catch (Exception e) {
                logError("Cannot set the user language", e);
            }
        }
        loginModule.clearFailedLoginAttempts(login);
        // Check if disclaimer has been accepted
        if (registrationManager.needsToConfirmDisclaimer(authenticatedIdentity)) {
            // accept disclaimer first
            removeAsListenerAndDispose(disclaimerCtr);
            disclaimerCtr = new DisclaimerController(ureq, getWindowControl());
            listenTo(disclaimerCtr);
            removeAsListenerAndDispose(cmc);
            cmc = new CloseableModalController(getWindowControl(), translate("close"), disclaimerCtr.getInitialComponent());
            listenTo(cmc);
            cmc.activate();
        } else {
            // disclaimer acceptance not required
            doLoginAndRegister(authenticatedIdentity, ureq, provider);
        }
    }
    if (source == subController) {
        if (event == Event.CANCELLED_EVENT || event == Event.DONE_EVENT) {
            cmc.deactivate();
        }
    } else if (source == disclaimerCtr) {
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            // User accepted disclaimer, do login now
            registrationManager.setHasConfirmedDislaimer(authenticatedIdentity);
            doLoginAndRegister(authenticatedIdentity, ureq, provider);
        } else if (event == Event.CANCELLED_EVENT) {
            // User did not accept, workflow ends here
            showWarning("disclaimer.form.cancelled");
        }
    } else if (source == cmc) {
        // User did close disclaimer window, workflow ends here
        showWarning("disclaimer.form.cancelled");
    }
}
Also used : DisclaimerController(org.olat.registration.DisclaimerController) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) UserSession(org.olat.core.util.UserSession) LDAPError(org.olat.ldap.LDAPError) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 8 with DisclaimerController

use of org.olat.registration.DisclaimerController in project openolat by klemens.

the class OLATAuthenticationController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == loginForm && event == Event.DONE_EVENT) {
        String login = loginForm.getLogin();
        String pass = loginForm.getPass();
        if (loginModule.isLoginBlocked(login)) {
            // do not proceed when blocked
            showError("login.blocked", loginModule.getAttackPreventionTimeoutMin().toString());
            getLogger().audit("Login attempt on already blocked login for " + login + ". IP::" + ureq.getHttpReq().getRemoteAddr(), null);
            return;
        }
        authenticatedIdentity = olatAuthenticationSpi.authenticate(null, login, pass);
        if (authenticatedIdentity == null) {
            if (loginModule.registerFailedLoginAttempt(login)) {
                getLogger().audit("Too many failed login attempts for " + login + ". Login blocked. IP::" + ureq.getHttpReq().getRemoteAddr(), null);
                showError("login.blocked", loginModule.getAttackPreventionTimeoutMin().toString());
                return;
            } else {
                showError("login.error", WebappHelper.getMailConfig("mailReplyTo"));
                return;
            }
        } else {
            try {
                String language = authenticatedIdentity.getUser().getPreferences().getLanguage();
                UserSession usess = ureq.getUserSession();
                if (StringHelper.containsNonWhitespace(language)) {
                    usess.setLocale(I18nManager.getInstance().getLocaleOrDefault(language));
                }
            } catch (Exception e) {
                logError("Cannot set the user language", e);
            }
        }
        loginModule.clearFailedLoginAttempts(login);
        // Check if disclaimer has been accepted
        if (registrationManager.needsToConfirmDisclaimer(authenticatedIdentity)) {
            // accept disclaimer first
            removeAsListenerAndDispose(disclaimerCtr);
            disclaimerCtr = new DisclaimerController(ureq, getWindowControl());
            listenTo(disclaimerCtr);
            removeAsListenerAndDispose(cmc);
            cmc = new CloseableModalController(getWindowControl(), translate("close"), disclaimerCtr.getInitialComponent());
            listenTo(cmc);
            cmc.activate();
        } else {
            // disclaimer acceptance not required
            authenticated(ureq, authenticatedIdentity);
        }
    } else if (source == disclaimerCtr) {
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            // disclaimer accepted
            registrationManager.setHasConfirmedDislaimer(authenticatedIdentity);
            authenticated(ureq, authenticatedIdentity);
        }
    } else if (cmc == source) {
        cleanUp();
    }
    if (source == subController) {
        if (event == Event.CANCELLED_EVENT) {
            cmc.deactivate();
            cleanUp();
        }
    }
}
Also used : DisclaimerController(org.olat.registration.DisclaimerController) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) UserSession(org.olat.core.util.UserSession) OLATSecurityException(org.olat.core.logging.OLATSecurityException)

Aggregations

DisclaimerController (org.olat.registration.DisclaimerController)8 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)6 UserSession (org.olat.core.util.UserSession)4 SecurityGroup (org.olat.basesecurity.SecurityGroup)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 User (org.olat.core.id.User)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 OLATSecurityException (org.olat.core.logging.OLATSecurityException)2 LDAPError (org.olat.ldap.LDAPError)2 OAuthUser (org.olat.login.oauth.model.OAuthUser)2 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)2