feat: NAS登录
This commit is contained in:
parent
aae8851a86
commit
cc3f07fbf1
@ -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,14 +111,15 @@ 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);
|
||||||
|
try {
|
||||||
// get请求获取群晖token
|
// get请求获取群晖token
|
||||||
// 使用UriComponentsBuilder构建带有查询参数的URL
|
// 使用UriComponentsBuilder构建带有查询参数的URL
|
||||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(DSM_LOGIN_URL)
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(DSM_LOGIN_URL)
|
||||||
.queryParam("api", "SYNO.API.Auth")
|
.queryParam("api", "SYNO.API.Auth")
|
||||||
.queryParam("version", "3")
|
.queryParam("version", "6")
|
||||||
.queryParam("method", "login")
|
.queryParam("method", "login")
|
||||||
.queryParam("account", "peihaoyu")
|
.queryParam("account", user.getSynoUserName())
|
||||||
.queryParam("passwd", "Phy0316.")
|
.queryParam("passwd", user.getSynoPassword())
|
||||||
.queryParam("enable_syno_token", "yes");
|
.queryParam("enable_syno_token", "yes");
|
||||||
// 构建完整的URL
|
// 构建完整的URL
|
||||||
String url = builder.toUriString();
|
String url = builder.toUriString();
|
||||||
@ -129,6 +131,9 @@ public class SysLoginController {
|
|||||||
if (jsonObject.get("success").equals(true)) {
|
if (jsonObject.get("success").equals(true)) {
|
||||||
user.setSynoToken(jsonObject.getJSONObject("data").getString("synotoken"));
|
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);
|
||||||
ajax.put("roles", roles);
|
ajax.put("roles", roles);
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user