package com.sptg.gateway.security;

import com.sptg.common.core.constant.HttpConstant;
import com.sptg.common.core.util.JsonUtils;
import com.sptg.common.core.util.WebUtils;
import com.sptg.common.security.service.impl.BaseRedisSecurityService;
import com.sptg.permissions.api.entity.Account;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * title: SecurityServiceImpl
 * package: com.sptg.estate.biz.service
 * description: 安全接口实现类
 *
 *               
 *                      
 */
@Service
public class SecurityServiceImpl extends BaseRedisSecurityService<Account> {

    public SecurityServiceImpl(RedisTemplate<String, String> redisTemplate) {
        super(redisTemplate);
    }

    /**
     * 获取令牌的方式--从头部获取
     *
     */
    @Override
    protected String getTokenByRequest() {
        HttpServletRequest request = WebUtils.getHttpServletRequest();
        return request.getHeader(HttpConstant.ACCESS_TOKEN);
    }

    @Override
    protected String getCacheName() {
        return "on-line:app-user:";
    }

    @Override
    protected long getTimeOut() {
        return 1800;
    }

    @Override
    protected Account jsonToPojo(String json) {
        return JsonUtils.jsonToPojo(json, Account.class);
    }
}
