|
@@ -5,6 +5,8 @@ import com.sooka.auth.form.RegisterBody;
|
|
|
import com.sooka.auth.service.SysLoginService;
|
|
|
import com.sooka.auth.util.RsaUtil;
|
|
|
import com.sooka.auth.util.SecretKeyBo;
|
|
|
+import com.sooka.common.core.constant.CacheConstants;
|
|
|
+import com.sooka.common.core.constant.SecurityConstants;
|
|
|
import com.sooka.common.core.domain.R;
|
|
|
import com.sooka.common.core.utils.JwtUtils;
|
|
|
import com.sooka.common.core.utils.StringUtils;
|
|
@@ -12,16 +14,15 @@ import com.sooka.common.redis.service.RedisService;
|
|
|
import com.sooka.common.security.auth.AuthUtil;
|
|
|
import com.sooka.common.security.service.TokenService;
|
|
|
import com.sooka.common.security.utils.SecurityUtils;
|
|
|
+import com.sooka.system.api.RemoteUserService;
|
|
|
import com.sooka.system.api.model.LoginUser;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
@@ -34,18 +35,39 @@ import java.util.concurrent.TimeUnit;
|
|
|
public class TokenController {
|
|
|
@Autowired
|
|
|
private TokenService tokenService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private SysLoginService sysLoginService;
|
|
|
-
|
|
|
@Resource
|
|
|
private RedisService redisService;
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取秘钥接口
|
|
|
+ * 前端请求后该方法会生成一对秘钥,分别为公钥和私钥
|
|
|
+ * 将公钥返回给前端用于加密,私钥存入缓存(60s)用于后台解密
|
|
|
+ * Pc端调用
|
|
|
+ */
|
|
|
+ @PostMapping("getRemoteSecretKey")
|
|
|
+ @ResponseBody
|
|
|
+ public R<?> getRemoteSecretKey() {
|
|
|
+ String publicKey;
|
|
|
+ try {
|
|
|
+ SecretKeyBo bo = RsaUtil.genKeyPair();
|
|
|
+ redisService.setCacheObject("remoteSecretKey", bo.getPrivateKey(), 60L, TimeUnit.SECONDS);
|
|
|
+ publicKey = bo.getPublicKey();
|
|
|
+ } catch (NoSuchAlgorithmException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(publicKey)) {
|
|
|
+ return R.ok(publicKey, "操作成功");
|
|
|
+ }
|
|
|
+ return R.fail(null,"操作失败");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取秘钥接口
|
|
|
* 前端请求后该方法会生成一对秘钥,分别为公钥和私钥
|
|
|
* 将公钥返回给前端用于加密,私钥存入缓存(60s)用于后台解密
|
|
|
- * Author 李猛
|
|
|
* Pc端调用
|
|
|
*/
|
|
|
@PostMapping("getSecretKey")
|
|
@@ -58,7 +80,6 @@ public class TokenController {
|
|
|
/**
|
|
|
* 改造获取秘钥接口
|
|
|
* App、Pc端通用
|
|
|
- * Author 李猛
|
|
|
*/
|
|
|
public R<?> getSecretKey(String sessionId) {
|
|
|
String publicKey;
|
|
@@ -125,4 +146,20 @@ public class TokenController {
|
|
|
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
|
|
|
return R.ok();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据token获取登录用户和权限等信息
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("selectLoginInfoByToken")
|
|
|
+ public R<?> selectLoginInfoByToken(HttpServletRequest request) {
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("access_token" , SecurityUtils.getToken(request));
|
|
|
+ map.put("expires_in" , CacheConstants.EXPIRATION);
|
|
|
+ LoginUser user = tokenService.getLoginUser(map.get("access_token").toString());
|
|
|
+ map.put("userinfo", user);
|
|
|
+ return R.ok(map);
|
|
|
+ }
|
|
|
+
|
|
|
}
|