[New] Added CertificateThreadLocal

This commit is contained in:
Robert von Burg 2024-03-21 14:23:04 +01:00
parent f4f9e2c798
commit 2aca456729
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
1 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,27 @@
package li.strolch.privilege.model;
public class CertificateThreadLocal extends ThreadLocal<Certificate> {
private static final CertificateThreadLocal instance = new CertificateThreadLocal();
public static boolean hasCert() {
return instance.get() != null;
}
public static Certificate getCert() {
Certificate cert = instance.get();
if (cert == null)
throw new IllegalStateException("No Cert available on thread " + Thread.currentThread().getName());
return cert;
}
public static void setCert(Certificate cert) {
if (instance.get() != null)
throw new IllegalStateException("THIS THREAD HAS ALREADY HAS A CERT!");
instance.set(cert);
}
public static void removeCert() {
instance.remove();
}
}