use of sun.net.www.protocol.http.AuthCacheImpl in project jsql-injection by ron190.
the class AuthenticationUtil method setKerberosCifs.
/**
* Initialize the utility class with preferences from the JVM
* and apply environment settings.
*/
public static void setKerberosCifs() {
// Use Preferences API to persist proxy configuration
Preferences prefs = Preferences.userRoot().node(InjectionModel.class.getName());
// Default proxy disabled
AuthenticationUtil.isAuthentication = prefs.getBoolean("isDigestAuthentication", false);
// Default TOR config
AuthenticationUtil.usernameAuthentication = prefs.get("usernameDigest", "");
AuthenticationUtil.passwordAuthentication = prefs.get("passwordDigest", "");
AuthenticationUtil.isKerberos = prefs.getBoolean("enableKerberos", false);
AuthenticationUtil.pathKerberosKrb5 = prefs.get("kerberosKrb5Conf", "");
AuthenticationUtil.pathKerberosLogin = prefs.get("kerberosLoginConf", "");
AuthCacheValue.setAuthCache(new AuthCacheImpl());
if (AuthenticationUtil.isAuthentication) {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(AuthenticationUtil.usernameAuthentication, AuthenticationUtil.passwordAuthentication.toCharArray());
}
});
}
AuthenticationUtil.setAuthentication();
}
use of sun.net.www.protocol.http.AuthCacheImpl in project jsql-injection by ron190.
the class AuthenticationUtil method set.
/**
* Get new authentication settings from the view, update the utility class,
* persist settings to the JVM and apply changes to the system.
* @param isAuthentication true if non-kerberos authent is activated
* @param usernameAuthentication login for standard authent
* @param passwordAuthentication pass for standard authent
* @param isKerberos true if krb authent is activated
* @param kerberosKrb5Conf path to the file krb5
* @param kerberosLoginConf path to the file login
*/
public static void set(boolean isAuthentication, String usernameAuthentication, String passwordAuthentication, boolean isKerberos, String kerberosKrb5Conf, String kerberosLoginConf) {
// Check if krb file has change
boolean isRestartRequired = false;
if (AuthenticationUtil.isKerberos && !new File(AuthenticationUtil.pathKerberosKrb5).exists() && !kerberosKrb5Conf.equals(AuthenticationUtil.pathKerberosKrb5)) {
isRestartRequired = true;
}
// Define proxy settings
AuthenticationUtil.isAuthentication = isAuthentication;
AuthenticationUtil.usernameAuthentication = usernameAuthentication;
AuthenticationUtil.passwordAuthentication = passwordAuthentication;
AuthenticationUtil.isKerberos = isKerberos;
AuthenticationUtil.pathKerberosKrb5 = kerberosKrb5Conf;
AuthenticationUtil.pathKerberosLogin = kerberosLoginConf;
// Persist to JVM
Preferences preferences = Preferences.userRoot().node(InjectionModel.class.getName());
preferences.putBoolean("isDigestAuthentication", AuthenticationUtil.isAuthentication);
preferences.put("usernameDigest", AuthenticationUtil.usernameAuthentication);
preferences.put("passwordDigest", AuthenticationUtil.passwordAuthentication);
preferences.putBoolean("enableKerberos", AuthenticationUtil.isKerberos);
preferences.put("kerberosKrb5Conf", AuthenticationUtil.pathKerberosKrb5);
preferences.put("kerberosLoginConf", AuthenticationUtil.pathKerberosLogin);
// Check krb integrity
if (AuthenticationUtil.isKerberos) {
// Fix #23877: NoClassDefFoundError on java/nio/file/Paths
if (!new File(AuthenticationUtil.pathKerberosKrb5).exists()) {
LOGGER.warn("Krb5 file not found: " + AuthenticationUtil.pathKerberosKrb5);
}
if (!new File(AuthenticationUtil.pathKerberosLogin).exists()) {
LOGGER.warn("Login file not found: " + AuthenticationUtil.pathKerberosLogin);
}
}
// Activate standard authentication
// TODO: java.lang.IllegalAccessError: class com.jsql.tool.AuthenticationTools (in unnamed module @0x266d09)
// cannot access class sun.net.www.protocol.http.AuthCacheImpl (in module java.base) because module java.base
// does not export sun.net.www.protocol.http to unnamed module @0x266d09
// Use Authenticator.setDefault(null); or a bad Authenticator
AuthCacheValue.setAuthCache(new AuthCacheImpl());
if (AuthenticationUtil.isAuthentication) {
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(AuthenticationUtil.usernameAuthentication, AuthenticationUtil.passwordAuthentication.toCharArray());
}
});
} else {
Authenticator.setDefault(null);
}
AuthenticationUtil.setAuthentication();
// TODO Remove from model
if (isRestartRequired && JOptionPane.showConfirmDialog(MediatorGui.frame(), "File krb5.conf has changed, please restart.", "Restart", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
new ActionNewWindow().actionPerformed(null);
}
}
use of sun.net.www.protocol.http.AuthCacheImpl in project coprhd-controller by CoprHD.
the class RecoverPointConnection method connect.
/**
* Connect to RP and return a handle that can be used for FAPI calls
*
* @param endpoint - Address to connect to
* @param username - Username for credentials
* @param password - Password for credentials
*
* @return FunctionalAPIImpl - A handle for FAPI access
*/
public FunctionalAPIImpl connect(URI endpoint, String username, String password) {
try {
ignoreCertifications();
// interceptCertificates();
} catch (Exception e) {
// so what?
}
String destAddress = endpoint.toASCIIString();
try {
URL baseUrl = FunctionalAPIImplService.class.getResource(".");
URL url = new URL(baseUrl, destAddress);
final String finalUser = username;
final String finalPassword = password;
// Modify the System Property for Max Redirects to a smaller number so we don't hammer
// the device over and over unnecessarily with bad credentials (if they're bad) as this
// takes a long time. Default is 20 redirects.
// However we will save the old redirect value and restore it after we're done.
String oldMaxRedirectsValue = null;
try {
oldMaxRedirectsValue = System.getProperty(SYSPROPS_HTTP_MAX_REDIRECTS);
} catch (NullPointerException npe) {
logger.warn("The System property " + SYSPROPS_HTTP_MAX_REDIRECTS + " does not already exist for some reason.");
}
// Set the Property for http.maxRedirects to 2 to prevent unnecessary retries
System.setProperty(SYSPROPS_HTTP_MAX_REDIRECTS, NEW_MAX_REDIRECTS);
// If we're creating a new connection, we want to clear the cache as it may be holding
// onto a previously valid connection.
AuthCacheValue.setAuthCache(new AuthCacheImpl());
Authenticator.setDefault(null);
// Create a PasswordAuthentication so when the request is asked via HTTP for authentication,
// the below will be automatically returned. This is set here, but invoked behind the scenes.
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(finalUser, finalPassword.toCharArray());
}
});
logger.info("Attempting to connect to service " + FAPI_SERVICENAME + " at url " + FAPI_URL + " using auth credentials for: " + finalUser);
// Connect to the service
FunctionalAPIImplService service = new FunctionalAPIImplService(url, new QName(FAPI_URL, FAPI_SERVICENAME));
FunctionalAPIImpl impl = service.getFunctionalAPIImplPort();
BindingProvider bp = (BindingProvider) impl;
Map<String, Object> map = bp.getRequestContext();
logger.info("RecoverPoint service: Dest: " + destAddress + ", user: " + username);
map.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, destAddress);
map.put(BindingProvider.USERNAME_PROPERTY, username);
map.put(BindingProvider.PASSWORD_PROPERTY, password);
// Reset the System Property for http.maxRedirects, but only if an existing value was present
if (oldMaxRedirectsValue != null && !oldMaxRedirectsValue.isEmpty()) {
System.setProperty(SYSPROPS_HTTP_MAX_REDIRECTS, oldMaxRedirectsValue);
}
logger.info("Connected.");
return impl;
} catch (MalformedURLException e) {
logger.error("Failed to create URL for the wsdl Location: " + destAddress);
logger.error(e.getMessage());
return null;
}
}
Aggregations