package com.hclsoftware.sso.kerberos.service;

import com.ibm.as400.access.AS400;
import com.ibm.as400.security.auth.ProfileTokenCredential;
import lombok.Getter;

public class TokenManager {
    private AS400 system;
    @Getter
    private byte[] profileToken;
    private long tokenExpirationTime; // in milliseconds




    public TokenManager(String systemName) {
        this.system = new AS400(systemName);
    }

    public byte[] generateProfileToken(AS400 system, byte[] profileToken) throws Exception {
        ProfileTokenCredential tokenCredential = new ProfileTokenCredential(system, profileToken, ProfileTokenCredential.TYPE_MULTIPLE_USE_RENEWABLE, 3600);
        this.profileToken = tokenCredential.getToken();
        this.tokenExpirationTime = System.currentTimeMillis() + (3600);
        return this.profileToken;
    }

    public boolean isTokenExpired() {
        return System.currentTimeMillis() >= this.tokenExpirationTime;
    }

}

