Search in sources :

Example 1 with UserExistsException

use of gemma.gsec.authentication.UserExistsException in project Gemma by PavlidisLab.

the class UserManagerImpl method createUser.

@Override
@Secured({ "IS_AUTHENTICATED_ANONYMOUSLY", "RUN_AS_ADMIN" })
@Transactional
public void createUser(UserDetails user) {
    /*
         * UserDetails is not an entity, so this method is not directly managed by the Audit or ACL advice. However, it
         * runs in a transaction and calls two service methods which are intercepted. This means it is intercepted
         * before the transaction is flushed.
         */
    this.validateUserName(user.getUsername());
    User u = ubic.gemma.model.common.auditAndSecurity.User.Factory.newInstance();
    u.setUserName(user.getUsername());
    u.setPassword(user.getPassword());
    u.setEnabled(user.isEnabled());
    if (user instanceof UserDetailsImpl) {
        u.setSignupToken(((UserDetailsImpl) user).getSignupToken());
        u.setSignupTokenDatestamp(((UserDetailsImpl) user).getSignupTokenDatestamp());
    }
    if (user instanceof UserDetailsImpl) {
        u.setEmail(((UserDetailsImpl) user).getEmail());
    }
    try {
        u = userService.create(u);
    } catch (UserExistsException e) {
        throw new RuntimeException(e);
    }
    // Add the user to the default user group.
    UserGroup g = this.loadGroup(AuthorityConstants.USER_GROUP_NAME);
    userService.addUserToGroup(g, u);
/*
         * We don't log the user in automatically, because we require that new users click a confirmation link in an
         * email.
         */
}
Also used : UserDetailsImpl(gemma.gsec.authentication.UserDetailsImpl) UserExistsException(gemma.gsec.authentication.UserExistsException) User(gemma.gsec.model.User) UserGroup(gemma.gsec.model.UserGroup) Secured(org.springframework.security.access.annotation.Secured) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserDetailsImpl (gemma.gsec.authentication.UserDetailsImpl)1 UserExistsException (gemma.gsec.authentication.UserExistsException)1 User (gemma.gsec.model.User)1 UserGroup (gemma.gsec.model.UserGroup)1 Secured (org.springframework.security.access.annotation.Secured)1 Transactional (org.springframework.transaction.annotation.Transactional)1