com.utils.ThreadLocalAuthenticator Maven / Gradle / Ivy
The newest version!
package com.utils;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
public class ThreadLocalAuthenticator extends Authenticator {
private final static ThreadLocal userThreadLocal = new ThreadLocal() {
@Override
protected synchronized String initialValue() {
return "";
}
};
private final static ThreadLocal passwordThreadLocal = new ThreadLocal() {
@Override
protected synchronized String initialValue() {
return "";
}
};
public static ThreadLocal getUserthreadlocal() {
return userThreadLocal;
}
public static ThreadLocal getPasswordthreadlocal() {
return passwordThreadLocal;
}
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userThreadLocal.get(), passwordThreadLocal.get().toCharArray());
}
}