Search in sources :

Example 31 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-oauth2 by jhipster.

the class UserResourceIntTest method testUserEquals.

@Test
@Transactional
public void testUserEquals() throws Exception {
    TestUtil.equalsVerifier(User.class);
    User user1 = new User();
    user1.setId("id1");
    User user2 = new User();
    user2.setId(user1.getId());
    assertThat(user1).isEqualTo(user2);
    user2.setId("id2");
    assertThat(user1).isNotEqualTo(user2);
    user1.setId(null);
    assertThat(user1).isNotEqualTo(user2);
}
Also used : User(io.github.jhipster.sample.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-websocket by jhipster.

the class UserService method removeNotActivatedUsers.

/**
 * Not activated users should be automatically deleted after 3 days.
 * <p>
 * This is scheduled to get fired everyday, at 01:00 (am).
 */
@Scheduled(cron = "0 0 1 * * ?")
public void removeNotActivatedUsers() {
    List<User> users = userRepository.findAllByActivatedIsFalseAndCreatedDateBefore(Instant.now().minus(3, ChronoUnit.DAYS));
    for (User user : users) {
        log.debug("Deleting not activated user {}", user.getLogin());
        userRepository.delete(user);
        this.clearUserCaches(user);
    }
}
Also used : User(io.github.jhipster.sample.domain.User) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 33 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-websocket by jhipster.

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::findById).filter(Optional::isPresent).map(Optional::get).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);
    this.clearUserCaches(user);
    log.debug("Created Information for User: {}", user);
    return user;
}
Also used : User(io.github.jhipster.sample.domain.User) Authority(io.github.jhipster.sample.domain.Authority)

Example 34 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-websocket by jhipster.

the class UserService method removeOldPersistentTokens.

/**
 * Persistent Token are used for providing automatic authentication, they should be automatically deleted after
 * 30 days.
 * <p>
 * This is scheduled to get fired everyday, at midnight.
 */
@Scheduled(cron = "0 0 0 * * ?")
public void removeOldPersistentTokens() {
    LocalDate now = LocalDate.now();
    persistentTokenRepository.findByTokenDateBefore(now.minusMonths(1)).forEach(token -> {
        log.debug("Deleting token {}", token.getSeries());
        User user = token.getUser();
        user.getPersistentTokens().remove(token);
        persistentTokenRepository.delete(token);
    });
}
Also used : User(io.github.jhipster.sample.domain.User) LocalDate(java.time.LocalDate) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 35 with User

use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-websocket by jhipster.

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(io.github.jhipster.sample.domain.User) Authority(io.github.jhipster.sample.domain.Authority)

Aggregations

User (io.github.jhipster.sample.domain.User)329 Test (org.junit.Test)251 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)251 Transactional (org.springframework.transaction.annotation.Transactional)150 WithMockUser (org.springframework.security.test.context.support.WithMockUser)138 ManagedUserVM (io.github.jhipster.sample.web.rest.vm.ManagedUserVM)90 AbstractCassandraTest (io.github.jhipster.sample.AbstractCassandraTest)38 UserDTO (io.github.jhipster.sample.service.dto.UserDTO)32 Authority (io.github.jhipster.sample.domain.Authority)24 PasswordChangeDTO (io.github.jhipster.sample.service.dto.PasswordChangeDTO)24 MimeMessage (javax.mail.internet.MimeMessage)24 Instant (java.time.Instant)21 Before (org.junit.Before)13 Timed (com.codahale.metrics.annotation.Timed)12 KeyAndPasswordVM (io.github.jhipster.sample.web.rest.vm.KeyAndPasswordVM)12 Scheduled (org.springframework.scheduling.annotation.Scheduled)8 GrantedAuthority (org.springframework.security.core.GrantedAuthority)7 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)7 UserDetails (org.springframework.security.core.userdetails.UserDetails)7 PersistentToken (io.github.jhipster.sample.domain.PersistentToken)6