Search in sources :

Example 46 with UserEntity

use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.

the class SocialConnectionService method addConnection.

@Override
@Transactional
public void addConnection(Connection<?> connection) {
    ConnectionData data = connection.createData();
    int rank = connectionRepository.getRank(userId, data.getProviderId());
    SocialConnectionEntity userConnection = new SocialConnectionEntity().setUser(new UserEntity().setId(userId)).setProvider(data.getProviderId()).setProviderUserId(data.getProviderUserId()).setRank(rank).setDisplayName(data.getDisplayName()).setProfileUrl(data.getProfileUrl()).setImageUrl(data.getImageUrl()).setAccessToken(encrypt(data.getAccessToken())).setSecret(encrypt(data.getSecret())).setRefreshToken(encrypt(data.getRefreshToken())).setExpireTime(data.getExpireTime());
    connectionRepository.save(userConnection);
}
Also used : ConnectionData(org.springframework.social.connect.ConnectionData) UserEntity(org.codenergic.theskeleton.user.UserEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with UserEntity

use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.

the class RoleServiceImpl method addRoleToUser.

@Override
@Transactional
public UserEntity addRoleToUser(String username, String roleCode) {
    UserEntity user = userRepository.findByUsername(username).orElseThrow(() -> new UsernameNotFoundException(username));
    RoleEntity role = roleRepository.findByCode(roleCode).orElseThrow(() -> new RoleNotFoundException(roleCode));
    return userRoleRepository.save(new UserRoleEntity(user, role)).getUser();
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) UserEntity(org.codenergic.theskeleton.user.UserEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 48 with UserEntity

use of org.codenergic.theskeleton.user.UserEntity in project theskeleton by codenergic.

the class RegistrationServiceImpl method activateUser.

@Override
@Transactional
public void activateUser(String activationToken) {
    try {
        TokenStoreRestData token = tokenStoreService.findAndVerifyToken(activationToken);
        UserEntity user = (UserEntity) token.getUser();
        if (user.isEnabled()) {
            throw new RegistrationException("Your Account is already activated");
        }
        user.setEnabled(true);
    } catch (InvalidSignatureException e) {
        throw new RegistrationException("Invalid Activation Key");
    }
}
Also used : InvalidSignatureException(org.springframework.security.jwt.crypto.sign.InvalidSignatureException) TokenStoreRestData(org.codenergic.theskeleton.tokenstore.TokenStoreRestData) UserEntity(org.codenergic.theskeleton.user.UserEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserEntity (org.codenergic.theskeleton.user.UserEntity)48 Test (org.junit.Test)30 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)14 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)10 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)8 Transactional (org.springframework.transaction.annotation.Transactional)7 WithMockUser (org.springframework.security.test.context.support.WithMockUser)6 Before (org.junit.Before)5 Authentication (org.springframework.security.core.Authentication)5 PageableHandlerMethodArgumentResolver (org.springframework.data.web.PageableHandlerMethodArgumentResolver)4 AuthenticationPrincipalArgumentResolver (org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver)4 InputStream (java.io.InputStream)3 Date (java.util.Date)3 UserArgumentResolver (org.codenergic.theskeleton.core.web.UserArgumentResolver)3 PageImpl (org.springframework.data.domain.PageImpl)3 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)3 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)2 OAuth2ClientEntity (org.codenergic.theskeleton.client.OAuth2ClientEntity)2 EmailServiceTest (org.codenergic.theskeleton.core.mail.EmailServiceTest)2 RegistrationException (org.codenergic.theskeleton.registration.RegistrationException)2