get token
This commit is contained in:
parent
f3d4bdb3a8
commit
517b804dbd
|
|
@ -8,8 +8,13 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.bonus.canteen.core.auth.oauth.util.OAuthUtil;
|
||||
import com.bonus.canteen.core.auth.user.dto.UserLoginDTO;
|
||||
import com.bonus.canteen.core.config.AccessToken;
|
||||
import com.bonus.canteen.core.config.SecureProperties;
|
||||
import com.bonus.canteen.core.config.SmUtils;
|
||||
import com.bonus.canteen.core.config.WebContext;
|
||||
import com.bonus.canteen.core.customer.model.PigxUser;
|
||||
import com.bonus.canteen.core.device.mq.MacMessageService;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.google.common.base.Joiner;
|
||||
|
|
@ -90,29 +95,28 @@ public class AuthController {
|
|||
//
|
||||
// return LeResponse.succ(object);
|
||||
// }
|
||||
//
|
||||
// @PostMapping({"/token"})
|
||||
// @RequiresGuest
|
||||
// @ApiOperation("设备登陆接口登陆")
|
||||
// public LeResponse<JSONObject> login(@RequestParam String content) {
|
||||
// MgrUserLoginDTO loginDTO = (MgrUserLoginDTO)JSON.parseObject(content, MgrUserLoginDTO.class);
|
||||
//
|
||||
// JSONObject object;
|
||||
// try {
|
||||
// PigxUser user = this.mgrUserService.login(loginDTO);
|
||||
// object = JSON.parseObject(JSON.toJSONString(user));
|
||||
// object.put("user_id", user.getId());
|
||||
// object.put("merchant_id", user.getMerchantId());
|
||||
// if (WebContext.get().getAccessToken().isPresent()) {
|
||||
// object.put("securityTokenSign", OAuthUtil.responseSetSecurityTokenSign(user.getMerchantId(), ((AccessToken)WebContext.get().getAccessToken().get()).getId()));
|
||||
// }
|
||||
// } catch (LeCheckedException var5) {
|
||||
// return LeResponse.fail(var5.getMessage());
|
||||
// }
|
||||
//
|
||||
// return LeResponse.succ(object);
|
||||
// }
|
||||
//
|
||||
|
||||
@PostMapping({"/token"})
|
||||
@ApiOperation("设备登陆接口登陆")
|
||||
public AjaxResult login(@RequestParam String content) {
|
||||
UserLoginDTO loginDTO = (UserLoginDTO)JSON.parseObject(content, UserLoginDTO.class);
|
||||
|
||||
JSONObject object;
|
||||
try {
|
||||
PigxUser user = new PigxUser(); //this.mgrUserService.login(loginDTO);
|
||||
object = JSON.parseObject(JSON.toJSONString(user));
|
||||
object.put("user_id", user.getId());
|
||||
object.put("merchant_id", user.getMerchantId());
|
||||
if (WebContext.get().getAccessToken().isPresent()) {
|
||||
object.put("securityTokenSign", OAuthUtil.responseSetSecurityTokenSign(user.getMerchantId(), ((AccessToken)WebContext.get().getAccessToken().get()).getId()));
|
||||
}
|
||||
} catch (Exception var5) {
|
||||
return AjaxResult.error(var5.getMessage());
|
||||
}
|
||||
|
||||
return AjaxResult.success(object);
|
||||
}
|
||||
|
||||
// @DeleteMapping({"/logOut"})
|
||||
// @RequiresAuthentication
|
||||
// @ApiOperation("退出登陆")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
package com.bonus.canteen.core.auth.oauth.util;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.bonus.canteen.core.common.utils.SpringContextHolder;
|
||||
import com.bonus.canteen.core.config.SecureProperties;
|
||||
import com.bonus.canteen.core.config.SmUtils;
|
||||
import com.bonus.canteen.core.config.WebContext;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class OAuthUtil {
|
||||
private static final String HEADER_SECURITY_TENANT_ID = "X-Security-Tenant-Id";
|
||||
private static final String HEADER_SECURITY_TOKEN = "X-Security-Token";
|
||||
@Lazy
|
||||
private static final SecureProperties secureProperties = (SecureProperties) SpringContextHolder.getBean(SecureProperties.class);
|
||||
|
||||
private OAuthUtil() {
|
||||
}
|
||||
|
||||
public static String responseSetSecurityTokenSign(Long merchantId, String token) {
|
||||
TreeMap<String, String> needSignMap = new TreeMap();
|
||||
String securityTokenSign = null;
|
||||
if (WebContext.get().getRequest().isPresent()) {
|
||||
String encryptKey = ((HttpServletRequest)WebContext.get().getRequest().get()).getHeader(secureProperties.getSecurity().getServerEncryptedClientKeyHeaderName());
|
||||
if (ObjectUtil.isNotNull(encryptKey)) {
|
||||
if (ObjectUtil.isNotNull(merchantId)) {
|
||||
needSignMap.put("X-Security-Tenant-Id", String.valueOf(merchantId));
|
||||
}
|
||||
|
||||
needSignMap.put("X-Security-Token", token);
|
||||
String serverEncryptedClientKey = ((HttpServletRequest) WebContext.get().getRequest().get()).getHeader(secureProperties.getSecurity().getServerEncryptedClientKeyHeaderName());
|
||||
String clientKey = SmUtils.decryptBySm4WithServerKey(serverEncryptedClientKey);
|
||||
securityTokenSign = SmUtils.signAuthTokenBySm3(needSignMap, clientKey);
|
||||
}
|
||||
}
|
||||
|
||||
return securityTokenSign;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package com.bonus.canteen.core.auth.user.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ApiModel("登录入参")
|
||||
public class UserLoginDTO implements Serializable {
|
||||
@ApiModelProperty("用户名")
|
||||
private @NotBlank(
|
||||
message = "用户名不能为空"
|
||||
) String username;
|
||||
@ApiModelProperty("密码")
|
||||
private @NotBlank(
|
||||
message = "密码不能为空"
|
||||
) String password;
|
||||
private String scope;
|
||||
private String grant_type;
|
||||
private String role;
|
||||
private String openid;
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public String getScope() {
|
||||
return this.scope;
|
||||
}
|
||||
|
||||
public String getGrant_type() {
|
||||
return this.grant_type;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return this.role;
|
||||
}
|
||||
|
||||
public String getOpenid() {
|
||||
return this.openid;
|
||||
}
|
||||
|
||||
public void setUsername(final String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setPassword(final String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void setScope(final String scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public void setGrant_type(final String grant_type) {
|
||||
this.grant_type = grant_type;
|
||||
}
|
||||
|
||||
public void setRole(final String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public void setOpenid(final String openid) {
|
||||
this.openid = openid;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String var10000 = this.getUsername();
|
||||
return "MgrUserLoginDTO(username=" + var10000 + ", password=" + this.getPassword() + ", scope=" + this.getScope() + ", grant_type=" + this.getGrant_type() + ", role=" + this.getRole() + ", openid=" + this.getOpenid() + ")";
|
||||
}
|
||||
|
||||
public UserLoginDTO(final String username, final String password, final String scope, final String grant_type, final String role, final String openid) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.scope = scope;
|
||||
this.grant_type = grant_type;
|
||||
this.role = role;
|
||||
this.openid = openid;
|
||||
}
|
||||
|
||||
public UserLoginDTO() {
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue