# HG changeset patch # User Lukas Jungmann # Date 1213979066 -7200 # Node ID 9d1eab5b68579101ffc95d4eee7088318233fdb8 # Parent 2c57beded08a7e7989f43ccccc756ad9ec026b52 IZ #135838: I can make refresh JAX-RPC web service client fail with HTTP BASIC Authentication - core diff -r 2c57beded08a -r 9d1eab5b6857 o.n.core/src/org/netbeans/core/Bundle.properties --- a/o.n.core/src/org/netbeans/core/Bundle.properties Fri Jun 20 12:43:27 2008 +0400 +++ b/o.n.core/src/org/netbeans/core/Bundle.properties Fri Jun 20 18:24:26 2008 +0200 @@ -214,13 +214,6 @@ ACSD_ListOfChangedFiles=List of changed files for save ACSD_ExitDialog=Dialog for save any changes -#NbAuthenticator -LAB_AUTH_User_Name=&User Name\: -LAB_AUTH_Password=&Password\: -ACSD_PasswordField=N/A -ACSD_UserNameField=N/A -ACSD_NbAuthenticatorPasswordPanel=N/A - #NonGuiMain CTL_INPUT_option=-i input file of commands CTL_OUTPUT_option=-o output file for commands @@ -250,3 +243,10 @@ # blocked event queue LOG_EventQueueBlocked=AWT Event Dispatch Thread is blocked for {0} ms LOG_EventQueueBlocked_ICON_BASE=org/netbeans/core/resources/log-file.gif + +# NbAuthenticator +CTL_Authentication=Authentication Required + +# NbAuthenticatorPanel +NbAuthenticatorPanel.userNameLbl.text=&User Name: +NbAuthenticatorPanel.passwordLbl.text=&Password: diff -r 2c57beded08a -r 9d1eab5b6857 o.n.core/src/org/netbeans/core/NbAuthenticator.java --- a/o.n.core/src/org/netbeans/core/NbAuthenticator.java Fri Jun 20 12:43:27 2008 +0400 +++ b/o.n.core/src/org/netbeans/core/NbAuthenticator.java Fri Jun 20 18:24:26 2008 +0200 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common @@ -38,35 +38,45 @@ * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ - package org.netbeans.core; +import java.net.PasswordAuthentication; import java.util.logging.Level; import java.util.logging.Logger; import java.util.prefs.Preferences; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.util.NbBundle; import org.openide.util.NbPreferences; /** Global password protected sites Authenticator for IDE * * @author Jiri Rechtacek */ +class NbAuthenticator extends java.net.Authenticator { -class NbAuthenticator extends java.net.Authenticator { - NbAuthenticator () { - Preferences proxySettingsNode = NbPreferences.root ().node ("/org/netbeans/core"); + NbAuthenticator() { + Preferences proxySettingsNode = NbPreferences.root().node("/org/netbeans/core"); //NOI18N assert proxySettingsNode != null; } + @Override protected java.net.PasswordAuthentication getPasswordAuthentication() { - Logger.getLogger (NbAuthenticator.class.getName ()).log (Level.FINER, "Authenticator.getPasswordAuthentication() with prompt " + this.getRequestingPrompt()); - - if (ProxySettings.useAuthentication ()) { - Logger.getLogger (NbAuthenticator.class.getName ()).log (Level.FINER, "Username set to " + ProxySettings.getAuthenticationUsername () + " while request " + this.getRequestingURL ()); - return new java.net.PasswordAuthentication (ProxySettings.getAuthenticationUsername (), ProxySettings.getAuthenticationPassword ()); + Logger.getLogger(NbAuthenticator.class.getName()).log(Level.FINER, "Authenticator.getPasswordAuthentication() with prompt " + this.getRequestingPrompt()); //NOI18N + + if (RequestorType.PROXY == getRequestorType() && ProxySettings.useAuthentication()) { + Logger.getLogger(NbAuthenticator.class.getName()).log(Level.FINER, "Username set to " + ProxySettings.getAuthenticationUsername() + " while request " + this.getRequestingURL()); //NOI18N + return new java.net.PasswordAuthentication(ProxySettings.getAuthenticationUsername(), ProxySettings.getAuthenticationPassword()); } else { - Logger.getLogger (NbAuthenticator.class.getName ()).log (Level.WARNING, "No authentication set while requesting " + this.getRequestingURL ()); - return null; + NbAuthenticatorPanel ui = new NbAuthenticatorPanel(getRequestingPrompt()); + Object result = DialogDisplayer.getDefault().notify( + new DialogDescriptor(ui, NbBundle.getMessage(NbAuthenticator.class, "CTL_Authentication"))); //NOI18N + if (DialogDescriptor.OK_OPTION == result) { + return new PasswordAuthentication(ui.getUserName(), ui.getPassword()); + } } - + + Logger.getLogger(NbAuthenticator.class.getName()).log(Level.WARNING, "No authentication set while requesting " + this.getRequestingURL()); //NOI18N + return null; } } diff -r 2c57beded08a -r 9d1eab5b6857 o.n.core/src/org/netbeans/core/NbAuthenticatorPanel.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/o.n.core/src/org/netbeans/core/NbAuthenticatorPanel.form Fri Jun 20 18:24:26 2008 +0200 @@ -0,0 +1,96 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 2c57beded08a -r 9d1eab5b6857 o.n.core/src/org/netbeans/core/NbAuthenticatorPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/o.n.core/src/org/netbeans/core/NbAuthenticatorPanel.java Fri Jun 20 18:24:26 2008 +0200 @@ -0,0 +1,97 @@ +/* + * AuthenticatorPanel.java + * + * Created on June 12, 2008, 9:42 PM + */ + +package org.netbeans.core; + +/** + * + * @author lukas + */ +final class NbAuthenticatorPanel extends javax.swing.JPanel { + + private String realmName; + + /** Creates new form AuthenticatorPanel */ + public NbAuthenticatorPanel(String realmName) { + this.realmName = realmName; + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + userNameLbl = new javax.swing.JLabel(); + userName = new javax.swing.JTextField(); + passwordLbl = new javax.swing.JLabel(); + password = new javax.swing.JPasswordField(); + realmNameLbl = new javax.swing.JLabel(); + + userNameLbl.setLabelFor(userName); + org.openide.awt.Mnemonics.setLocalizedText(userNameLbl, org.openide.util.NbBundle.getMessage(NbAuthenticatorPanel.class, "NbAuthenticatorPanel.userNameLbl.text")); // NOI18N + + passwordLbl.setLabelFor(password); + org.openide.awt.Mnemonics.setLocalizedText(passwordLbl, org.openide.util.NbBundle.getMessage(NbAuthenticatorPanel.class, "NbAuthenticatorPanel.passwordLbl.text")); // NOI18N + + realmNameLbl.setText(realmName); + realmNameLbl.setFocusable(false); + realmNameLbl.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(userNameLbl) + .add(passwordLbl)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(realmNameLbl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE) + .add(password, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE) + .add(userName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 287, Short.MAX_VALUE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .add(realmNameLbl) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(userNameLbl) + .add(userName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(passwordLbl) + .add(password, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPasswordField password; + private javax.swing.JLabel passwordLbl; + private javax.swing.JLabel realmNameLbl; + private javax.swing.JTextField userName; + private javax.swing.JLabel userNameLbl; + // End of variables declaration//GEN-END:variables + + public char[] getPassword() { + return password.getPassword(); + } + + public String getUserName() { + return userName.getText(); + } + +}