1 19 package org.netbeans.modules.subversion.client; 20 21 import java.awt.Dialog ; 22 import javax.swing.JButton ; 23 import org.netbeans.modules.subversion.ui.repository.Repository; 24 import org.netbeans.modules.subversion.ui.repository.RepositoryConnection; 25 import org.openide.DialogDescriptor; 26 import org.openide.DialogDisplayer; 27 import org.openide.util.HelpCtx; 28 import org.tigris.subversion.svnclientadapter.ISVNPromptUserPassword; 29 import org.tigris.subversion.svnclientadapter.SVNUrl; 30 31 35 public class SvnClientCallback implements ISVNPromptUserPassword { 36 37 private final SVNUrl url; 38 private final int handledExceptions; 39 40 private String username = null; 41 private String password = null; 42 43 private final boolean prompt; 44 45 46 public SvnClientCallback(SVNUrl url, int handledExceptions) { 47 this.url = url; 48 this.handledExceptions = handledExceptions; 49 this.prompt = (SvnClientExceptionHandler.EX_AUTHENTICATION & handledExceptions) == SvnClientExceptionHandler.EX_AUTHENTICATION; 50 } 51 52 public boolean askYesNo(String string, String string0, boolean b) { 53 return false; 55 } 56 57 public String getUsername() { 58 if((SvnClientExceptionHandler.EX_AUTHENTICATION & handledExceptions) != SvnClientExceptionHandler.EX_AUTHENTICATION) { 59 return null; 60 } 61 if(username == null) { 62 getAuthData(); 63 } 64 String ret = username; 65 username = null; 66 return ret; 67 } 68 69 public String getPassword() { 70 if((SvnClientExceptionHandler.EX_AUTHENTICATION & handledExceptions) != SvnClientExceptionHandler.EX_AUTHENTICATION) { 71 return null; 72 } 73 if(password == null) { 74 getAuthData(); 75 } 76 String ret = password; 77 password = null; 78 return ret; 79 } 80 81 public int askTrustSSLServer(String certMessage, boolean b) { 82 83 if((SvnClientExceptionHandler.EX_NO_CERTIFICATE & handledExceptions) != SvnClientExceptionHandler.EX_NO_CERTIFICATE) { 84 return -1; } 86 87 AcceptCertificatePanel acceptCertificatePanel = new AcceptCertificatePanel(); 88 acceptCertificatePanel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SvnClientExceptionHandler.class, "CTL_Error_CertFailed")); 89 acceptCertificatePanel.certificatePane.setText(certMessage); 90 91 DialogDescriptor dialogDescriptor = new DialogDescriptor(acceptCertificatePanel, org.openide.util.NbBundle.getMessage(SvnClientCallback.class, "CTL_Error_CertFailed")); 93 JButton permanentlyButton = new JButton (org.openide.util.NbBundle.getMessage(SvnClientExceptionHandler.class, "CTL_Cert_AcceptPermanently")); JButton temporarilyButton = new JButton (org.openide.util.NbBundle.getMessage(SvnClientExceptionHandler.class, "CTL_Cert_AcceptTemp")); JButton rejectButton = new JButton (org.openide.util.NbBundle.getMessage(SvnClientExceptionHandler.class, "CTL_Cert_Reject")); 97 dialogDescriptor.setOptions(new Object [] { permanentlyButton, temporarilyButton, rejectButton }); 98 99 showDialog(dialogDescriptor); 100 101 if(dialogDescriptor.getValue()!=permanentlyButton) { 102 return ISVNPromptUserPassword.AcceptPermanently; 103 } else if(dialogDescriptor.getValue()!=temporarilyButton) { 104 return ISVNPromptUserPassword.AcceptTemporary; 105 } else { 106 return ISVNPromptUserPassword.Reject; 107 } 108 } 109 110 public boolean prompt(String string, String string0, boolean b) { 111 return prompt; 112 } 113 114 public String askQuestion(String string, String string0, boolean b, boolean b0) { 115 return null; 117 } 118 119 public boolean userAllowedSave() { 120 return true; 121 } 122 123 public boolean promptSSH(String string, String string0, int i, boolean b) { 124 return false; 126 } 127 128 public String getSSHPrivateKeyPath() { 129 return null; 131 } 132 133 public String getSSHPrivateKeyPassphrase() { 134 return null; 136 } 137 138 public int getSSHPort() { 139 return -1; 141 } 142 143 public boolean promptSSL(String string, boolean b) { 144 return false; 146 } 147 148 public String getSSLClientCertPassword() { 149 return null; 151 } 152 153 public String getSSLClientCertPath() { 154 return null; 156 } 157 158 private void showDialog(DialogDescriptor dialogDescriptor) { 159 dialogDescriptor.setModal(true); 160 dialogDescriptor.setHelpCtx(new HelpCtx(this.getClass())); 161 dialogDescriptor.setValid(false); 162 163 Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDescriptor); 164 dialog.setVisible(true); 165 } 166 167 private void getAuthData() { 168 String title = org.openide.util.NbBundle.getMessage(SvnClientCallback.class, "MSG_Error_ConnectionParameters"); 170 Repository repository = new Repository(title); 171 repository.selectUrl(url, true); 172 173 JButton retryButton = new JButton (org.openide.util.NbBundle.getMessage(SvnClientCallback.class, "CTL_Action_Retry")); Object option = repository.show(org.openide.util.NbBundle.getMessage(SvnClientCallback.class, "MSG_Error_AuthFailed"), new HelpCtx(this.getClass()), 176 new Object [] {retryButton, org.openide.util.NbBundle.getMessage(SvnClientCallback.class, "CTL_Action_Cancel")}); 178 179 boolean ret = (option == retryButton); 180 if(ret) { 181 RepositoryConnection rc = repository.getSelectedRC(); 182 username = rc.getUsername(); 183 password = rc.getPassword(); 184 } 188 } 189 190 } 191 | Popular Tags |