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

View File

@ -149,6 +149,14 @@ public class SysUser extends BaseEntity {
@Getter
private IpLocation location;
// 群晖用户名
private String synoUserName;
// 群晖密码
private String synoPassword;
// 群晖token
private String synoToken;
public SysUser() {
@ -347,6 +355,26 @@ public class SysUser extends BaseEntity {
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() {
return synoToken;
}