Search in sources :

Example 1 with UserImpl

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

the class BaseSecurityManager method createAndPersistIdentityAndUser.

/**
 * @param username the username
 * @param user the unpresisted User
 * @param authusername the username used as authentication credential
 *          (=username for provider "OLAT")
 * @param provider the provider of the authentication ("OLAT" or "AAI"). If null, no
 * authentication token is generated.
 * @param credential the credentials or null if not used
 * @return Identity
 */
@Override
public Identity createAndPersistIdentityAndUser(String username, String externalId, User user, String provider, String authusername, String credential) {
    IdentityImpl iimpl = new IdentityImpl();
    iimpl.setUser(user);
    iimpl.setName(username);
    iimpl.setLastLogin(new Date());
    iimpl.setExternalId(externalId);
    iimpl.setStatus(Identity.STATUS_ACTIV);
    ((UserImpl) user).setIdentity(iimpl);
    dbInstance.getCurrentEntityManager().persist(iimpl);
    if (provider != null) {
        createAndPersistAuthenticationIntern(iimpl, provider, authusername, credential, loginModule.getDefaultHashAlgorithm());
    }
    notifyNewIdentityCreated(iimpl);
    return iimpl;
}
Also used : UserImpl(org.olat.user.UserImpl) Date(java.util.Date)

Example 2 with UserImpl

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

the class UserNameReadOnlyPropertyHandler method getUserPropertyAsHTML.

@Override
public String getUserPropertyAsHTML(User user, Locale locale) {
    String val = getInternalValue(user);
    if (val != null) {
        Identity identity = ((UserImpl) user).getIdentity();
        ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(identity);
        String homepage = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
        return "<a href='" + homepage + "'>" + StringHelper.escapeHtml(val) + "</a>";
    }
    return "";
}
Also used : UserImpl(org.olat.user.UserImpl) Identity(org.olat.core.id.Identity) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 3 with UserImpl

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

the class BaseSecurityManager method createAndPersistIdentityAndUser.

/**
 * @param username the username
 * @param user the unpresisted User
 * @param authusername the username used as authentication credential
 *          (=username for provider "OLAT")
 * @param provider the provider of the authentication ("OLAT" or "AAI"). If null, no
 * authentication token is generated.
 * @param credential the credentials or null if not used
 * @return Identity
 */
@Override
public Identity createAndPersistIdentityAndUser(String username, String externalId, User user, String provider, String authusername, String credential) {
    IdentityImpl iimpl = new IdentityImpl();
    iimpl.setUser(user);
    iimpl.setName(username);
    iimpl.setLastLogin(new Date());
    iimpl.setExternalId(externalId);
    iimpl.setStatus(Identity.STATUS_ACTIV);
    ((UserImpl) user).setIdentity(iimpl);
    dbInstance.getCurrentEntityManager().persist(iimpl);
    if (provider != null) {
        createAndPersistAuthenticationIntern(iimpl, provider, authusername, credential, loginModule.getDefaultHashAlgorithm());
    }
    notifyNewIdentityCreated(iimpl);
    return iimpl;
}
Also used : UserImpl(org.olat.user.UserImpl) Date(java.util.Date)

Example 4 with UserImpl

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

the class UserNameReadOnlyPropertyHandler method getUserPropertyAsHTML.

@Override
public String getUserPropertyAsHTML(User user, Locale locale) {
    String val = getInternalValue(user);
    if (val != null) {
        Identity identity = ((UserImpl) user).getIdentity();
        ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(identity);
        String homepage = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
        return "<a href='" + homepage + "'>" + StringHelper.escapeHtml(val) + "</a>";
    }
    return "";
}
Also used : UserImpl(org.olat.user.UserImpl) Identity(org.olat.core.id.Identity) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 5 with UserImpl

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

the class SetupModule method createUser.

/**
 * Method to create a user with the given configuration
 *
 * @return Identity or null
 */
protected Identity createUser(DefaultUser user) {
    Identity identity;
    identity = securityManager.findIdentityByName(user.getUserName());
    if (identity == null) {
        // Create new user and subject
        UserImpl newUser = new UserImpl();
        newUser.setFirstName(user.getFirstName());
        newUser.setLastName(user.getLastName());
        newUser.setEmail(user.getEmail());
        newUser.getPreferences().setLanguage(user.getLanguage());
        newUser.getPreferences().setInformSessionTimeout(true);
        if (!StringUtils.hasText(authenticationProviderConstant)) {
            throw new OLATRuntimeException(this.getClass(), "Auth token not set! Please fix! " + authenticationProviderConstant, null);
        }
        // Now finally create that user thing on the database with all
        // credentials, person etc. in one transation context!
        identity = securityManager.createAndPersistIdentityAndUser(user.getUserName(), null, newUser, authenticationProviderConstant, user.getUserName(), user.getPassword());
        if (identity == null) {
            throw new OLATRuntimeException(this.getClass(), "Error, could not create  user and subject with name " + user.getUserName(), null);
        } else {
            if (user.isGuest()) {
                SecurityGroup anonymousGroup = securityManager.findSecurityGroupByName(Constants.GROUP_ANONYMOUS);
                securityManager.addIdentityToSecurityGroup(identity, anonymousGroup);
                log.info("Created anonymous user " + user.getUserName());
            } else {
                SecurityGroup olatuserGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
                if (user.isAdmin()) {
                    SecurityGroup adminGroup = securityManager.findSecurityGroupByName(Constants.GROUP_ADMIN);
                    securityManager.addIdentityToSecurityGroup(identity, adminGroup);
                    securityManager.addIdentityToSecurityGroup(identity, olatuserGroup);
                    log.info("Created admin user " + user.getUserName());
                } else if (user.isAuthor()) {
                    SecurityGroup authorGroup = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
                    securityManager.addIdentityToSecurityGroup(identity, authorGroup);
                    securityManager.addIdentityToSecurityGroup(identity, olatuserGroup);
                    log.info("Created author user " + user.getUserName());
                } else if (user.isUserManager()) {
                    SecurityGroup usermanagerGroup = securityManager.findSecurityGroupByName(Constants.GROUP_USERMANAGERS);
                    securityManager.addIdentityToSecurityGroup(identity, usermanagerGroup);
                    securityManager.addIdentityToSecurityGroup(identity, olatuserGroup);
                    log.info("Created userManager user " + user.getUserName());
                } else if (user.isGroupManager()) {
                    SecurityGroup groupmanagerGroup = securityManager.findSecurityGroupByName(Constants.GROUP_GROUPMANAGERS);
                    securityManager.addIdentityToSecurityGroup(identity, groupmanagerGroup);
                    securityManager.addIdentityToSecurityGroup(identity, olatuserGroup);
                    log.info("Created groupManager user " + user.getUserName());
                } else {
                    securityManager.addIdentityToSecurityGroup(identity, olatuserGroup);
                    log.info("Created user " + user.getUserName());
                }
            }
        }
    }
    return identity;
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) UserImpl(org.olat.user.UserImpl) Identity(org.olat.core.id.Identity) SecurityGroup(org.olat.basesecurity.SecurityGroup)

Aggregations

UserImpl (org.olat.user.UserImpl)6 Identity (org.olat.core.id.Identity)4 Date (java.util.Date)2 SecurityGroup (org.olat.basesecurity.SecurityGroup)2 ContextEntry (org.olat.core.id.context.ContextEntry)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2