< prev index next >
jaxws/src/jdk.xml.bind/share/classes/com/sun/istack/internal/tools/DefaultAuthenticator.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 31,49 ****
--- 31,52 ----
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
+ import java.lang.reflect.Method;
import java.net.Authenticator;
import java.net.Authenticator.RequestorType;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.AccessController;
import java.security.PrivilegedAction;
+ import java.security.PrivilegedActionException;
+ import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
*** 54,68 ****
* @author Vivek Pandey
* @author Lukas Jungmann
*/
public class DefaultAuthenticator extends Authenticator {
private static DefaultAuthenticator instance;
private static Authenticator systemAuthenticator = getCurrentAuthenticator();
private String proxyUser;
private String proxyPasswd;
! private final List<AuthInfo> authInfo = new ArrayList<AuthInfo>();
private static int counter = 0;
DefaultAuthenticator() {
//try undocumented but often used properties
if (System.getProperty("http.proxyUser") != null) {
--- 57,72 ----
* @author Vivek Pandey
* @author Lukas Jungmann
*/
public class DefaultAuthenticator extends Authenticator {
+ private static final Logger LOGGER = Logger.getLogger(DefaultAuthenticator.class.getName());
private static DefaultAuthenticator instance;
private static Authenticator systemAuthenticator = getCurrentAuthenticator();
private String proxyUser;
private String proxyPasswd;
! private final List<AuthInfo> authInfo = new ArrayList<>();
private static int counter = 0;
DefaultAuthenticator() {
//try undocumented but often used properties
if (System.getProperty("http.proxyUser") != null) {
*** 143,156 ****
locator.setSystemId(f.getAbsolutePath());
try {
fi = new FileInputStream(f);
is = new InputStreamReader(fi, "UTF-8");
in = new BufferedReader(is);
! } catch (UnsupportedEncodingException e) {
! listener.onError(e, locator);
! return;
! } catch (FileNotFoundException e) {
listener.onError(e, locator);
return;
}
try {
int lineno = 1;
--- 147,157 ----
locator.setSystemId(f.getAbsolutePath());
try {
fi = new FileInputStream(f);
is = new InputStreamReader(fi, "UTF-8");
in = new BufferedReader(is);
! } catch (UnsupportedEncodingException | FileNotFoundException e) {
listener.onError(e, locator);
return;
}
try {
int lineno = 1;
*** 168,178 ****
listener.onParsingError(text, locator);
}
}
} catch (IOException e) {
listener.onError(e, locator);
! Logger.getLogger(DefaultAuthenticator.class.getName()).log(Level.SEVERE, e.getMessage(), e);
}
} finally {
try {
if (in != null) {
in.close();
--- 169,179 ----
listener.onParsingError(text, locator);
}
}
} catch (IOException e) {
listener.onError(e, locator);
! LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
} finally {
try {
if (in != null) {
in.close();
*** 182,192 ****
}
if (fi != null) {
fi.close();
}
} catch (IOException ex) {
! Logger.getLogger(DefaultAuthenticator.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private AuthInfo parseLine(String text) throws Exception {
--- 183,193 ----
}
if (fi != null) {
fi.close();
}
} catch (IOException ex) {
! LOGGER.log(Level.SEVERE, null, ex);
}
}
}
private AuthInfo parseLine(String text) throws Exception {
*** 223,232 ****
--- 224,256 ----
}
throw new Exception();
}
static Authenticator getCurrentAuthenticator() {
+ try {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Authenticator>() {
+ @Override
+ public Authenticator run() throws Exception {
+ Method method = Authenticator.class.getMethod("getDefault");
+ return (Authenticator) method.invoke(null);
+ }
+
+ });
+ } catch (PrivilegedActionException pae) {
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.log(Level.FINE, null, pae);
+ }
+ Exception ex = pae.getException();
+ if (!(ex instanceof NoSuchMethodException)) {
+ // if Authenticator.getDefault has not been found,
+ // we likely didn't get through sec, so return null
+ // and don't care about JDK version we're on
+ return null;
+ }
+ // or we're on JDK <9, so let's continue the old way...
+ }
+
final Field f = getTheAuthenticator();
if (f == null) {
return null;
}
*** 237,247 ****
f.setAccessible(true);
return null;
}
});
return (Authenticator) f.get(null);
! } catch (Exception ex) {
return null;
} finally {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
--- 261,271 ----
f.setAccessible(true);
return null;
}
});
return (Authenticator) f.get(null);
! } catch (IllegalAccessException | IllegalArgumentException ex) {
return null;
} finally {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
*** 253,263 ****
}
private static Field getTheAuthenticator() {
try {
return Authenticator.class.getDeclaredField("theAuthenticator");
! } catch (Exception ex) {
return null;
}
}
public static interface Receiver {
--- 277,287 ----
}
private static Field getTheAuthenticator() {
try {
return Authenticator.class.getDeclaredField("theAuthenticator");
! } catch (NoSuchFieldException | SecurityException ex) {
return null;
}
}
public static interface Receiver {
*** 275,285 ****
}
@Override
public void onError(Exception e, Locator loc) {
System.err.println(getLocationString(loc) + ": " + e.getMessage());
! Logger.getLogger(DefaultAuthenticator.class.getName()).log(Level.SEVERE, e.getMessage(), e);
}
private String getLocationString(Locator l) {
return "[" + l.getSystemId() + "#" + l.getLineNumber() + "]";
}
--- 299,309 ----
}
@Override
public void onError(Exception e, Locator loc) {
System.err.println(getLocationString(loc) + ": " + e.getMessage());
! LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
private String getLocationString(Locator l) {
return "[" + l.getSystemId() + "#" + l.getLineNumber() + "]";
}
< prev index next >