0
我有一个类Customer类这样如何在Spring Security上下文中投射UserDetails?
public class MyCustomer {
public String username;
public String email;
public String password;
}
,我有一个一流的服务,这是实现的UserDetailsService
@Override
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException
{
MyCustomer customer = customerDao.findByName(username);
return new User(customer.getName(), customer.getEmail(), true, true, true, true, customer.getRoles())
}
我怎样才能在控制类MyCustomer?我已经尝试过,但不幸的是,它不起作用。
MyCustomer customer = (MyCustomer)SecurityContextHolder.getContext().getAuthentication().getPrincipal();