Search in sources :

Example 1 with UserPropertiesConfig

use of org.olat.user.UserPropertiesConfig in project OpenOLAT by OpenOLAT.

the class RegistrationController method createNewUserAfterRegistration.

/**
 * OO-92
 * this will finally create the user, set all it's userproperties
 *
 * @return User the newly created, persisted User Object
 */
private Identity createNewUserAfterRegistration() {
    // create user with mandatory fields from registration-form
    UserManager um = UserManager.getInstance();
    User volatileUser = um.createUser(registrationForm.getFirstName(), registrationForm.getLastName(), tempKey.getEmailAddress());
    // set user configured language
    Preferences preferences = volatileUser.getPreferences();
    preferences.setLanguage(registrationForm.getLangKey());
    volatileUser.setPreferences(preferences);
    // create an identity with the given username / pwd and the user object
    String login = registrationForm.getLogin();
    String pwd = registrationForm.getPassword();
    Identity persistedIdentity = registrationManager.createNewUserAndIdentityFromTemporaryKey(login, pwd, volatileUser, tempKey);
    if (persistedIdentity == null) {
        showError("user.notregistered");
        return null;
    } else {
        // update other user properties from form
        List<UserPropertyHandler> userPropertyHandlers = um.getUserPropertyHandlersFor(RegistrationForm2.USERPROPERTIES_FORM_IDENTIFIER, false);
        User persistedUser = persistedIdentity.getUser();
        // add eventually static value
        UserPropertiesConfig userPropertiesConfig = CoreSpringFactory.getImpl(UserPropertiesConfig.class);
        if (registrationModule.isStaticPropertyMappingEnabled()) {
            String propertyName = registrationModule.getStaticPropertyMappingName();
            String propertyValue = registrationModule.getStaticPropertyMappingValue();
            if (StringHelper.containsNonWhitespace(propertyName) && StringHelper.containsNonWhitespace(propertyValue) && userPropertiesConfig.getPropertyHandler(propertyName) != null) {
                try {
                    persistedUser.setProperty(propertyName, propertyValue);
                } catch (Exception e) {
                    logError("Cannot set the static property value", e);
                }
            }
        }
        for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
            FormItem fi = registrationForm.getPropFormItem(userPropertyHandler.getName());
            userPropertyHandler.updateUserFromFormItem(persistedUser, fi);
        }
        // persist changes in db
        um.updateUserFromIdentity(persistedIdentity);
        // send notification mail to sys admin
        String notiEmail = CoreSpringFactory.getImpl(RegistrationModule.class).getRegistrationNotificationEmail();
        if (notiEmail != null) {
            registrationManager.sendNewUserNotificationMessage(notiEmail, persistedIdentity);
        }
        // tell system that this user did accept the disclaimer
        registrationManager.setHasConfirmedDislaimer(persistedIdentity);
        return persistedIdentity;
    }
}
Also used : User(org.olat.core.id.User) UserManager(org.olat.user.UserManager) FormItem(org.olat.core.gui.components.form.flexible.FormItem) Preferences(org.olat.core.id.Preferences) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) UserPropertiesConfig(org.olat.user.UserPropertiesConfig)

Example 2 with UserPropertiesConfig

use of org.olat.user.UserPropertiesConfig in project openolat by klemens.

the class RegistrationController method createNewUserAfterRegistration.

/**
 * OO-92
 * this will finally create the user, set all it's userproperties
 *
 * @return User the newly created, persisted User Object
 */
private Identity createNewUserAfterRegistration() {
    // create user with mandatory fields from registration-form
    UserManager um = UserManager.getInstance();
    User volatileUser = um.createUser(registrationForm.getFirstName(), registrationForm.getLastName(), tempKey.getEmailAddress());
    // set user configured language
    Preferences preferences = volatileUser.getPreferences();
    preferences.setLanguage(registrationForm.getLangKey());
    volatileUser.setPreferences(preferences);
    // create an identity with the given username / pwd and the user object
    String login = registrationForm.getLogin();
    String pwd = registrationForm.getPassword();
    Identity persistedIdentity = registrationManager.createNewUserAndIdentityFromTemporaryKey(login, pwd, volatileUser, tempKey);
    if (persistedIdentity == null) {
        showError("user.notregistered");
        return null;
    } else {
        // update other user properties from form
        List<UserPropertyHandler> userPropertyHandlers = um.getUserPropertyHandlersFor(RegistrationForm2.USERPROPERTIES_FORM_IDENTIFIER, false);
        User persistedUser = persistedIdentity.getUser();
        // add eventually static value
        UserPropertiesConfig userPropertiesConfig = CoreSpringFactory.getImpl(UserPropertiesConfig.class);
        if (registrationModule.isStaticPropertyMappingEnabled()) {
            String propertyName = registrationModule.getStaticPropertyMappingName();
            String propertyValue = registrationModule.getStaticPropertyMappingValue();
            if (StringHelper.containsNonWhitespace(propertyName) && StringHelper.containsNonWhitespace(propertyValue) && userPropertiesConfig.getPropertyHandler(propertyName) != null) {
                try {
                    persistedUser.setProperty(propertyName, propertyValue);
                } catch (Exception e) {
                    logError("Cannot set the static property value", e);
                }
            }
        }
        for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
            FormItem fi = registrationForm.getPropFormItem(userPropertyHandler.getName());
            userPropertyHandler.updateUserFromFormItem(persistedUser, fi);
        }
        // persist changes in db
        um.updateUserFromIdentity(persistedIdentity);
        // send notification mail to sys admin
        String notiEmail = CoreSpringFactory.getImpl(RegistrationModule.class).getRegistrationNotificationEmail();
        if (notiEmail != null) {
            registrationManager.sendNewUserNotificationMessage(notiEmail, persistedIdentity);
        }
        // tell system that this user did accept the disclaimer
        registrationManager.setHasConfirmedDislaimer(persistedIdentity);
        return persistedIdentity;
    }
}
Also used : User(org.olat.core.id.User) UserManager(org.olat.user.UserManager) FormItem(org.olat.core.gui.components.form.flexible.FormItem) Preferences(org.olat.core.id.Preferences) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) UserPropertiesConfig(org.olat.user.UserPropertiesConfig)

Example 3 with UserPropertiesConfig

use of org.olat.user.UserPropertiesConfig in project OpenOLAT by OpenOLAT.

the class UsrPropCfgManager method loadModifiedUserPropertiesConfig.

/**
 * loads our persisted Config and manipulates the Config of the user-manager
 * (which comes from xml-config)
 */
private void loadModifiedUserPropertiesConfig(Properties props) {
    log.info("loading modified UserPropertiesConfig");
    UserPropertiesConfig usrMngConfig = userManager.getUserPropertiesConfig();
    cfgObject = new UsrPropCfgObject(allUserPropertyHandlersFromXML, usrMngConfig.getUserPropertyUsageContexts());
    // now manipulate this cfgObject according to our own config ( from the
    // persistedProperties)
    List<String> val_activeHandlers = Arrays.asList(props.getProperty(CONF_KEY_ACTUPROP, "").split(PROP_DELIMITER));
    List<String> val_dactiveHandlers = Arrays.asList(props.getProperty(CONF_KEY_DACTUPROP, "").split(PROP_DELIMITER));
    for (UserPropertyHandler handler : cfgObject.getPropertyHandlers()) {
        // modify the groupName of the handler
        String groupName = props.getProperty(handler.getName() + CONF_KEY_PROPGROUP, null);
        if (groupName != null) {
            handler.setGroup(groupName);
        }
        // either it is set as an active property, or the property can't be deactivated (email, firstname, lastname, etc.)
        if (val_activeHandlers.contains(handler.getName()) || !UsrPropCfgManager.canBeDeactivated(handler)) {
            cfgObject.setHandlerAsActive(handler, true);
        } else if (!val_dactiveHandlers.contains(handler.getName())) {
            // this is a new handler (not yet in our own config)
            // -->set it as active
            // (note: if you delete persistedProperties-conf-file, all handlers are
            // "new" and therefore should be active)
            log.info("UserPropertyHandler " + handler.getName() + " unknown in config, set Property as active.");
            cfgObject.setHandlerAsActive(handler, true);
        }
    }
    // handle contexts (these are the contexts from xml)
    for (Entry<String, UserPropertyUsageContext> ctxEntry : cfgObject.getUsageContexts().entrySet()) {
        UserPropertyUsageContext ctx = ctxEntry.getValue();
        String contextName = ctxEntry.getKey();
        List<UserPropertyHandler> ctx_allHandlers = new ArrayList<UserPropertyHandler>();
        Set<UserPropertyHandler> ctx_mandHandlers = new HashSet<UserPropertyHandler>();
        Set<UserPropertyHandler> ctx_adminonlyHandlers = new HashSet<UserPropertyHandler>();
        Set<UserPropertyHandler> ctx_usrreadonlyHandlers = new HashSet<UserPropertyHandler>();
        String handlerNameInConfig = props.getProperty(contextName, null);
        if (handlerNameInConfig == null) {
            // our config doesn't know this context,
            // leave it as is!
            log.info("UserPropertyUsageContext " + contextName + " unknown in config, leave Context untouched.");
            continue;
        }
        // this list from the persistedProperties has the correct order of handlers!
        List<String> val_handlers = Arrays.asList(props.getProperty(contextName + CONF_KEY_CONTPREFIX, "").split(PROP_DELIMITER));
        List<String> val_mandatoryHandlers = Arrays.asList(props.getProperty(contextName + CONF_KEY_CONTPREFIX + CONF_KEY_CONT_MANDATORY_PREFIX, "").split(PROP_DELIMITER));
        List<String> val_adminonlyHandlers = Arrays.asList(props.getProperty(contextName + CONF_KEY_CONTPREFIX + CONF_KEY_CONT_ADMINONLY_PREFIX, "").split(PROP_DELIMITER));
        List<String> val_userreadonlyHandlers = Arrays.asList(props.getProperty(contextName + CONF_KEY_CONTPREFIX + CONF_KEY_CONT_USERREADONLY_PREFIX, "").split(PROP_DELIMITER));
        for (UserPropertyHandler handler : cfgObject.getPropertyHandlers()) {
            String handlerName = handler.getName();
            if (val_handlers.contains(handlerName) && cfgObject.isActiveHandler(handler)) {
                ctx_allHandlers.add(handler);
                // either it is set as mandatory in config or it is one of the property where mandatory must be enforced :)
                if (val_mandatoryHandlers.contains(handlerName) || !UsrPropCfgManager.canBeOptionalInContext(handler, contextName)) {
                    ctx_mandHandlers.add(handler);
                }
                if (val_adminonlyHandlers.contains(handlerName)) {
                    ctx_adminonlyHandlers.add(handler);
                }
                if (val_userreadonlyHandlers.contains(handlerName)) {
                    ctx_usrreadonlyHandlers.add(handler);
                }
            }
        }
        ctx.setPropertyHandlers(restoreCorrectHandlerOrderWithinContext(ctx_allHandlers, val_handlers));
        ctx.setMandatoryProperties(ctx_mandHandlers);
        ctx.setAdminViewOnlyProperties(ctx_adminonlyHandlers);
        ctx.setUserViewReadOnlyProperties(ctx_usrreadonlyHandlers);
    }
    // create new modified userPropertiesConfig for UserManager
    setUserManagerProperties();
}
Also used : UserPropertyUsageContext(org.olat.user.propertyhandlers.UserPropertyUsageContext) ArrayList(java.util.ArrayList) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) UserPropertiesConfig(org.olat.user.UserPropertiesConfig) HashSet(java.util.HashSet)

Example 4 with UserPropertiesConfig

use of org.olat.user.UserPropertiesConfig in project openolat by klemens.

the class UsrPropCfgManager method loadModifiedUserPropertiesConfig.

/**
 * loads our persisted Config and manipulates the Config of the user-manager
 * (which comes from xml-config)
 */
private void loadModifiedUserPropertiesConfig(Properties props) {
    log.info("loading modified UserPropertiesConfig");
    UserPropertiesConfig usrMngConfig = userManager.getUserPropertiesConfig();
    cfgObject = new UsrPropCfgObject(allUserPropertyHandlersFromXML, usrMngConfig.getUserPropertyUsageContexts());
    // now manipulate this cfgObject according to our own config ( from the
    // persistedProperties)
    List<String> val_activeHandlers = Arrays.asList(props.getProperty(CONF_KEY_ACTUPROP, "").split(PROP_DELIMITER));
    List<String> val_dactiveHandlers = Arrays.asList(props.getProperty(CONF_KEY_DACTUPROP, "").split(PROP_DELIMITER));
    for (UserPropertyHandler handler : cfgObject.getPropertyHandlers()) {
        // modify the groupName of the handler
        String groupName = props.getProperty(handler.getName() + CONF_KEY_PROPGROUP, null);
        if (groupName != null) {
            handler.setGroup(groupName);
        }
        // either it is set as an active property, or the property can't be deactivated (email, firstname, lastname, etc.)
        if (val_activeHandlers.contains(handler.getName()) || !UsrPropCfgManager.canBeDeactivated(handler)) {
            cfgObject.setHandlerAsActive(handler, true);
        } else if (!val_dactiveHandlers.contains(handler.getName())) {
            // this is a new handler (not yet in our own config)
            // -->set it as active
            // (note: if you delete persistedProperties-conf-file, all handlers are
            // "new" and therefore should be active)
            log.info("UserPropertyHandler " + handler.getName() + " unknown in config, set Property as active.");
            cfgObject.setHandlerAsActive(handler, true);
        }
    }
    // handle contexts (these are the contexts from xml)
    for (Entry<String, UserPropertyUsageContext> ctxEntry : cfgObject.getUsageContexts().entrySet()) {
        UserPropertyUsageContext ctx = ctxEntry.getValue();
        String contextName = ctxEntry.getKey();
        List<UserPropertyHandler> ctx_allHandlers = new ArrayList<UserPropertyHandler>();
        Set<UserPropertyHandler> ctx_mandHandlers = new HashSet<UserPropertyHandler>();
        Set<UserPropertyHandler> ctx_adminonlyHandlers = new HashSet<UserPropertyHandler>();
        Set<UserPropertyHandler> ctx_usrreadonlyHandlers = new HashSet<UserPropertyHandler>();
        String handlerNameInConfig = props.getProperty(contextName, null);
        if (handlerNameInConfig == null) {
            // our config doesn't know this context,
            // leave it as is!
            log.info("UserPropertyUsageContext " + contextName + " unknown in config, leave Context untouched.");
            continue;
        }
        // this list from the persistedProperties has the correct order of handlers!
        List<String> val_handlers = Arrays.asList(props.getProperty(contextName + CONF_KEY_CONTPREFIX, "").split(PROP_DELIMITER));
        List<String> val_mandatoryHandlers = Arrays.asList(props.getProperty(contextName + CONF_KEY_CONTPREFIX + CONF_KEY_CONT_MANDATORY_PREFIX, "").split(PROP_DELIMITER));
        List<String> val_adminonlyHandlers = Arrays.asList(props.getProperty(contextName + CONF_KEY_CONTPREFIX + CONF_KEY_CONT_ADMINONLY_PREFIX, "").split(PROP_DELIMITER));
        List<String> val_userreadonlyHandlers = Arrays.asList(props.getProperty(contextName + CONF_KEY_CONTPREFIX + CONF_KEY_CONT_USERREADONLY_PREFIX, "").split(PROP_DELIMITER));
        for (UserPropertyHandler handler : cfgObject.getPropertyHandlers()) {
            String handlerName = handler.getName();
            if (val_handlers.contains(handlerName) && cfgObject.isActiveHandler(handler)) {
                ctx_allHandlers.add(handler);
                // either it is set as mandatory in config or it is one of the property where mandatory must be enforced :)
                if (val_mandatoryHandlers.contains(handlerName) || !UsrPropCfgManager.canBeOptionalInContext(handler, contextName)) {
                    ctx_mandHandlers.add(handler);
                }
                if (val_adminonlyHandlers.contains(handlerName)) {
                    ctx_adminonlyHandlers.add(handler);
                }
                if (val_userreadonlyHandlers.contains(handlerName)) {
                    ctx_usrreadonlyHandlers.add(handler);
                }
            }
        }
        ctx.setPropertyHandlers(restoreCorrectHandlerOrderWithinContext(ctx_allHandlers, val_handlers));
        ctx.setMandatoryProperties(ctx_mandHandlers);
        ctx.setAdminViewOnlyProperties(ctx_adminonlyHandlers);
        ctx.setUserViewReadOnlyProperties(ctx_usrreadonlyHandlers);
    }
    // create new modified userPropertiesConfig for UserManager
    setUserManagerProperties();
}
Also used : UserPropertyUsageContext(org.olat.user.propertyhandlers.UserPropertyUsageContext) ArrayList(java.util.ArrayList) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) UserPropertiesConfig(org.olat.user.UserPropertiesConfig) HashSet(java.util.HashSet)

Aggregations

UserPropertiesConfig (org.olat.user.UserPropertiesConfig)4 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 Identity (org.olat.core.id.Identity)2 Preferences (org.olat.core.id.Preferences)2 User (org.olat.core.id.User)2 UserManager (org.olat.user.UserManager)2 UserPropertyUsageContext (org.olat.user.propertyhandlers.UserPropertyUsageContext)2