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);
}
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);
}
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;
}
}
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);
}
}
Aggregations