Search in sources :

Example 1 with Authority

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

Authority (com.ctrip.framework.apollo.portal.entity.po.Authority)1 UserPO (com.ctrip.framework.apollo.portal.entity.po.UserPO)1 Transactional (org.springframework.transaction.annotation.Transactional)1