Helius
2020-05-14 7c31b75ddb67608b0a86ce2317608f275d44a872
src/main/java/com/xcong/excoin/common/system/controller/LoginController.java
@@ -1,11 +1,15 @@
package com.xcong.excoin.common.system.controller;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.common.contants.AppContants;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.common.system.bean.LoginUserBean;
import com.xcong.excoin.common.system.dto.LoginDto;
import com.xcong.excoin.configurations.properties.ApplicationProperties;
import com.xcong.excoin.configurations.properties.SecurityProperties;
import com.xcong.excoin.utils.RedisUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
@@ -32,8 +36,11 @@
@RequestMapping(value = "/")
public class LoginController {
    @Value("${rsa.private_key}")
    private String privateKey;
    @Resource
    private ApplicationProperties applicationProperties;
    @Resource
    private SecurityProperties securityProperties;
    @Resource
    private AuthenticationManagerBuilder authenticationManagerBuilder;
@@ -48,12 +55,20 @@
        String token = IdUtil.simpleUUID();
        LoginUserBean loginUserBean = (LoginUserBean) authentication.getPrincipal();
        redisUtils.set(AppContants.APP_LOGIN_PREFIX + token, JSONObject.toJSONString(loginUserBean), 300000);
        Map<String, Object> authInfo = new HashMap<String, Object>(2){
            {
                put("token", token);
                put("user", loginUserBean);
        Map<String, Object> authInfo = new HashMap<>();
        if (applicationProperties.isDebug()) {
            authInfo.put("token", token);
            authInfo.put("rsaToken", generateAsaToken(token));
            authInfo.put("user", loginUserBean);
        } else {
            authInfo.put("token", token);
            authInfo.put("user", loginUserBean);
            }
        };
        return Result.ok("success", authInfo);
    }
    public String generateAsaToken(String token) {
        RSA rsa = new RSA(null, securityProperties.getPublicKey());
        return rsa.encryptBase64(token + "_" +System.currentTimeMillis(), KeyType.PublicKey);
    }
}