Skip to content

Instantly share code, notes, and snippets.

@rixlabs
Created August 29, 2016 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rixlabs/0162796b0c8c1425d9bb7793b090cf57 to your computer and use it in GitHub Desktop.
Save rixlabs/0162796b0c8c1425d9bb7793b090cf57 to your computer and use it in GitHub Desktop.
CustomUserdetailService
import ch.lugano.egov.data.AccountRepository;
import ch.lugano.egov.data.StaticUserStore;
import ch.lugano.egov.models.Account;
import ch.lugano.egov.models.CustomUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
@Service
public class CustomUserdetailService implements UserDetailsService {
@Autowired
StaticUserStore userStore;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Account account = userStore.findByUsername(username);
if(account != null) {
return new CustomUser(
account.getId(),
account.getUsername(),
account.getPassword(),
account.getLastPasswordReset(),
AuthorityUtils.createAuthorityList("USER"));
} else {
throw new UsernameNotFoundException("could not find the user '"
+ username + "'");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment