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

com.identityx.auth.util.CertValidationResultCache Maven / Gradle / Ivy

Go to download

Client library used for adding authentication to http messages as required by IdentityX Rest Services

There is a newer version: 5.6.0.2
Show newest version
package com.identityx.auth.util;

import java.util.Date;
import java.util.HashMap;


public class CertValidationResultCache {
	
	private static HashMap singleton = new HashMap();
	private Date passedTime = null;
	private int expiryTimeSec = 60 * 60 * 12;
	
	public int getExpiryTimeSec() {
		return expiryTimeSec;
	}

	public synchronized void setExpiryTimeSec(int expiryTimeSec) {
		this.expiryTimeSec = expiryTimeSec;
	}

	protected CertValidationResultCache() {
	}
	
	public static CertValidationResultCache getInstance(String key) {
	    if(!singleton.containsKey(key)) {
	    	synchronized(CertValidationResultCache.class) {
	    		singleton.put(key, new CertValidationResultCache());
	    	}
	    }
	    return singleton.get(key);
	}
	
	public synchronized void markPassedValidation() {
		passedTime = new Date();
	}
	
	public synchronized void resetCache() {
		passedTime = null;
	}
	
	public synchronized boolean isCached() {
		if (passedTime == null) return false;
		Date now = new Date();		
		if (now.getTime() - passedTime.getTime() < expiryTimeSec * 1000) {
			return true;
		}
		else {
			passedTime = null;
			return false;
		}
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy