Created
August 29, 2016 15:02
-
-
Save rixlabs/0162796b0c8c1425d9bb7793b090cf57 to your computer and use it in GitHub Desktop.
CustomUserdetailService
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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