| | |
| | | import org.springblade.core.jwt.JwtUtil; |
| | | import org.springblade.core.jwt.props.JwtProperties; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.*; |
| | | import org.springblade.system.cache.ParamCache; |
| | | import org.springblade.common.cache.ParamCache; |
| | | import org.springblade.system.entity.Tenant; |
| | | import org.springblade.system.feign.ISysClient; |
| | | import org.springblade.system.service.IRoleService; |
| | | import org.springblade.system.service.ITenantService; |
| | | import org.springblade.system.user.entity.User; |
| | | import org.springblade.system.user.entity.UserInfo; |
| | | import org.springblade.system.user.enums.UserEnum; |
| | | import org.springblade.system.user.feign.IUserClient; |
| | | import org.springblade.system.user.service.IUserService; |
| | | import org.springframework.security.core.authority.AuthorityUtils; |
| | | import org.springframework.security.core.userdetails.UserDetailsService; |
| | | import org.springframework.security.core.userdetails.UsernameNotFoundException; |
| | |
| | | public static final Integer FAIL_COUNT = 5; |
| | | public static final String FAIL_COUNT_VALUE = "account.failCount"; |
| | | |
| | | private final IUserClient userClient; |
| | | private final ISysClient sysClient; |
| | | private final IUserService userClient; |
| | | private final ITenantService tenantService; |
| | | private final IRoleService sysClient; |
| | | |
| | | private final BladeRedis bladeRedis; |
| | | private final JwtProperties jwtProperties; |
| | |
| | | } |
| | | |
| | | // 获取租户信息 |
| | | R<Tenant> tenant = sysClient.getTenant(tenantId); |
| | | if (tenant.isSuccess()) { |
| | | if (TokenUtil.judgeTenant(tenant.getData())) { |
| | | Tenant tenant = tenantService.getByTenantId(tenantId); |
| | | if (null!=tenant) { |
| | | if (TokenUtil.judgeTenant(tenant)) { |
| | | throw new UserDeniedAuthorizationException(TokenUtil.USER_HAS_NO_TENANT_PERMISSION); |
| | | } |
| | | } else { |
| | |
| | | String userType = Func.toStr(request.getHeader(TokenUtil.USER_TYPE_HEADER_KEY), TokenUtil.DEFAULT_USER_TYPE); |
| | | |
| | | // 远程调用返回数据 |
| | | R<UserInfo> result; |
| | | UserInfo userInfo; |
| | | // 根据不同用户类型调用对应的接口返回数据,用户可自行拓展 |
| | | if (userType.equals(UserEnum.WEB.getName())) { |
| | | result = userClient.userInfo(tenantId, username, UserEnum.WEB.getName()); |
| | | userInfo = userClient.userInfo(tenantId, username, UserEnum.WEB); |
| | | } else if (userType.equals(UserEnum.APP.getName())) { |
| | | result = userClient.userInfo(tenantId, username, UserEnum.APP.getName()); |
| | | userInfo = userClient.userInfo(tenantId, username, UserEnum.APP); |
| | | } else { |
| | | result = userClient.userInfo(tenantId, username, UserEnum.OTHER.getName()); |
| | | userInfo = userClient.userInfo(tenantId, username, UserEnum.OTHER); |
| | | } |
| | | |
| | | // 判断返回信息 |
| | | if (result.isSuccess()) { |
| | | UserInfo userInfo = result.getData(); |
| | | if (null!=userInfo) { |
| | | User user = userInfo.getUser(); |
| | | // 用户不存在,但提示用户名与密码错误并锁定账号 |
| | | if (user == null || user.getId() == null) { |
| | |
| | | } |
| | | // 多角色情况下指定单角色 |
| | | if (Func.isNotEmpty(headerRole) && user.getRoleId().contains(headerRole)) { |
| | | R<List<String>> roleResult = sysClient.getRoleAliases(headerRole); |
| | | if (roleResult.isSuccess()) { |
| | | userInfo.setRoles(roleResult.getData()); |
| | | List<String> roleResult = sysClient.getRoleAliases(headerRole); |
| | | if (roleResult.size()>0) { |
| | | userInfo.setRoles(roleResult); |
| | | } |
| | | user.setRoleId(headerRole); |
| | | } |
| | |
| | | delFailCount(tenantId, username); |
| | | return new BladeUserDetails(user.getId(), |
| | | user.getTenantId(), StringPool.EMPTY, user.getName(), user.getRealName(), user.getDeptId(), user.getPostId(), user.getRoleId(), Func.join(userInfo.getRoles()), Func.toStr(user.getAvatar(), TokenUtil.DEFAULT_AVATAR), |
| | | username, AuthConstant.ENCRYPT + user.getPassword(), userInfo.getDetail(), true, true, true, true, |
| | | AuthorityUtils.commaSeparatedStringToAuthorityList(Func.join(result.getData().getRoles()))); |
| | | user.getClientIds(),username, AuthConstant.ENCRYPT + user.getPassword(), userInfo.getDetail(), true, true, true, true, |
| | | AuthorityUtils.commaSeparatedStringToAuthorityList(Func.join(userInfo.getRoles()))); |
| | | } else { |
| | | throw new UsernameNotFoundException(result.getMsg()); |
| | | throw new UsernameNotFoundException("没有找到用户信息"); |
| | | } |
| | | } |
| | | |