package com.css.simulation.oauth.server.cofiguration.security;


import api.common.pojo.po.system.UserPO;
import api.common.util.CollectionUtil;
import com.css.simulation.oauth.server.mapper.UserMapper;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
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;

import javax.annotation.Resource;

@Service
public class MyUserDetailsService implements UserDetailsService {

    @Resource
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserPO userPO = userMapper.selectByUsername(username);
        return new MyUserDetails(
                userPO.getId(),
                userPO.getUsername(),
                userPO.getPassword(),
                userPO.getRoleCode(),
                userPO.getUseType(),
                userPO.getCreateUserId(),
                CollectionUtil.createHashSet(new SimpleGrantedAuthority("default11111111111"))
        );
    }


}
