|
@@ -2,17 +2,22 @@ package com.ruoyi.web.controller.system;
|
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.R;
|
|
|
+import com.ruoyi.common.core.domain.Result;
|
|
|
import com.ruoyi.system.domain.TokenRequest;
|
|
|
import com.ruoyi.web.controller.tool.RsaUtil;
|
|
|
import com.ruoyi.web.controller.tool.SecretKeyBo;
|
|
|
import com.ruoyi.web.controller.tool.StringUtils;
|
|
|
-import com.ruoyi.web.service.RedisService;
|
|
|
+import com.ruoyi.common.redis.RedisService;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
import org.apache.shiro.authc.AuthenticationException;
|
|
|
import org.apache.shiro.authc.UsernamePasswordToken;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.apache.shiro.subject.Subject;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
+import com.ruoyi.common.utils.CookieUtils;
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.Cookie;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
@@ -34,7 +39,7 @@ public class SecurityController {
|
|
|
*/
|
|
|
@PostMapping("/getRemoteSecretKey")
|
|
|
@ResponseBody
|
|
|
- public R<?> getRemoteSecretKey() {
|
|
|
+ public Result<?> getRemoteSecretKey() {
|
|
|
String publicKey;
|
|
|
try {
|
|
|
SecretKeyBo bo = RsaUtil.genKeyPair();
|
|
@@ -44,9 +49,9 @@ public class SecurityController {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(publicKey)) {
|
|
|
- return R.ok(publicKey, "操作成功");
|
|
|
+ return Result.ok(publicKey, "操作成功");
|
|
|
}
|
|
|
- return R.fail("操作失败");
|
|
|
+ return Result.fail("操作失败");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -54,31 +59,30 @@ public class SecurityController {
|
|
|
* 获取token
|
|
|
*/
|
|
|
@PostMapping("/getToken")
|
|
|
- public R<?> getToken(@RequestBody TokenRequest form) {
|
|
|
+ public Result<?> getToken(@RequestBody TokenRequest form,HttpServletRequest request) {
|
|
|
+ Result<Object> result = new Result<>();
|
|
|
//解密密码字符串
|
|
|
String privateKey = redisService.getCacheObject("remoteSecretKey");
|
|
|
try {
|
|
|
form.setPassword(RsaUtil.decrypt(form.getPassword(), privateKey));
|
|
|
} catch (Exception e) {
|
|
|
- R<Object> objectR = new R<>();
|
|
|
- objectR.setCode(40002);
|
|
|
- objectR.setMsg("获取token失败");
|
|
|
- return objectR;
|
|
|
+ result.setCode(40002);
|
|
|
+ result.setMsg("获取token失败");
|
|
|
+ return result;
|
|
|
}
|
|
|
- UsernamePasswordToken token = new UsernamePasswordToken(form.getUsername(), form.getPassword(), false);
|
|
|
-// Subject subject = SecurityUtils.getSubject();
|
|
|
+ UsernamePasswordToken token = new UsernamePasswordToken(form.getUsername(), form.getPassword(), true);
|
|
|
+ Subject subject = SecurityUtils.getSubject();
|
|
|
try {
|
|
|
-// subject.login(token);
|
|
|
- return R.ok(token);
|
|
|
+ subject.login(token);
|
|
|
+ return Result.ok(subject);
|
|
|
} catch (AuthenticationException e) {
|
|
|
String msg = "用户或密码错误";
|
|
|
if (com.ruoyi.common.utils.StringUtils.isNotEmpty(e.getMessage())) {
|
|
|
msg = e.getMessage();
|
|
|
}
|
|
|
- R<Object> objectR = new R<>();
|
|
|
- objectR.setCode(40000);
|
|
|
- objectR.setMsg(msg);
|
|
|
- return objectR;
|
|
|
+ result.setCode(40000);
|
|
|
+ result.setMsg(msg);
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|
|
|
|