public CXFAuthenticator() {
}
public static synchronized void addAuthenticator() {
if (!setup) {
Authenticator wrapped = null;
for (final Field f : Authenticator.class.getDeclaredFields()) {
if (f.getType().equals(Authenticator.class)) {
ReflectionUtil.setAccessible(f);
try {
wrapped = (Authenticator)f.get(null);
} catch (Exception e) {
//ignore
}
}
}
try {
InputStream ins = ReferencingAuthenticator.class.getResourceAsStream("ReferencingAuthenticator.class");
final byte b[] = IOUtils.readBytesFromStream(ins);
ClassLoader loader = new URLClassLoader(new URL[0], ClassLoader.getSystemClassLoader());
Method m = ClassLoader.class.getDeclaredMethod("defineClass", String.class,
byte[].class, Integer.TYPE, Integer.TYPE);
ReflectionUtil.setAccessible(m).invoke(loader, ReferencingAuthenticator.class.getName(),
b, 0, b.length);
Class<?> cls = loader.loadClass(ReferencingAuthenticator.class.getName());
Authenticator auth = (Authenticator)cls.getConstructor(Authenticator.class, Authenticator.class)
.newInstance(INSTANCE, wrapped);
Authenticator.setDefault(auth);
} catch (Throwable t) {
//ignore