@@ -0,0 +1,2003 @@
+package com.rizki.mufrizal.belajar.oauth2.service;%0A%0Aimport com.rizki.mufrizal.belajar.oauth2.domain.UserRole;%0Aimport com.rizki.mufrizal.belajar.oauth2.repository.UserRepository;%0Aimport org.springframework.security.core.GrantedAuthority;%0Aimport org.springframework.security.core.authority.SimpleGrantedAuthority;%0Aimport org.springframework.security.core.userdetails.User;%0Aimport org.springframework.security.core.userdetails.UserDetails;%0Aimport org.springframework.security.core.userdetails.UserDetailsService;%0Aimport org.springframework.security.core.userdetails.UsernameNotFoundException;%0Aimport org.springframework.stereotype.Service;%0A%0Aimport javax.annotation.Resource;%0Aimport java.util.ArrayList;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0A@Service%0Apublic class UserDetailLoginService implements UserDetailsService%7B%0A%0A    @Resource%0A    private UserRepository userRepository;%0A%0A    @Override%0A    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException %7B%0A        com.rizki.mufrizal.belajar.oauth2.domain.User user = userRepository.getUserByUsername(username);%0A%0A        if (user == null) %7B%0A            return null;%0A        %7D%0A%0A        List%3CGrantedAuthority%3E userGrantedAuthorities = buildUserAuthority(user.getUserRoles());%0A        return buildUserForAuthentication(user, userGrantedAuthorities);%0A    %7D%0A%0A    private User buildUserForAuthentication(com.rizki.mufrizal.belajar.oauth2.domain.User user, List%3CGrantedAuthority%3E authorities) %7B%0A        return new User(user.getUsername(), user.getPassword(), user.isEnable(), true, true, true, authorities);%0A    %7D%0A%0A    private List%3CGrantedAuthority%3E buildUserAuthority(Set%3CUserRole%3E userRoleSet) %7B%0A        Set%3CGrantedAuthority%3E grantedAuthorities = new HashSet%3CGrantedAuthority%3E();%0A%0A        for (UserRole userRole : userRoleSet) %7B%0A            grantedAuthorities.add(new SimpleGrantedAuthority(userRole.getRole()));%0A        %7D%0A%0A        return new ArrayList%3CGrantedAuthority%3E(grantedAuthorities);%0A    %7D%0A%7D%0A

Add Domain User Detail Login