package com.sptg.gateway.security;

import com.sptg.common.core.constant.HttpConstant;
import com.sptg.common.core.util.CookieUtils;
import com.sptg.common.core.util.JsonUtils;
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;

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

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

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

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

    @Override
    protected long getTimeOut() {
        return 60 * 60 * 4;
    }

    @Override
    protected String getTokenByRequest() {
        //  从Cookie中获取Token
        return CookieUtils.getCookieValue(HttpConstant.ACCESS_TOKEN);
    }
}
