|
@@ -1,6 +1,9 @@
|
|
|
package com.zd.alg.forward.serivce;
|
|
package com.zd.alg.forward.serivce;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.zd.alg.forward.config.AlgorithmYml;
|
|
import com.zd.alg.forward.config.AlgorithmYml;
|
|
|
|
|
+import com.zd.auth.feign.RemoteAuthService;
|
|
|
|
|
+import com.zd.auth.form.LoginBody;
|
|
|
import com.zd.common.core.exception.ServiceException;
|
|
import com.zd.common.core.exception.ServiceException;
|
|
|
import com.zd.common.core.security.TokenService;
|
|
import com.zd.common.core.security.TokenService;
|
|
|
import com.zd.model.constant.SecurityConstants;
|
|
import com.zd.model.constant.SecurityConstants;
|
|
@@ -18,6 +21,7 @@ import org.springframework.util.Assert;
|
|
|
import org.springframework.web.client.RestClientException;
|
|
import org.springframework.web.client.RestClientException;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
@@ -32,6 +36,9 @@ public class LoginService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
TokenService tokenService;
|
|
TokenService tokenService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private RemoteAuthService remoteAuthService;
|
|
|
|
|
+
|
|
|
private String token;
|
|
private String token;
|
|
|
|
|
|
|
|
public String getToken() {
|
|
public String getToken() {
|
|
@@ -48,22 +55,14 @@ public class LoginService {
|
|
|
*/
|
|
*/
|
|
|
public void loginLab() {
|
|
public void loginLab() {
|
|
|
//不再重复登录
|
|
//不再重复登录
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
- //创建请求头
|
|
|
|
|
- String url = algorithmYml.getLoginUri() + "auth/one/login";
|
|
|
|
|
- Map<String, String> map = new HashMap<>(2);
|
|
|
|
|
- map.put("username", "admin");
|
|
|
|
|
- map.put("password", "zd123456..");
|
|
|
|
|
- ParameterizedTypeReference<R<Map<String, Object>>> reference = new ParameterizedTypeReference<R<Map<String, Object>>>(){};
|
|
|
|
|
|
|
+ LoginBody body=new LoginBody();
|
|
|
|
|
+ body.setUsername("admin");
|
|
|
|
|
+ body.setPassword("zd123456..");
|
|
|
try {
|
|
try {
|
|
|
- ResponseEntity<R<Map<String, Object>>> response = restTemplate.exchange(url, HttpMethod.POST, new HttpEntity<>(map), reference);
|
|
|
|
|
- R<Map<String, Object>> parse = response.getBody();
|
|
|
|
|
- if (parse != null) {
|
|
|
|
|
- Assert.isTrue(parse.getCode() == R.SUCCESS, "登录失败:" + parse.getMsg());
|
|
|
|
|
- //拿到token
|
|
|
|
|
- Map<String, Object> data = parse.getData();
|
|
|
|
|
- setToken("Bearer " + data.get("access_token"));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ R<?> r = remoteAuthService.oneLogin(body);
|
|
|
|
|
+ Assert.isTrue(r.getCode() == R.SUCCESS, "登录失败:" + r.getMsg());
|
|
|
|
|
+ Map<String, Object> data = (Map<String, Object>) r.getData();
|
|
|
|
|
+ setToken("Bearer " + data.get("access_token"));
|
|
|
} catch (RestClientException e) {
|
|
} catch (RestClientException e) {
|
|
|
throw new ServiceException(e.getMessage());
|
|
throw new ServiceException(e.getMessage());
|
|
|
}
|
|
}
|