Search in sources :

Example 1 with DisclaimerController

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

the class OAuthRegistrationController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    String lang = langEl.getSelectedKey();
    String username = usernameEl.getValue();
    OAuthUser oauthUser = registration.getOauthUser();
    User newUser = userManager.createUser(null, null, null);
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        FormItem propertyItem = this.flc.getFormComponent(userPropertyHandler.getName());
        userPropertyHandler.updateUserFromFormItem(newUser, propertyItem);
    }
    // Init preferences
    newUser.getPreferences().setLanguage(lang);
    newUser.getPreferences().setInformSessionTimeout(true);
    String id;
    if (StringHelper.containsNonWhitespace(oauthUser.getId())) {
        id = oauthUser.getId();
    } else if (StringHelper.containsNonWhitespace(oauthUser.getEmail())) {
        id = oauthUser.getEmail();
    } else {
        id = username;
    }
    authenticatedIdentity = securityManager.createAndPersistIdentityAndUser(username, null, newUser, registration.getAuthProvider(), id, null);
    // Add user to system users group
    SecurityGroup olatuserGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
    securityManager.addIdentityToSecurityGroup(authenticatedIdentity, olatuserGroup);
    // open disclaimer
    removeAsListenerAndDispose(disclaimerController);
    disclaimerController = new DisclaimerController(ureq, getWindowControl());
    listenTo(disclaimerController);
    cmc = new CloseableModalController(getWindowControl(), translate("close"), disclaimerController.getInitialComponent(), true, translate("disclaimer.title"));
    cmc.activate();
    listenTo(cmc);
}
Also used : OAuthUser(org.olat.login.oauth.model.OAuthUser) User(org.olat.core.id.User) DisclaimerController(org.olat.registration.DisclaimerController) OAuthUser(org.olat.login.oauth.model.OAuthUser) FormItem(org.olat.core.gui.components.form.flexible.FormItem) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) SecurityGroup(org.olat.basesecurity.SecurityGroup) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 2 with DisclaimerController

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

the class UserSettingsController method doOpenDisclaimer.

private void doOpenDisclaimer(UserRequest ureq) {
    if (disclaimerCtrl == null) {
        disclaimerCtrl = new DisclaimerController(ureq, getWindowControl(), true);
        listenTo(disclaimerCtrl);
    }
    mainVC.put("segmentCmp", disclaimerCtrl.getInitialComponent());
}
Also used : DisclaimerController(org.olat.registration.DisclaimerController)

Example 3 with DisclaimerController

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

the class OAuthRegistrationController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    String lang = langEl.getSelectedKey();
    String username = usernameEl.getValue();
    OAuthUser oauthUser = registration.getOauthUser();
    User newUser = userManager.createUser(null, null, null);
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        FormItem propertyItem = this.flc.getFormComponent(userPropertyHandler.getName());
        userPropertyHandler.updateUserFromFormItem(newUser, propertyItem);
    }
    // Init preferences
    newUser.getPreferences().setLanguage(lang);
    newUser.getPreferences().setInformSessionTimeout(true);
    String id;
    if (StringHelper.containsNonWhitespace(oauthUser.getId())) {
        id = oauthUser.getId();
    } else if (StringHelper.containsNonWhitespace(oauthUser.getEmail())) {
        id = oauthUser.getEmail();
    } else {
        id = username;
    }
    authenticatedIdentity = securityManager.createAndPersistIdentityAndUser(username, null, newUser, registration.getAuthProvider(), id, null);
    // Add user to system users group
    SecurityGroup olatuserGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
    securityManager.addIdentityToSecurityGroup(authenticatedIdentity, olatuserGroup);
    // open disclaimer
    removeAsListenerAndDispose(disclaimerController);
    disclaimerController = new DisclaimerController(ureq, getWindowControl());
    listenTo(disclaimerController);
    cmc = new CloseableModalController(getWindowControl(), translate("close"), disclaimerController.getInitialComponent(), true, translate("disclaimer.title"));
    cmc.activate();
    listenTo(cmc);
}
Also used : OAuthUser(org.olat.login.oauth.model.OAuthUser) User(org.olat.core.id.User) DisclaimerController(org.olat.registration.DisclaimerController) OAuthUser(org.olat.login.oauth.model.OAuthUser) FormItem(org.olat.core.gui.components.form.flexible.FormItem) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) SecurityGroup(org.olat.basesecurity.SecurityGroup) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 4 with DisclaimerController

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

the class UserSettingsController method doOpenDisclaimer.

private void doOpenDisclaimer(UserRequest ureq) {
    if (disclaimerCtrl == null) {
        disclaimerCtrl = new DisclaimerController(ureq, getWindowControl(), true);
        listenTo(disclaimerCtrl);
    }
    mainVC.put("segmentCmp", disclaimerCtrl.getInitialComponent());
}
Also used : DisclaimerController(org.olat.registration.DisclaimerController)

Example 5 with DisclaimerController

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

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)

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