Search in sources :

Example 1 with ActionNewWindow

use of com.jsql.view.swing.action.ActionNewWindow 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);
    }
}
Also used : InjectionModel(com.jsql.model.InjectionModel) AuthCacheImpl(sun.net.www.protocol.http.AuthCacheImpl) Preferences(java.util.prefs.Preferences) File(java.io.File) Authenticator(java.net.Authenticator) PasswordAuthentication(java.net.PasswordAuthentication) ActionNewWindow(com.jsql.view.swing.action.ActionNewWindow)

Aggregations

InjectionModel (com.jsql.model.InjectionModel)1 ActionNewWindow (com.jsql.view.swing.action.ActionNewWindow)1 File (java.io.File)1 Authenticator (java.net.Authenticator)1 PasswordAuthentication (java.net.PasswordAuthentication)1 Preferences (java.util.prefs.Preferences)1 AuthCacheImpl (sun.net.www.protocol.http.AuthCacheImpl)1