|
|
|
@ -16,10 +16,12 @@
|
|
|
|
|
*/ |
|
|
|
|
package org.springblade.auth.service; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.alibaba.nacos.common.utils.StringUtils; |
|
|
|
|
import io.jsonwebtoken.Claims; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.SneakyThrows; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.auth.constant.AuthConstant; |
|
|
|
|
import org.springblade.auth.utils.TokenUtil; |
|
|
|
|
import org.springblade.common.cache.CacheNames; |
|
|
|
@ -53,6 +55,7 @@ import java.util.List;
|
|
|
|
|
*/ |
|
|
|
|
@Service |
|
|
|
|
@AllArgsConstructor |
|
|
|
|
@Slf4j |
|
|
|
|
public class BladeUserDetailsServiceImpl implements UserDetailsService { |
|
|
|
|
|
|
|
|
|
public static final Integer FAIL_COUNT = 5; |
|
|
|
@ -149,16 +152,34 @@ public class BladeUserDetailsServiceImpl implements UserDetailsService {
|
|
|
|
|
user.setRoleId(headerRole); |
|
|
|
|
} |
|
|
|
|
// 判断账号的停用时间
|
|
|
|
|
if(Func.isNotEmpty(user.getDownTime()) && user.getDownTime().getTime() < new Date().getTime()){ |
|
|
|
|
if (Func.isNotEmpty(user.getDownTime()) && user.getDownTime().getTime() < new Date().getTime()) { |
|
|
|
|
throw new UserDeniedAuthorizationException(TokenUtil.ACCOUNT_DISABLE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 绑定仓库
|
|
|
|
|
String key = CacheNames.tenantKeyObj(tenantId, CacheNames.USER_WAREHOUSE_KEY, user.getId()); |
|
|
|
|
try{ |
|
|
|
|
Object json = bladeRedis.getRedisTemplate().opsForValue().get(key); |
|
|
|
|
if(ObjectUtil.isNotEmpty(json)){ |
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(json.toString()); |
|
|
|
|
if(ObjectUtil.isNotEmpty(jsonObject)){ |
|
|
|
|
userInfo.getDetail().put("warehouse_id",jsonObject.get("id")); |
|
|
|
|
userInfo.getDetail().put("warehouse_name",jsonObject.get("name")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}catch (Exception e){ |
|
|
|
|
log.error("登录获取仓库信息报错 {}",e.getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 成功则清除登录错误次数
|
|
|
|
|
delFailCount(tenantId, username); |
|
|
|
|
return new BladeUserDetails(user.getId(), |
|
|
|
|
|
|
|
|
|
BladeUserDetails bladeUserDetails = 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()))); |
|
|
|
|
|
|
|
|
|
return bladeUserDetails; |
|
|
|
|
} else { |
|
|
|
|
throw new UsernameNotFoundException(result.getMsg()); |
|
|
|
|
} |
|
|
|
|