Search in sources :

Example 1 with Authority

use of io.github.jhipster.sample.domain.Authority in project jhipster-sample-app-dto by jhipster.

the class UserResourceIntTest method testUserToUserDTO.

@Test
public void testUserToUserDTO() {
    user.setId(DEFAULT_ID);
    user.setCreatedBy(DEFAULT_LOGIN);
    user.setCreatedDate(Instant.now());
    user.setLastModifiedBy(DEFAULT_LOGIN);
    user.setLastModifiedDate(Instant.now());
    Set<Authority> authorities = new HashSet<>();
    Authority authority = new Authority();
    authority.setName(AuthoritiesConstants.USER);
    authorities.add(authority);
    user.setAuthorities(authorities);
    UserDTO userDTO = userMapper.userToUserDTO(user);
    assertThat(userDTO.getId()).isEqualTo(DEFAULT_ID);
    assertThat(userDTO.getLogin()).isEqualTo(DEFAULT_LOGIN);
    assertThat(userDTO.getFirstName()).isEqualTo(DEFAULT_FIRSTNAME);
    assertThat(userDTO.getLastName()).isEqualTo(DEFAULT_LASTNAME);
    assertThat(userDTO.getEmail()).isEqualTo(DEFAULT_EMAIL);
    assertThat(userDTO.isActivated()).isEqualTo(true);
    assertThat(userDTO.getImageUrl()).isEqualTo(DEFAULT_IMAGEURL);
    assertThat(userDTO.getLangKey()).isEqualTo(DEFAULT_LANGKEY);
    assertThat(userDTO.getCreatedBy()).isEqualTo(DEFAULT_LOGIN);
    assertThat(userDTO.getCreatedDate()).isEqualTo(user.getCreatedDate());
    assertThat(userDTO.getLastModifiedBy()).isEqualTo(DEFAULT_LOGIN);
    assertThat(userDTO.getLastModifiedDate()).isEqualTo(user.getLastModifiedDate());
    assertThat(userDTO.getAuthorities()).containsExactly(AuthoritiesConstants.USER);
    assertThat(userDTO.toString()).isNotNull();
}
Also used : Authority(io.github.jhipster.sample.domain.Authority) UserDTO(io.github.jhipster.sample.service.dto.UserDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Authority

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

the class UserResourceIntTest method testAuthorityEquals.

@Test
public void testAuthorityEquals() throws Exception {
    Authority authorityA = new Authority();
    assertThat(authorityA).isEqualTo(authorityA);
    assertThat(authorityA).isNotEqualTo(null);
    assertThat(authorityA).isNotEqualTo(new Object());
    assertThat(authorityA.hashCode()).isEqualTo(0);
    assertThat(authorityA.toString()).isNotNull();
    Authority authorityB = new Authority();
    assertThat(authorityA).isEqualTo(authorityB);
    authorityB.setName(AuthoritiesConstants.ADMIN);
    assertThat(authorityA).isNotEqualTo(authorityB);
    authorityA.setName(AuthoritiesConstants.USER);
    assertThat(authorityA).isNotEqualTo(authorityB);
    authorityB.setName(AuthoritiesConstants.USER);
    assertThat(authorityA).isEqualTo(authorityB);
    assertThat(authorityA.hashCode()).isEqualTo(authorityB.hashCode());
}
Also used : Authority(io.github.jhipster.sample.domain.Authority) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Authority

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

the class UserResourceIntTest method testUserToUserDTO.

@Test
public void testUserToUserDTO() {
    user.setId(DEFAULT_ID);
    user.setCreatedBy(DEFAULT_LOGIN);
    user.setCreatedDate(Instant.now());
    user.setLastModifiedBy(DEFAULT_LOGIN);
    user.setLastModifiedDate(Instant.now());
    Set<Authority> authorities = new HashSet<>();
    Authority authority = new Authority();
    authority.setName(AuthoritiesConstants.USER);
    authorities.add(authority);
    user.setAuthorities(authorities);
    UserDTO userDTO = userMapper.userToUserDTO(user);
    assertThat(userDTO.getId()).isEqualTo(DEFAULT_ID);
    assertThat(userDTO.getLogin()).isEqualTo(DEFAULT_LOGIN);
    assertThat(userDTO.getFirstName()).isEqualTo(DEFAULT_FIRSTNAME);
    assertThat(userDTO.getLastName()).isEqualTo(DEFAULT_LASTNAME);
    assertThat(userDTO.getEmail()).isEqualTo(DEFAULT_EMAIL);
    assertThat(userDTO.isActivated()).isEqualTo(true);
    assertThat(userDTO.getImageUrl()).isEqualTo(DEFAULT_IMAGEURL);
    assertThat(userDTO.getLangKey()).isEqualTo(DEFAULT_LANGKEY);
    assertThat(userDTO.getCreatedBy()).isEqualTo(DEFAULT_LOGIN);
    assertThat(userDTO.getCreatedDate()).isEqualTo(user.getCreatedDate());
    assertThat(userDTO.getLastModifiedBy()).isEqualTo(DEFAULT_LOGIN);
    assertThat(userDTO.getLastModifiedDate()).isEqualTo(user.getLastModifiedDate());
    assertThat(userDTO.getAuthorities()).containsExactly(AuthoritiesConstants.USER);
    assertThat(userDTO.toString()).isNotNull();
}
Also used : Authority(io.github.jhipster.sample.domain.Authority) UserDTO(io.github.jhipster.sample.service.dto.UserDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Authority

use of io.github.jhipster.sample.domain.Authority 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 5 with Authority

use of io.github.jhipster.sample.domain.Authority 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

Authority (io.github.jhipster.sample.domain.Authority)37 User (io.github.jhipster.sample.domain.User)24 Test (org.junit.Test)18 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 UserDTO (io.github.jhipster.sample.service.dto.UserDTO)7 WithMockUser (org.springframework.security.test.context.support.WithMockUser)5 ChangeSet (com.github.mongobee.changeset.ChangeSet)2 HashSet (java.util.HashSet)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)1 Transactional (org.springframework.transaction.annotation.Transactional)1