Browse Source

1.提交登录获取仓库信息的问题 待解决

pull/1/head
pref_mail@163.com 2 years ago
parent
commit
30fcfc5ead
  1. 7
      blade-auth/pom.xml
  2. 25
      blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java
  3. 18
      blade-common/src/main/java/org/springblade/common/cache/CacheNames.java

7
blade-auth/pom.xml

@ -115,6 +115,13 @@
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springblade</groupId>-->
<!-- <artifactId>logpm-basicdata-api</artifactId>-->
<!-- <version>3.1.0.RELEASE</version>-->
<!-- </dependency>-->
</dependencies>
<build>

25
blade-auth/src/main/java/org/springblade/auth/service/BladeUserDetailsServiceImpl.java

@ -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());
}

18
blade-common/src/main/java/org/springblade/common/cache/CacheNames.java vendored

@ -45,6 +45,19 @@ public interface CacheNames {
static String tenantKey(String tenantId, String cacheKey, String cacheKeyValue) {
return tenantId.concat(":").concat(cacheKey).concat(cacheKeyValue);
}
/**
* 返回租户格式的key
*
* @param tenantId 租户编号
* @param cacheKey 缓存key
* @param cacheKeyValue 缓存key值
* @return tenantKey
*/
static String tenantKeyObj(String tenantId, String cacheKey, Object cacheKeyValue) {
return tenantId.concat(":").concat(cacheKey).concat(cacheKeyValue.toString());
}
/**
* 验证码key
@ -56,4 +69,9 @@ public interface CacheNames {
*/
String USER_FAIL_KEY = "blade:user::blade:fail:";
/**
* 用户选择仓库的key
*/
String USER_WAREHOUSE_KEY = "logpm:user:warehouse:select:";
}

Loading…
Cancel
Save