use of com.ctrip.framework.apollo.portal.entity.po.Authority 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