|
@@ -1,18 +1,16 @@
|
|
|
package cn.org.bjca.trust.java.imserver.controller.user.v1;
|
|
|
|
|
|
import cn.org.bjca.trust.java.imserver.HttpResult;
|
|
|
+import cn.org.bjca.trust.java.imserver.common.RabbitMQHelper;
|
|
|
import cn.org.bjca.trust.java.imserver.entitys.UserInfo;
|
|
|
+import cn.org.bjca.trust.java.imserver.entitys.sys.ApplicationEntity;
|
|
|
import cn.org.bjca.trust.java.imserver.repository.UserRepository;
|
|
|
+import cn.org.bjca.trust.java.imserver.repository.tenant.ApplicationRepository;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.io.OutputStream;
|
|
|
-import java.net.HttpURLConnection;
|
|
|
-import java.net.URL;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
@RestController
|
|
@@ -23,14 +21,19 @@ public class UserV1Controller {
|
|
|
private HttpServletRequest request;
|
|
|
@Autowired
|
|
|
private UserRepository userRepository;
|
|
|
+ @Autowired
|
|
|
+ private ApplicationRepository applicationRepository;
|
|
|
|
|
|
@PostMapping("/login")
|
|
|
- public HttpResult<LoginData> getById(@RequestBody LoginBean user, @RequestHeader HttpHeaders headers) throws Exception {
|
|
|
+ public HttpResult<LoginData> login(@RequestBody LoginBean user, @RequestHeader HttpHeaders headers) throws Exception {
|
|
|
String appid = headers.getFirst("appid");
|
|
|
String userid = headers.getFirst("userid");
|
|
|
String ostype = headers.getFirst("ostype");
|
|
|
- requestByGetAndParams("http://114.115.203.60:15672/api/vhosts/"+appid, "");
|
|
|
if (null != appid && null != userid && null != ostype) {
|
|
|
+
|
|
|
+ ApplicationEntity app = applicationRepository.findFirstByAppId(appid);
|
|
|
+ if (null == app) return new HttpResult<>(201, "appId不存在", new LoginData());
|
|
|
+
|
|
|
UserInfo userInfo = userRepository.findUserInfoByUserIdAndOsTypeAndAppId(userid, ostype, appid);
|
|
|
if (null == userInfo) {
|
|
|
System.out.println("-----------------用户不存在------------------");
|
|
@@ -42,10 +45,10 @@ public class UserV1Controller {
|
|
|
userInfo.setPassword(UUID.randomUUID().toString());
|
|
|
userRepository.save(userInfo);
|
|
|
|
|
|
- requestByGetAndParams("http://114.115.203.60:15672/api/users/" + userInfo.getUserName(), "{\"username\":\"" + userInfo.getUserName() + "\",\"password\":\"" + userInfo.getPassword() + "\",\"tags\":\"\"}");
|
|
|
- requestByGetAndParams("http://114.115.203.60:15672/api/permissions/%2F/" + userInfo.getUserName(), "{\"username\":\"" + userInfo.getUserName() + "\",\"vhost\":\"" + appid + "\",\"configure\":\".*\",\"write\":\".*\",\"read\":\".*\"}");
|
|
|
- requestByGetAndParams("http://114.115.203.60:15672/api/permissions/" + appid + "/" + userInfo.getUserName(), "{\"username\":\"" + userInfo.getUserName() + "\",\"vhost\":\"" + appid + "\",\"configure\":\".*\",\"write\":\".*\",\"read\":\".*\"}");
|
|
|
- requestByGetAndParams("http://114.115.203.60:15672/api/topic-permissions/" + appid + "/" + userInfo.getUserName(), "{\"username\":\"" + userInfo.getUserName() + "\",\"vhost\":\"" + appid + "\",\"exchange\":\"\",\"write\":\".*\",\"read\":\".*\"}");
|
|
|
+ RabbitMQHelper.requestByGetAndParams("http://114.115.203.60:15672/api/users/" + userInfo.getUserName(), "{\"username\":\"" + userInfo.getUserName() + "\",\"password\":\"" + userInfo.getPassword() + "\",\"tags\":\"\"}");
|
|
|
+ RabbitMQHelper.requestByGetAndParams("http://114.115.203.60:15672/api/permissions/%2F/" + userInfo.getUserName(), "{\"username\":\"" + userInfo.getUserName() + "\",\"vhost\":\"" + appid + "\",\"configure\":\".*\",\"write\":\".*\",\"read\":\".*\"}");
|
|
|
+ RabbitMQHelper.requestByGetAndParams("http://114.115.203.60:15672/api/permissions/" + appid + "/" + userInfo.getUserName(), "{\"username\":\"" + userInfo.getUserName() + "\",\"vhost\":\"" + appid + "\",\"configure\":\".*\",\"write\":\".*\",\"read\":\".*\"}");
|
|
|
+ RabbitMQHelper.requestByGetAndParams("http://114.115.203.60:15672/api/topic-permissions/" + appid + "/" + userInfo.getUserName(), "{\"username\":\"" + userInfo.getUserName() + "\",\"vhost\":\"" + appid + "\",\"exchange\":\"\",\"write\":\".*\",\"read\":\".*\"}");
|
|
|
|
|
|
}
|
|
|
|
|
@@ -56,28 +59,4 @@ public class UserV1Controller {
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void requestByGetAndParams(String requestUrl, String param) throws Exception {
|
|
|
- System.out.println(requestUrl + ":\n" + param);
|
|
|
- URL url = new URL(requestUrl);
|
|
|
- HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
|
|
- //设置请求方式,请求参数类型
|
|
|
- httpURLConnection.setRequestMethod("PUT");
|
|
|
- httpURLConnection.setRequestProperty("content-type", "application/json;charset=UTF-8");
|
|
|
- httpURLConnection.setRequestProperty("Authorization", "Basic YWRtaW46YWRtaW4=");
|
|
|
- httpURLConnection.setDoOutput(true);
|
|
|
- OutputStream outputStream = httpURLConnection.getOutputStream();
|
|
|
- //将参数写入输出流,param必须是JSON格式
|
|
|
- outputStream.write(param.getBytes());
|
|
|
- outputStream.flush();
|
|
|
- InputStream inputStream = httpURLConnection.getInputStream();
|
|
|
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
|
|
- byte[] bytes = new byte[1024];
|
|
|
- int len = 0;
|
|
|
- while ((len = inputStream.read(bytes)) >= 0) {
|
|
|
- bout.write(bytes, 0, len);
|
|
|
- }
|
|
|
- inputStream.close();
|
|
|
- bout.close();
|
|
|
- bout.toByteArray();
|
|
|
- }
|
|
|
}
|