feat: 群晖token
This commit is contained in:
parent
e26eee87d0
commit
868d1f136a
@ -17,9 +17,17 @@ import com.pnkx.framework.web.service.TokenService;
|
||||
import com.pnkx.service.IPxLikeRecordService;
|
||||
import com.pnkx.system.service.ISysMenuService;
|
||||
import com.pnkx.system.service.ISysUserService;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@ -37,6 +45,8 @@ public class SysLoginController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SysLoginController.class);
|
||||
|
||||
private static final String DSM_LOGIN_URL = "http://192.168.31.104:5000/webapi/auth.cgi";
|
||||
|
||||
@Resource
|
||||
private SysLoginService loginService;
|
||||
@Resource
|
||||
@ -50,7 +60,6 @@ public class SysLoginController {
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
|
||||
|
||||
/**
|
||||
* 登录方法
|
||||
*
|
||||
@ -106,6 +115,25 @@ 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"));
|
||||
}
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("user", user);
|
||||
ajax.put("roles", roles);
|
||||
|
@ -149,6 +149,8 @@ public class SysUser extends BaseEntity {
|
||||
@Getter
|
||||
private IpLocation location;
|
||||
|
||||
private String SynoToken;
|
||||
|
||||
public SysUser() {
|
||||
|
||||
}
|
||||
@ -345,6 +347,14 @@ public class SysUser extends BaseEntity {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getSynoToken() {
|
||||
return SynoToken;
|
||||
}
|
||||
|
||||
public void setSynoToken(String synoToken) {
|
||||
SynoToken = synoToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysUser{" +
|
||||
|
@ -1,15 +1,8 @@
|
||||
package com.pnkx.common.utils.ip;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.pnkx.common.utils.StringUtils;
|
||||
import com.pnkx.common.utils.html.EscapeUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.lionsoul.ip2region.xdb.Searcher;
|
||||
@ -17,6 +10,12 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.math.BigDecimal.ZERO;
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user