A granted authority textual representation is required
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
@Autowired
private UserInfoService userInfoDAO;
@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
UserInfo userInfo = userInfoDAO.getUserInfoByUserName();
GrantedAuthority authority = new SimpleGrantedAuthority(userInfo.getRole());
return new User(userInfo.getUserName(), userInfo.getPassword(), Arrays.asList(authority));
}
}
@Service
public class UserInfoService {
@Value("${auth.username}")
private String username;
@Value("${auth.password}")
private String password;
//setting the system user
public UserInfo getUserInfoByUserName(){
UserInfo userInfo =new UserInfo();
userInfo.setUserName(username);
userInfo.setPassword(password);
userInfo.setRole("USER");
return userInfo;
}
}