New file |
| | |
| | | package com.jilongda.applet.security; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.jilongda.applet.mapper.TAppUserMapper; |
| | | import com.jilongda.applet.model.SecUser; |
| | | import com.jilongda.applet.model.TAppUser; |
| | | import com.jilongda.common.basic.Constant; |
| | | import com.jilongda.common.utils.SpringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.core.userdetails.UserDetailsService; |
| | | import org.springframework.security.core.userdetails.UsernameNotFoundException; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | /** |
| | | * 用户登录认证信息查询 |
| | | * |
| | | * @author xiaochen |
| | | * @date Jun 29, 2019 |
| | | */ |
| | | @Component("loadUserDetailsService") |
| | | public class SysUserDetailsService implements UserDetailsService { |
| | | @Autowired |
| | | private TAppUserMapper appUserMapper; |
| | | |
| | | |
| | | @Override |
| | | public SecurityUserDetails loadUserByUsername(String openId) throws UsernameNotFoundException { |
| | | TAppUser user = appUserMapper.selectOne(Wrappers.lambdaQuery(TAppUser.class).eq(TAppUser::getOpenId, openId).last(" LIMIT 1")); |
| | | |
| | | if (Objects.isNull(user)) { |
| | | throw new UsernameNotFoundException("该用户不存在"); |
| | | } |
| | | |
| | | SecurityUserDetails vo = SpringUtils.beanCopy(user, SecurityUserDetails.class); |
| | | // if (user.getAccount().equals(Constant.ADMIN)) { |
| | | // getAdminPermission(vo); |
| | | // } else { |
| | | // List<SecRole> roles = secRoleMapper.selectRolesByUid(user.getId()); |
| | | // List<Long> roleIds = roles.stream().map(SecRole::getId).collect(Collectors.toList()); |
| | | // List<SecResourceVO> resources; |
| | | // if (CollectionUtils.isEmpty(roleIds)) { |
| | | // resources = new ArrayList<>(); |
| | | // } else { |
| | | // resources = secUserService.getResourceTag(user.getId()); |
| | | // } |
| | | // vo.setRoles(roles); |
| | | // vo.setResources(resources); |
| | | // } |
| | | // // 更新登录时间 |
| | | // SecurityUserDetails securityUserDetails = new SecurityUserDetails(); |
| | | // securityUserDetails.setId(user.getId()); |
| | | // securityUserDetails.setLastLoginTime(LocalDateTime.now()); |
| | | // secUserMapper.updateById(securityUserDetails); |
| | | return vo; |
| | | } |
| | | } |