All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.dev33.satoken.temp.jwt.SaTempForJwt Maven / Gradle / Ivy

There is a newer version: 1.39.0
Show newest version
package cn.dev33.satoken.temp.jwt;

import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.exception.SaTokenException;
import cn.dev33.satoken.temp.SaTempInterface;
import cn.dev33.satoken.util.SaFoxUtil;

/**
 * Sa-Token 临时令牌验证模块接口 JWT实现类 
 * @author kong
 *
 */
public class SaTempForJwt implements SaTempInterface {
	
	/**
	 * 根据value创建一个token 
	 */
	public String createToken(Object value, long timeout) {
		String token = SaJwtUtil.createToken(value, timeout, getJwtSecretKey());
		return token;
	}
	
	/**
	 *  解析token获取value 
	 */
	public Object parseToken(String token) {
		Object value = SaJwtUtil.getValue(token, getJwtSecretKey());
		return value;
	}
	
	/**
	 * 返回指定token的剩余有效期,单位:秒 
	 */
	public long getTimeout(String token) {
		long timeout = SaJwtUtil.getTimeout(token, getJwtSecretKey());
		return timeout;
	}
	
	/**
	 * 获取jwt秘钥 
	 * @return jwt秘钥 
	 */
	public String getJwtSecretKey() {
		String jwtSecretKey = SaManager.getConfig().getJwtSecretKey();
		if(SaFoxUtil.isEmpty(jwtSecretKey)) {
			throw new SaTokenException("请配置:jwtSecretKey");
		}
		return jwtSecretKey;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy