feat: NAS登录

This commit is contained in:
裴浩宇 2024-05-28 09:06:02 +08:00
parent aae8851a86
commit cc3f07fbf1
2 changed files with 51 additions and 18 deletions

View File

@ -21,6 +21,7 @@ import net.sf.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
@ -110,24 +111,28 @@ public class SysLoginController {
Set<String> roles = permissionService.getRolePermission(user); Set<String> roles = permissionService.getRolePermission(user);
// 权限集合 // 权限集合
Set<String> permissions = permissionService.getMenuPermission(user); Set<String> permissions = permissionService.getMenuPermission(user);
// get请求获取群晖token try {
// 使用UriComponentsBuilder构建带有查询参数的URL // get请求获取群晖token
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(DSM_LOGIN_URL) // 使用UriComponentsBuilder构建带有查询参数的URL
.queryParam("api", "SYNO.API.Auth") UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(DSM_LOGIN_URL)
.queryParam("version", "3") .queryParam("api", "SYNO.API.Auth")
.queryParam("method", "login") .queryParam("version", "6")
.queryParam("account", "peihaoyu") .queryParam("method", "login")
.queryParam("passwd", "Phy0316.") .queryParam("account", user.getSynoUserName())
.queryParam("enable_syno_token", "yes"); .queryParam("passwd", user.getSynoPassword())
// 构建完整的URL .queryParam("enable_syno_token", "yes");
String url = builder.toUriString(); // 构建完整的URL
// 发送GET请求并获取响应 String url = builder.toUriString();
RestTemplate restTemplate = new RestTemplate(); // 发送GET请求并获取响应
String result = restTemplate.getForObject(url, String.class); RestTemplate restTemplate = new RestTemplate();
logger.info("群晖token:{}", result); String result = restTemplate.getForObject(url, String.class);
JSONObject jsonObject = JSONObject.fromObject(result); logger.info("群晖token:{}", result);
if (jsonObject.get("success").equals(true)) { JSONObject jsonObject = JSONObject.fromObject(result);
user.setSynoToken(jsonObject.getJSONObject("data").getString("synotoken")); if (jsonObject.get("success").equals(true)) {
user.setSynoToken(jsonObject.getJSONObject("data").getString("synotoken"));
}
} catch (RestClientException e) {
logger.error("请求群晖token失败异常信息", e);
} }
AjaxResult ajax = AjaxResult.success(); AjaxResult ajax = AjaxResult.success();
ajax.put("user", user); ajax.put("user", user);

View File

@ -149,6 +149,14 @@ public class SysUser extends BaseEntity {
@Getter @Getter
private IpLocation location; private IpLocation location;
// 群晖用户名
private String synoUserName;
// 群晖密码
private String synoPassword;
// 群晖token
private String synoToken; private String synoToken;
public SysUser() { public SysUser() {
@ -347,6 +355,26 @@ public class SysUser extends BaseEntity {
this.location = location; this.location = location;
} }
public IpLocation getLocation() {
return location;
}
public String getSynoUserName() {
return synoUserName;
}
public void setSynoUserName(String synoUserName) {
this.synoUserName = synoUserName;
}
public String getSynoPassword() {
return synoPassword;
}
public void setSynoPassword(String synoPassword) {
this.synoPassword = synoPassword;
}
public String getSynoToken() { public String getSynoToken() {
return synoToken; return synoToken;
} }