Search in sources :

Example 1 with Authority

use of com.dubion.domain.Authority in project dubion by valsamiq.

the class UserService method registerUser.

public User registerUser(ManagedUserVM userDTO) {
    User newUser = new User();
    Authority authority = authorityRepository.findOne(AuthoritiesConstants.USER);
    Set<Authority> authorities = new HashSet<>();
    String encryptedPassword = passwordEncoder.encode(userDTO.getPassword());
    newUser.setLogin(userDTO.getLogin());
    // new user gets initially a generated password
    newUser.setPassword(encryptedPassword);
    newUser.setFirstName(userDTO.getFirstName());
    newUser.setLastName(userDTO.getLastName());
    newUser.setEmail(userDTO.getEmail());
    newUser.setImageUrl(userDTO.getImageUrl());
    newUser.setLangKey(userDTO.getLangKey());
    // new user is not active
    newUser.setActivated(false);
    // new user gets registration key
    newUser.setActivationKey(RandomUtil.generateActivationKey());
    authorities.add(authority);
    newUser.setAuthorities(authorities);
    userRepository.save(newUser);
    log.debug("Created Information for User: {}", newUser);
    return newUser;
}
Also used : User(com.dubion.domain.User) Authority(com.dubion.domain.Authority)

Example 2 with Authority

use of com.dubion.domain.Authority in project dubion by valsamiq.

the class UserMapper method userDTOToUser.

public User userDTOToUser(UserDTO userDTO) {
    if (userDTO == null) {
        return null;
    } else {
        User user = new User();
        user.setId(userDTO.getId());
        user.setLogin(userDTO.getLogin());
        user.setFirstName(userDTO.getFirstName());
        user.setLastName(userDTO.getLastName());
        user.setEmail(userDTO.getEmail());
        user.setImageUrl(userDTO.getImageUrl());
        user.setActivated(userDTO.isActivated());
        user.setLangKey(userDTO.getLangKey());
        Set<Authority> authorities = this.authoritiesFromStrings(userDTO.getAuthorities());
        if (authorities != null) {
            user.setAuthorities(authorities);
        }
        return user;
    }
}
Also used : User(com.dubion.domain.User) Authority(com.dubion.domain.Authority)

Example 3 with Authority

use of com.dubion.domain.Authority in project dubion by valsamiq.

the class SocialService method createUserIfNotExist.

private User createUserIfNotExist(UserProfile userProfile, String langKey, String providerId, String imageUrl) {
    String email = userProfile.getEmail();
    String userName = userProfile.getUsername();
    if (!StringUtils.isBlank(userName)) {
        userName = userName.toLowerCase(Locale.ENGLISH);
    }
    if (StringUtils.isBlank(email) && StringUtils.isBlank(userName)) {
        log.error("Cannot create social user because email and login are null");
        throw new IllegalArgumentException("Email and login cannot be null");
    }
    if (StringUtils.isBlank(email) && userRepository.findOneByLogin(userName).isPresent()) {
        log.error("Cannot create social user because email is null and login already exist, login -> {}", userName);
        throw new IllegalArgumentException("Email cannot be null with an existing login");
    }
    if (!StringUtils.isBlank(email)) {
        Optional<User> user = userRepository.findOneByEmailIgnoreCase(email);
        if (user.isPresent()) {
            log.info("User already exist associate the connection to this account");
            return user.get();
        }
    }
    String login = getLoginDependingOnProviderId(userProfile, providerId);
    String encryptedPassword = passwordEncoder.encode(RandomStringUtils.random(10));
    Set<Authority> authorities = new HashSet<>(1);
    authorities.add(authorityRepository.findOne(AuthoritiesConstants.USER));
    User newUser = new User();
    newUser.setLogin(login);
    newUser.setPassword(encryptedPassword);
    newUser.setFirstName(userProfile.getFirstName());
    newUser.setLastName(userProfile.getLastName());
    newUser.setEmail(email);
    newUser.setActivated(true);
    newUser.setAuthorities(authorities);
    newUser.setLangKey(langKey);
    newUser.setImageUrl(imageUrl);
    return userRepository.save(newUser);
}
Also used : User(com.dubion.domain.User) Authority(com.dubion.domain.Authority)

Example 4 with Authority

use of com.dubion.domain.Authority in project dubion by valsamiq.

the class UserService method createUser.

public User createUser(UserDTO userDTO) {
    User user = new User();
    user.setLogin(userDTO.getLogin());
    user.setFirstName(userDTO.getFirstName());
    user.setLastName(userDTO.getLastName());
    user.setEmail(userDTO.getEmail());
    user.setImageUrl(userDTO.getImageUrl());
    if (userDTO.getLangKey() == null) {
        // default language
        user.setLangKey(Constants.DEFAULT_LANGUAGE);
    } else {
        user.setLangKey(userDTO.getLangKey());
    }
    if (userDTO.getAuthorities() != null) {
        Set<Authority> authorities = userDTO.getAuthorities().stream().map(authorityRepository::findOne).collect(Collectors.toSet());
        user.setAuthorities(authorities);
    }
    String encryptedPassword = passwordEncoder.encode(RandomUtil.generatePassword());
    user.setPassword(encryptedPassword);
    user.setResetKey(RandomUtil.generateResetKey());
    user.setResetDate(Instant.now());
    user.setActivated(true);
    userRepository.save(user);
    log.debug("Created Information for User: {}", user);
    return user;
}
Also used : User(com.dubion.domain.User) Authority(com.dubion.domain.Authority)

Aggregations

Authority (com.dubion.domain.Authority)4 User (com.dubion.domain.User)4