Search in sources :

Example 1 with UserInfo

use of org.example.security.auth.entity.UserInfo in project spring-boot-learning-demo by rookie-ricardo.

the class CustomUserDetailsService method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
    log.debug("开始登陆验证,用户名为: {}", s);
    // 根据用户名验证用户
    QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
    queryWrapper.lambda().eq(UserInfo::getUsername, s);
    UserInfo userInfo = userService.getOne(queryWrapper);
    if (userInfo == null) {
        throw new UsernameNotFoundException("用户名不存在,登陆失败。");
    }
    // 构建UserDetail对象
    UserDetail userDetail = new UserDetail();
    userDetail.setUserInfo(userInfo);
    List<RoleInfo> roleInfoList = roleInfoService.listRoleByUserId(userInfo.getId());
    userDetail.setRoleInfoList(roleInfoList);
    return userDetail;
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) UserDetail(org.example.security.auth.entity.UserDetail) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) RoleInfo(org.example.security.auth.entity.RoleInfo) UserInfo(org.example.security.auth.entity.UserInfo)

Example 2 with UserInfo

use of org.example.security.auth.entity.UserInfo in project spring-boot-learning-demo by rookie-ricardo.

the class UserServiceTest method insertData.

@Test
public void insertData() {
    UserInfo userInfo = new UserInfo();
    userInfo.setUsername("test");
    userInfo.setPassword(passwordEncoder.encode("123456"));
    userInfo.setActiveStatus(1);
    userInfo.setCreateTime(LocalDateTime.now());
    boolean save = userService.save(userInfo);
    if (save) {
        System.out.println("插入成功");
    }
}
Also used : UserInfo(org.example.security.auth.entity.UserInfo) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

UserInfo (org.example.security.auth.entity.UserInfo)2 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 RoleInfo (org.example.security.auth.entity.RoleInfo)1 UserDetail (org.example.security.auth.entity.UserDetail)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1