/*
 *  Copyright 2016 http://www.hswebframework.org
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  
 *
 */
package org.hswebframework.web.authorization.oauth2.client;

import com.alibaba.fastjson.annotation.JSONField;

import java.io.Serializable;

/**
 * 默认的服务实现
 *
 * @author zhouhao
 */
public class AccessTokenInfo implements Serializable {
    private String id;
    //授权码
    @JSONField(name = "access_token")
    private String accessToken;
    //更新码
    @JSONField(name = "refresh_token")
    private String refreshToken;
    //有效期
    @JSONField(name = "expires_in")
    private Integer expiresIn;
    //授权范围
    private String scope;

    private Long createTime;

    private Long updateTime;

    @JSONField(name = "token_type")
    private String tokenType;

    private String grantType;

    private String serverId;

    public boolean isExpire() {
        if (expiresIn == null) {
            return true;
        }
        long time = updateTime==null?createTime:updateTime;

        return System.currentTimeMillis() - time > expiresIn * 1000;
    }

    public String getTokenType() {
        return tokenType;
    }

    public void setTokenType(String tokenType) {
        this.tokenType = tokenType;
    }

    /**
     * @return 授权码
     */
    public String getAccessToken() {
        return this.accessToken;
    }

    /**
     * 设置 授权码
     */
    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    /**
     * @return 更新码
     */
    public String getRefreshToken() {
        return this.refreshToken;
    }

    /**
     * 设置 更新码
     */
    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    /**
     * @return 有效期
     */
    public Integer getExpiresIn() {
        return this.expiresIn;
    }

    /**
     * 设置 有效期
     */
    public void setExpiresIn(Integer expiresIn) {
        this.expiresIn = expiresIn;
    }

    /**
     * @return 授权范围
     */
    public String getScope() {
        return this.scope;
    }

    /**
     * 设置 授权范围
     */
    public void setScope(String scope) {
        this.scope = scope;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public Long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Long updateTime) {
        this.updateTime = updateTime;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setGrantType(String grantType) {
        this.grantType = grantType;
    }

    public String getGrantType() {
        return grantType;
    }

    public String getServerId() {
        return serverId;
    }

    public void setServerId(String serverId) {
        this.serverId = serverId;
    }
}

@@ -740,16 +740,33 @@
 ONField;
+%0Aimport lombok.*;
 %0A%0Aimport
@@ -834,62 +834,198 @@
  */%0A
-public class AccessTokenInfo implements Serializable %7B
+@Getter%0A@Setter%0A@Builder%0A@NoArgsConstructor%0A@AllArgsConstructor%0Apublic class AccessTokenInfo implements Serializable %7B%0A    private static final long serialVersionUID = -6261971233479574076L;
 %0A   
@@ -1910,1691 +1910,6 @@
  %7D%0A%0A
-    /**%0A     * @return %E6%8E%88%E6%9D%83%E7%A0%81%0A     */%0A    public String getAccessToken() %7B%0A        return this.accessToken;%0A    %7D%0A%0A    /**%0A     * %E8%AE%BE%E7%BD%AE %E6%8E%88%E6%9D%83%E7%A0%81%0A     */%0A    public void setAccessToken(String accessToken) %7B%0A        this.accessToken = accessToken;%0A    %7D%0A%0A    /**%0A     * @return %E6%9B%B4%E6%96%B0%E7%A0%81%0A     */%0A    public String getRefreshToken() %7B%0A        return this.refreshToken;%0A    %7D%0A%0A    /**%0A     * %E8%AE%BE%E7%BD%AE %E6%9B%B4%E6%96%B0%E7%A0%81%0A     */%0A    public void setRefreshToken(String refreshToken) %7B%0A        this.refreshToken = refreshToken;%0A    %7D%0A%0A    /**%0A     * @return %E6%9C%89%E6%95%88%E6%9C%9F%0A     */%0A    public Integer getExpiresIn() %7B%0A        return this.expiresIn;%0A    %7D%0A%0A    /**%0A     * %E8%AE%BE%E7%BD%AE %E6%9C%89%E6%95%88%E6%9C%9F%0A     */%0A    public void setExpiresIn(Integer expiresIn) %7B%0A        this.expiresIn = expiresIn;%0A    %7D%0A%0A    /**%0A     * @return %E6%8E%88%E6%9D%83%E8%8C%83%E5%9B%B4%0A     */%0A    public String getScope() %7B%0A        return this.scope;%0A    %7D%0A%0A    /**%0A     * %E8%AE%BE%E7%BD%AE %E6%8E%88%E6%9D%83%E8%8C%83%E5%9B%B4%0A     */%0A    public void setScope(String scope) %7B%0A        this.scope = scope;%0A    %7D%0A%0A    public Long getCreateTime() %7B%0A        return createTime;%0A    %7D%0A%0A    public void setCreateTime(Long createTime) %7B%0A        this.createTime = createTime;%0A    %7D%0A%0A    public Long getUpdateTime() %7B%0A        return updateTime;%0A    %7D%0A%0A    public void setUpdateTime(Long updateTime) %7B%0A        this.updateTime = updateTime;%0A    %7D%0A%0A    public void setId(String id) %7B%0A        this.id = id;%0A    %7D%0A%0A    public String getId() %7B%0A        return id;%0A    %7D%0A%0A    public void setGrantType(String grantType) %7B%0A        this.grantType = grantType;%0A    %7D%0A%0A    public String getGrantType() %7B%0A        return grantType;%0A    %7D%0A%0A    public String getServerId() %7B%0A        return serverId;%0A    %7D%0A%0A    public void setServerId(String serverId) %7B%0A        this.serverId = serverId;%0A    %7D%0A
 %7D%0A

add lombok