use of java.net.Authenticator in project cxf by apache.
the class ReferencingAuthenticator method getPasswordAuthentication.
@Override
protected PasswordAuthentication getPasswordAuthentication() {
Authenticator cxfauth = auth.get();
if (cxfauth == null) {
remove();
}
PasswordAuthentication pauth = null;
if (wrapped != null) {
try {
pauth = tryWith(wrapped);
if (pauth != null) {
return pauth;
}
} catch (Exception e) {
pauth = null;
}
}
if (cxfauth != null) {
try {
pauth = tryWith(cxfauth);
} catch (Exception e1) {
pauth = null;
}
}
return pauth;
}
use of java.net.Authenticator in project cxf by apache.
the class ReferencingAuthenticator method removeInternal.
private void removeInternal() {
try {
for (final Field f : Authenticator.class.getDeclaredFields()) {
if (f.getType().equals(Authenticator.class)) {
try {
f.setAccessible(true);
Authenticator o = (Authenticator) f.get(null);
if (o == this) {
// this is at the root of any chain of authenticators
Authenticator.setDefault(wrapped);
} else {
removeFromChain(o);
}
} catch (Exception e) {
// ignore
}
}
}
} catch (Throwable t) {
// ignore
}
}
use of java.net.Authenticator in project cxf by apache.
the class ReferencingAuthenticator method check.
public final void check() {
Authenticator cxfauth = auth.get();
if (cxfauth == null) {
remove();
}
if (wrapped != null && wrapped.getClass().getName().equals(ReferencingAuthenticator.class.getName())) {
try {
Method m = wrapped.getClass().getMethod("check");
m.setAccessible(true);
m.invoke(wrapped);
} catch (Throwable t) {
// ignore
}
}
}
use of java.net.Authenticator in project cxf by apache.
the class ReferencingAuthenticator method remove.
private void remove() {
try {
// Try Authenticator.getDefault() first, JDK9+
final MethodHandle mt = MethodHandles.lookup().findStatic(Authenticator.class, "getDefault", MethodType.methodType(Authenticator.class));
removeInternal((Authenticator) mt.invoke());
} catch (final NoSuchMethodException | IllegalAccessException ex) {
removeInternal();
} catch (Throwable e) {
// ignore
}
}
use of java.net.Authenticator in project cxf by apache.
the class ReferencingAuthenticator method removeFromChain.
private void removeFromChain(Authenticator a) {
try {
if (a.getClass().getName().equals(ReferencingAuthenticator.class.getName())) {
// multiple referencing authenticators, we can remove ourself
Field f2 = a.getClass().getDeclaredField("wrapped");
f2.setAccessible(true);
Authenticator a2 = (Authenticator) f2.get(a);
if (a2 == this) {
f2.set(a, wrapped);
} else {
removeFromChain(a2);
}
}
} catch (Throwable t) {
// ignore
}
}
Aggregations