package com.dxhy.auth.util.user;

import javax.annotation.Resource;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import com.dxhy.admin.sys.config.AdminConfig;
import com.dxhy.auth.config.KeyConfiguration;
import com.dxhy.common.jwt.IJWTInfo;
import com.dxhy.common.jwt.JWTHelper;

import lombok.extern.slf4j.Slf4j;

/**
 *
 * @author jiaohongyang
 * @date 2017/9/10
 */
@Component
@Slf4j
public class JwtTokenUtil {

    @Resource
    private KeyConfiguration keyConfiguration;

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    public String generateToken(IJWTInfo jwtInfo) throws Exception {
        return JWTHelper.generateToken(jwtInfo, keyConfiguration.getUserPriKey(), AdminConfig.expire);
    }

    public IJWTInfo getInfoFromToken(String token) throws Exception {
        return JWTHelper.getInfoFromToken(token, keyConfiguration.getUserPubKey());
    }

}
