package com.uas.sso;

import javax.servlet.http.HttpServletRequest;

import com.alibaba.fastjson.annotation.JSONField;
import com.uas.sso.common.IpHelper;

/**
 * <p>
 * SSO登录标记Cookie基本信息对象
 * </p>
 * 
 */
public class SSOToken extends Token {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/* 登录类型 */
	private Integer type;

	/* 预留 */
	private String data;

	/**
	 * <p>
	 * 预留对象，默认 fastjson 不参与序列化（也就是不存放在 cookie 中 ）
	 * </p>
	 * <p>
	 * 此处配合分布式缓存使用，可以存放用户常用基本信息
	 * </p>
	 */
	@JSONField(serialize = false)
	private Object object;

	public SSOToken() {
		this.setApp(SSOConfig.getInstance().getAppName());
	}

	public SSOToken(HttpServletRequest request) {
		this.setIp(IpHelper.getIpAddr(request));
		this.setApp(SSOConfig.getInstance().getAppName());
	}

	public SSOToken(HttpServletRequest request, String uid) {
		this(request);
		this.setUid(uid);
	}

	public SSOToken(HttpServletRequest request, String uid, Integer type) {
		this(request, uid);
		this.setType(type);
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}

	/**
	 * 缓存用户信息，自动类型转换
	 */
	@SuppressWarnings("unchecked")
	public <T> T getCacheObject() {
		return (T) this.getObject();
	}

	public Object getObject() {
		return object;
	}

	public void setObject(Object object) {
		this.object = object;
	}
}
