|
@@ -17,13 +17,17 @@
|
|
|
package org.springblade.system.user.controller;
|
|
|
|
|
|
|
|
|
+import cn.hutool.jwt.JWT;
|
|
|
+import cn.hutool.jwt.JWTUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.nacos.common.utils.MD5Utils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import io.jsonwebtoken.Claims;
|
|
|
import io.swagger.annotations.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.http.Consts;
|
|
@@ -31,6 +35,7 @@ import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.NameValuePair;
|
|
|
import org.apache.http.client.HttpClient;
|
|
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
@@ -423,58 +428,78 @@ public class UserController {
|
|
|
return R.success("操作成功");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* token验证登录
|
|
|
*/
|
|
|
@PostMapping("/loginByToken")
|
|
|
@ApiOperationSupport(order = 20)
|
|
|
@ApiOperation(value = "token验证加密", notes = "token验证登录")
|
|
|
- public R loginByToken(String token, String account, String timestamp) {
|
|
|
- if (StringUtil.isBlank(token)) {
|
|
|
- return R.fail("请输出token");
|
|
|
- }
|
|
|
- if (StringUtil.isBlank(account)) {
|
|
|
- return R.fail("请输出account");
|
|
|
- }
|
|
|
- if (StringUtil.isBlank(timestamp)) {
|
|
|
- return R.fail("请输出timestamp");
|
|
|
+ public R loginByToken(String token) {
|
|
|
+ // this.loginByToken2(token);
|
|
|
+ token = "bearer "+token;
|
|
|
+ HttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
+ HttpGet httpPost = new HttpGet("http://47.110.251.215:8090/blade-auth/oauth/user-info");
|
|
|
+ httpPost.setHeader("Authorization", token); //这个需要 client:
|
|
|
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ HttpResponse httpResponse = httpClient.execute(httpPost);
|
|
|
+ InputStream inputStream = httpResponse.getEntity().getContent();
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int index = 0;
|
|
|
+ while ((index = inputStream.read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, index);
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSON.parseObject(outputStream.toString());
|
|
|
+ if(jsonObject!=null && ObjectUtil.isNotEmpty(jsonObject)){
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ String name = data.getString("name");
|
|
|
+ return this.loginByToken2(name);
|
|
|
+ }else{
|
|
|
+ return R.fail("token解析用户失败");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return R.success("操作失败");
|
|
|
}
|
|
|
|
|
|
- //解析tokne
|
|
|
- String tokenInfo = AesInfoUtil.decrypt(token, null);
|
|
|
- if (tokenInfo != null && tokenInfo.length() >= 20) {
|
|
|
- JSONObject tokenUser = JSON.parseObject(tokenInfo);
|
|
|
- String tokenPw = tokenUser.getString("password");
|
|
|
+ }
|
|
|
|
|
|
- String tokenAccount = tokenUser.getString("account");
|
|
|
+ @PostMapping("/loginByToken2")
|
|
|
+ @ApiOperationSupport(order = 20)
|
|
|
+ @ApiOperation(value = "token验证加密", notes = "token验证登录")
|
|
|
+ public R loginByToken2(String account) {
|
|
|
+ if (StringUtil.isBlank(account)) {
|
|
|
+ return R.fail("请输出token");
|
|
|
+ }
|
|
|
|
|
|
- String tokenTimestamp = tokenUser.getString("timestamp");
|
|
|
- if (!account.equals(account)) {
|
|
|
- return R.fail("token解析用户和account不一致");
|
|
|
- }
|
|
|
+ if (account != null) {
|
|
|
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("account", tokenAccount);
|
|
|
+ queryWrapper.eq("account", account);
|
|
|
// queryWrapper.eq("password", tokenPw);
|
|
|
queryWrapper.eq("sys_type", 2);
|
|
|
User userInfo = userService.getOne(queryWrapper);
|
|
|
if (userInfo == null) {
|
|
|
return R.fail("用户名或密码错误");
|
|
|
}
|
|
|
- //获取用户list
|
|
|
+ String tenId =userInfo.getTenantId();
|
|
|
+ String pass = userInfo.getPlaintextPassword();
|
|
|
+ String md5Pass =MD5Utils.md5Hex(pass,"UTF-8");
|
|
|
+ System.out.println("密码"+ md5Pass);
|
|
|
+
|
|
|
HttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
- HttpPost httpPost = new HttpPost("http://172.31.222.127:8090/blade-auth/oauth/token");
|
|
|
- httpPost.setHeader("Authorization", "Basic Y2xpZW50OmNsaWVudF9zZWNyZXQ="); //这个需要 client:
|
|
|
+ HttpPost httpPost = new HttpPost("http://47.110.251.215:8090/blade-auth/oauth/token");
|
|
|
+ httpPost.setHeader("Authorization", "Basic YXJjaGl2ZXM6YXJjaGl2ZXNfc2VjcmV0");
|
|
|
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
|
httpPost.setHeader("Tenant-Id", "000000");
|
|
|
List<NameValuePair> params = new ArrayList<NameValuePair>();
|
|
|
params.add(new BasicNameValuePair("grant_type", "password"));
|
|
|
- params.add(new BasicNameValuePair("username", userInfo.getAccount()));
|
|
|
- params.add(new BasicNameValuePair("password", "e10adc3949ba59abbe56e057f20f883e"));
|
|
|
+ params.add(new BasicNameValuePair("username", account));
|
|
|
+ params.add(new BasicNameValuePair("password", md5Pass));
|
|
|
params.add(new BasicNameValuePair("scope", "all"));
|
|
|
params.add(new BasicNameValuePair("tenantId", "000000"));
|
|
|
httpPost.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8));
|
|
|
-
|
|
|
try {
|
|
|
HttpResponse httpResponse = httpClient.execute(httpPost);
|
|
|
InputStream inputStream = httpResponse.getEntity().getContent();
|
|
@@ -484,15 +509,15 @@ public class UserController {
|
|
|
while ((index = inputStream.read(buffer)) != -1) {
|
|
|
outputStream.write(buffer, 0, index);
|
|
|
}
|
|
|
- System.out.println(JSON.parseObject(outputStream.toString()));
|
|
|
+ System.out.println("\n");
|
|
|
return R.data(JSON.parseObject(outputStream.toString()));
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
- return R.success("操作失败");
|
|
|
}
|
|
|
} else {
|
|
|
- return R.fail("请确认token是否有误");
|
|
|
+ return R.fail("请确认account是否有误");
|
|
|
}
|
|
|
+ return R.fail("");
|
|
|
}
|
|
|
|
|
|
/**
|