Exemplo n.º 1
0
 @Override
 public AccountDTO registerUser(RegistrationForm registrationForm) {
   if (null == registrationForm) {
     log.error("registrationForm was invalid, registration failed");
   } else {
     registrationForm.setPassword(EncodingUtils.encrypt(registrationForm.getPassword()));
     Account account = getMapper().map(registrationForm, Account.class);
     account.setAuthorities(new HashSet<>(Arrays.asList(Authority.AUTHOR)));
     return getMapper().map(accountRepository.save(account), AccountDTO.class);
   }
   return null;
 }
Exemplo n.º 2
0
 @Override
 public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException {
   UserDetails userDetails = null;
   Account account = accountRepository.findByLogin(login);
   if (null == account) {
     log.warn("User " + login + " not found");
     throw new UsernameNotFoundException("User " + login + " not found.");
   }
   List<GrantedAuthority> authorities = buildUserAuthority(account.getAuthorities());
   userDetails = buildUserForAuthentication(account, authorities);
   return userDetails;
 }
Exemplo n.º 3
0
 private User buildUserForAuthentication(Account account, List<GrantedAuthority> authorities) {
   return new User(
       account.getUsername(),
       account.getPassword(),
       account.isEnabled(),
       account.isAccountNonExpired(),
       account.isCredentialsNonExpired(),
       account.isAccountNonLocked(),
       authorities);
 }