取得UserDetailService对象
自定义接口,实现UserDetailService接口
package com.example.service;
import org.springframework.security.core.userdetails.UserDetailsService;
public interface IUserDetailService extends UserDetailsService {
}
自定义接口实现类
package com.example.service.impl;
import org.springframework.security.core.userdetails.User;
import com.example.service.IUserDetailService;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import java.util.ArrayList;
import java.util.List;
public class UserDetailServiceImpl implements IUserDetailService {
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
String password = "456";
List<SimpleGrantedAuthority> list = new ArrayList<>();
list.add(new SimpleGrantedAuthority("USER1"));
UserDetails userDetails = new User(username,password,list);
return userDetails;
}
}