cust auth
This commit is contained in:
parent
94885418dc
commit
12b2cd17a6
|
|
@ -3,6 +3,7 @@ package com.bonus.system.api.model;
|
|||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
import com.bonus.system.api.domain.SysUser;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
|
|
@ -63,6 +64,12 @@ public class LoginUser implements Serializable
|
|||
*/
|
||||
private SysUser sysUser;
|
||||
|
||||
@ApiModelProperty("过期时间")
|
||||
private Long expireIn;
|
||||
|
||||
@ApiModelProperty("是否登录")
|
||||
private boolean isLogin;
|
||||
|
||||
public String getToken()
|
||||
{
|
||||
return token;
|
||||
|
|
@ -160,4 +167,20 @@ public class LoginUser implements Serializable
|
|||
{
|
||||
this.sysUser = sysUser;
|
||||
}
|
||||
|
||||
public Long getExpireIn() {
|
||||
return expireIn;
|
||||
}
|
||||
|
||||
public void setExpireIn(Long expireIn) {
|
||||
this.expireIn = expireIn;
|
||||
}
|
||||
|
||||
public boolean isLogin() {
|
||||
return isLogin;
|
||||
}
|
||||
|
||||
public void setLogin(boolean login) {
|
||||
isLogin = login;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.bonus.common.core.domain.R;
|
|||
import com.bonus.common.core.exception.ServiceException;
|
||||
import com.bonus.common.core.utils.JwtUtils;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.utils.encryption.Sm4Utils;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.redis.service.RedisService;
|
||||
import com.bonus.common.security.auth.AuthUtil;
|
||||
|
|
@ -31,6 +32,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
|
@ -147,8 +149,19 @@ public class TokenController {
|
|||
|
||||
LoginUser login = strategy.login(form.getUsername(), form.getPassword());
|
||||
logService.saveLogin(form.getUsername(), "登录", "登录成功", null, "成功");
|
||||
return R.ok(tokenService.createToken(login));
|
||||
|
||||
if (LoginType.CUST_PHONE_PASSWORD.equals(form.getLoginType()) || LoginType.CUST_PHONE_OPT.equals(form.getLoginType())) {
|
||||
Map<String, Object> map = tokenService.createCustToken(login);
|
||||
login.setToken((String) map.get("access_token"));
|
||||
login.setExpireIn((Long) map.get("expires_in"));
|
||||
login.setLogin((boolean) map.get("isLogin"));
|
||||
login.getSysUser().setPhonenumber(Sm4Utils.custDecrypt(login.getSysUser().getPhonenumber()));
|
||||
login.getSysUser().setCustName(Sm4Utils.custDecrypt(login.getSysUser().getCustName()));
|
||||
System.out.println(SecurityUtils.getLoginUser());
|
||||
return R.ok(login);
|
||||
} else {
|
||||
return R.ok(tokenService.createToken(login));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class CustPhonePasswordLoginStrategy implements LoginStrategy {
|
|||
passwordValidatorService.validateUserResult(phone, userResult);
|
||||
//获取用户信息
|
||||
LoginUser userInfo = userResult.getData();
|
||||
SysUser user = userInfo.getSysUser();
|
||||
//SysUser user = userInfo.getSysUser();
|
||||
//校验用户审批状态
|
||||
//passwordValidatorService.validateApprovalStatus(user.getUserName(), user);
|
||||
// 处理IP校验
|
||||
|
|
|
|||
|
|
@ -94,6 +94,36 @@ public class TokenService {
|
|||
return rspMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建客户令牌
|
||||
*/
|
||||
public Map<String, Object> createCustToken(LoginUser loginUser) {
|
||||
// 检查并删除已有的token
|
||||
delExistingToken(loginUser.getCustId());
|
||||
String token = IdUtils.fastUUID();
|
||||
Long custId = loginUser.getCustId();
|
||||
String userName = loginUser.getSysUser().getCustName();
|
||||
loginUser.setToken(token);
|
||||
loginUser.setCustId(custId);
|
||||
loginUser.getSysUser().setCustName(userName);
|
||||
loginUser.setIpaddr(IpUtils.getIpAddr());
|
||||
refreshToken(loginUser);
|
||||
// Jwt存储信息
|
||||
Map<String, Object> claimsMap = new HashMap<String, Object>(16);
|
||||
claimsMap.put(SecurityConstants.USER_KEY, token);
|
||||
claimsMap.put(SecurityConstants.DETAILS_USER_ID, custId);
|
||||
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
|
||||
String accessToken = JwtUtils.createToken(claimsMap);
|
||||
Map<String, Object> rspMap = new HashMap<String, Object>(16);
|
||||
rspMap.put(ACCESS_TOKEN, accessToken);
|
||||
rspMap.put("expires_in", EXPIRETIME);
|
||||
rspMap.put("isLogin", isLogin(String.valueOf(custId)));
|
||||
long tokenTime = getTokenTime();
|
||||
//对token进行存储
|
||||
redisService.setCacheObject(LOGIN_USER_KEY + custId, token, tokenTime, TimeUnit.MINUTES);
|
||||
return rspMap;
|
||||
}
|
||||
|
||||
public boolean isLogin(String userId) {
|
||||
String existingTokenKey = redisService.getCacheObject(LOGIN_USER_KEY + userId);
|
||||
return existingTokenKey != null;
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ public class SysUserController extends BaseController {
|
|||
* 获取当前用户信息
|
||||
*/
|
||||
@InnerAuth
|
||||
@GetMapping("/CustInfoPhoto/{photoNumber}")
|
||||
@GetMapping("/custInfoPhoto/{photoNumber}")
|
||||
public R<LoginUser> custInfoPhotoNumber(@PathVariable("photoNumber") String photoNumber) {
|
||||
SysUser sysUser = userService.selectCustInfoByPhoneNumber(photoNumber);
|
||||
if (StringUtils.isNull(sysUser)) {
|
||||
|
|
@ -224,11 +224,12 @@ public class SysUserController extends BaseController {
|
|||
//Set<String> roles = permissionService.getRolePermission(sysUser);
|
||||
// 权限集合
|
||||
//Set<String> permissions = permissionService.getMenuPermission(sysUser);
|
||||
LoginUser sysUserVo = new LoginUser();
|
||||
sysUserVo.setSysUser(sysUser);
|
||||
LoginUser loginUser = new LoginUser();
|
||||
loginUser.setCustId(sysUser.getCustId());
|
||||
loginUser.setSysUser(sysUser);
|
||||
//sysUserVo.setRoles(roles);
|
||||
//sysUserVo.setPermissions(permissions);
|
||||
return R.ok(sysUserVo);
|
||||
return R.ok(loginUser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -371,21 +371,13 @@
|
|||
|
||||
<!--根据人员id集合获取人员信息-->
|
||||
<select id="selectCustInfoByPhoneNumber" resultType="com.bonus.system.api.domain.SysUser">
|
||||
select cust_id, cust_name, cust_num, cust_photo_url, mobile as phonenumber, pwd as password
|
||||
select cust_id as custId, cust_name as custName, cust_num as custNum, cust_photo_url as custPhotoUrl,
|
||||
mobile as phonenumber, pwd as password
|
||||
from cust_info
|
||||
<where>
|
||||
cust_state = 1 and (psn_type != 999 or psn_type is null)
|
||||
<if test="custName != null and custName != ''">
|
||||
and cust_name = #{custName}
|
||||
</if>
|
||||
<if test="custNum != null and custNum != ''">
|
||||
and cust_num = #{custNum}
|
||||
</if>
|
||||
<if test="mobile != null and mobile != ''">
|
||||
and mobile = #{mobile}
|
||||
</if>
|
||||
<if test="idCard != null and idCard != ''">
|
||||
and id_card = #{idCard}
|
||||
<if test="phoneNumber != null and phoneNumber != ''">
|
||||
and mobile = #{phoneNumber}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
|
|
|||
Loading…
Reference in New Issue