Search in sources :

Example 1 with UserPO

use of com.ctrip.framework.apollo.portal.entity.po.UserPO in project apollo by ctripcorp.

the class OidcLocalUserServiceImpl method updateUserInfoInternal.

private void updateUserInfoInternal(UserInfo newUserInfo) {
    UserPO managedUser = userRepository.findByUsername(newUserInfo.getUserId());
    if (!StringUtils.isBlank(newUserInfo.getEmail())) {
        managedUser.setEmail(newUserInfo.getEmail());
    }
    if (!StringUtils.isBlank(newUserInfo.getName())) {
        managedUser.setUserDisplayName(newUserInfo.getName());
    }
    userRepository.save(managedUser);
}
Also used : UserPO(com.ctrip.framework.apollo.portal.entity.po.UserPO)

Example 2 with UserPO

use of com.ctrip.framework.apollo.portal.entity.po.UserPO in project apollo by ctripcorp.

the class UserInfoControllerTest method testCreateOrUpdateUser.

@Test
public void testCreateOrUpdateUser() {
    UserPO user = new UserPO();
    user.setUsername("username");
    user.setPassword("password");
    Mockito.when(userPasswordChecker.checkWeakPassword(Mockito.anyString())).thenReturn(new CheckResult(Boolean.TRUE, ""));
    userInfoController.createOrUpdateUser(user);
}
Also used : CheckResult(com.ctrip.framework.apollo.portal.util.checker.CheckResult) UserPO(com.ctrip.framework.apollo.portal.entity.po.UserPO) Test(org.junit.Test)

Example 3 with UserPO

use of com.ctrip.framework.apollo.portal.entity.po.UserPO in project apollo by ctripcorp.

the class UserInfoControllerTest method testCreateOrUpdateUserFailed.

@Test(expected = BadRequestException.class)
public void testCreateOrUpdateUserFailed() {
    UserPO user = new UserPO();
    user.setUsername("username");
    user.setPassword("password");
    String msg = "fake error message";
    Mockito.when(userPasswordChecker.checkWeakPassword(Mockito.anyString())).thenReturn(new CheckResult(Boolean.FALSE, msg));
    try {
        userInfoController.createOrUpdateUser(user);
    } catch (BadRequestException e) {
        Assert.assertEquals(msg, e.getMessage());
        throw e;
    }
}
Also used : CheckResult(com.ctrip.framework.apollo.portal.util.checker.CheckResult) BadRequestException(com.ctrip.framework.apollo.common.exception.BadRequestException) UserPO(com.ctrip.framework.apollo.portal.entity.po.UserPO) Test(org.junit.Test)

Example 4 with UserPO

use of com.ctrip.framework.apollo.portal.entity.po.UserPO in project apollo by ctripcorp.

the class SpringSecurityUserService method createOrUpdate.

@Transactional
public void createOrUpdate(UserPO user) {
    String username = user.getUsername();
    String newPassword = passwordEncoder.encode(user.getPassword());
    UserPO managedUser = userRepository.findByUsername(username);
    if (managedUser == null) {
        user.setPassword(newPassword);
        user.setEnabled(1);
        userRepository.save(user);
        // save authorities
        Authority authority = new Authority();
        authority.setUsername(username);
        authority.setAuthority("ROLE_user");
        authorityRepository.save(authority);
    } else {
        managedUser.setPassword(newPassword);
        managedUser.setEmail(user.getEmail());
        managedUser.setUserDisplayName(user.getUserDisplayName());
        userRepository.save(managedUser);
    }
}
Also used : Authority(com.ctrip.framework.apollo.portal.entity.po.Authority) UserPO(com.ctrip.framework.apollo.portal.entity.po.UserPO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UserPO (com.ctrip.framework.apollo.portal.entity.po.UserPO)4 CheckResult (com.ctrip.framework.apollo.portal.util.checker.CheckResult)2 Test (org.junit.Test)2 BadRequestException (com.ctrip.framework.apollo.common.exception.BadRequestException)1 Authority (com.ctrip.framework.apollo.portal.entity.po.Authority)1 Transactional (org.springframework.transaction.annotation.Transactional)1