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

com.ksyun.api.sdk.auth.Credential Maven / Gradle / Ivy

There is a newer version: 2.1.8
Show newest version
package com.ksyun.api.sdk.auth;

import java.util.Calendar;
import java.util.Date;

public class Credential {
	
    private final Date refreshDate;
	private Date expiredDate;
	private String accessKeyId;
	private String accessSecret;
	private String securityToken;

	public Credential() {
		this.refreshDate = new Date();
	} 
	
	public Credential(String keyId, String secret) {
		this.accessKeyId = keyId;
		this.accessSecret = secret;
		this.refreshDate = new Date();
	}
	
    public Credential(String keyId, String secret, String securityToken) {
        this.accessKeyId = keyId;
        this.accessSecret = secret;
        this.securityToken = securityToken;
        this.refreshDate = new Date();
    }

	public Credential(String keyId, String secret, int expiredHours) {
		this.accessKeyId = keyId;
		this.accessSecret = secret;
		this.refreshDate = new Date();
		
		setExpiredDate(expiredHours);
	}

    public Credential(String keyId, String secret, String securityToken, int expiredHours) {
        this.accessKeyId = keyId;
        this.accessSecret = secret;
        this.securityToken = securityToken;
        this.refreshDate = new Date();

        setExpiredDate(expiredHours);
    }

	private void setExpiredDate(int expiredHours) {
		if (expiredHours > 0) {
			Calendar cal = Calendar.getInstance();   
	        cal.setTime(new Date());   
	        cal.add(Calendar.HOUR, expiredHours);
	        expiredDate = cal.getTime();   
		}
	}
	
	public String getAccessKeyId() {
		return accessKeyId;
	}
	
	public void setAccessKeyId(String accessKeyId) {
		this.accessKeyId = accessKeyId;
	}
	
	public String getAccessSecret() {
		return accessSecret;
	}
	
	public void setAccessSecret(String accessSecret) {
		this.accessSecret = accessSecret;
	}
	
	public boolean isExpired() {
		if (this.expiredDate == null){
			return false;
		}
		if (this.expiredDate.after(new Date())){
			return false;
		}
		return true;
	}
	
	public String getSecurityToken() {
		return securityToken;
	}

	public void setSecurityToken(String securityToken) {
		this.securityToken = securityToken;
	}

	public Date getRefreshDate() {
		return refreshDate;
	}

	public Date getExpiredDate() {
		return expiredDate;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy