001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008-2010 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2016 ForgeRock AS.
016 */
017
018package org.opends.guitools.uninstaller.ui;
019
020import java.awt.Dimension;
021import java.awt.GridBagConstraints;
022import java.awt.GridBagLayout;
023import java.awt.event.ActionEvent;
024import java.awt.event.ActionListener;
025import java.net.URI;
026import java.security.cert.X509Certificate;
027import java.util.ArrayList;
028
029import javax.naming.NamingException;
030import javax.swing.Box;
031import javax.swing.JButton;
032import javax.swing.JDialog;
033import javax.swing.JFrame;
034import javax.swing.JLabel;
035import javax.swing.JPanel;
036import javax.swing.JTextField;
037import javax.swing.SwingUtilities;
038import javax.swing.text.JTextComponent;
039
040import org.forgerock.i18n.LocalizableMessage;
041import org.forgerock.i18n.slf4j.LocalizedLogger;
042import org.opends.admin.ads.ADSContext;
043import org.opends.admin.ads.util.ApplicationTrustManager;
044import org.opends.admin.ads.util.ConnectionWrapper;
045import org.opends.guitools.controlpanel.datamodel.ConnectionProtocolPolicy;
046import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
047import org.opends.guitools.controlpanel.util.ConfigFromFile;
048import org.opends.quicksetup.ApplicationException;
049import org.opends.quicksetup.Constants;
050import org.opends.quicksetup.Installation;
051import org.opends.quicksetup.ReturnCode;
052import org.opends.quicksetup.Step;
053import org.opends.quicksetup.UserData;
054import org.opends.quicksetup.UserDataCertificateException;
055import org.opends.quicksetup.event.MinimumSizeComponentListener;
056import org.opends.quicksetup.ui.CertificateDialog;
057import org.opends.quicksetup.ui.UIFactory;
058import org.opends.quicksetup.ui.Utilities;
059import org.opends.quicksetup.util.BackgroundTask;
060import org.opends.quicksetup.util.UIKeyStore;
061import org.opends.quicksetup.util.Utils;
062
063import static com.forgerock.opendj.cli.Utils.*;
064import static org.opends.messages.AdminToolMessages.*;
065import static org.opends.messages.QuickSetupMessages.*;
066
067/**
068 * This class is a dialog that appears when the user must provide authentication
069 * to connect to the Directory Server in order to be able to display
070 * information.
071 */
072public class LoginDialog extends JDialog
073{
074  private static final long serialVersionUID = 9049409381101152000L;
075
076  private final JFrame parent;
077
078  private JLabel lHostName;
079  private JLabel lUid;
080  private JLabel lPwd;
081
082  private JTextField tfHostName;
083  private JTextField tfUid;
084  private JTextField tfPwd;
085
086  private JButton cancelButton;
087  private JButton okButton;
088
089  private boolean isCanceled = true;
090
091  private final ApplicationTrustManager trustManager;
092  private final int timeout;
093
094  private ConnectionWrapper connWrapper;
095
096  private String usedUrl;
097
098  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
099
100  /**
101   * Constructor of the LoginDialog.
102   * @param parent the parent frame for this dialog.
103   * @param trustManager the trust manager to be used for the secure
104   * connections.
105   * @param timeout the timeout to establish the connection in milliseconds.
106   * Use {@code 0} to express no timeout.
107   */
108  public LoginDialog(JFrame parent, ApplicationTrustManager trustManager,
109      int timeout)
110  {
111    super(parent);
112    setTitle(INFO_LOGIN_DIALOG_TITLE.get().toString());
113    this.parent = parent;
114    getContentPane().add(createPanel());
115    if (trustManager == null)
116    {
117      throw new IllegalArgumentException("The trustmanager cannot be null.");
118    }
119    this.trustManager = trustManager;
120    this.timeout = timeout;
121    /*
122     * TODO: find a way to calculate this dynamically.  This is done to avoid
123     * all the text in a single line.
124     */
125    setPreferredSize(new Dimension(500, 250));
126    addComponentListener(new MinimumSizeComponentListener(this, 500, 250));
127    getRootPane().setDefaultButton(okButton);
128  }
129
130  /**
131   * Returns <CODE>true</CODE> if the user clicked on cancel and
132   * <CODE>false</CODE> otherwise.
133   * @return <CODE>true</CODE> if the user clicked on cancel and
134   * <CODE>false</CODE> otherwise.
135   */
136  public boolean isCanceled()
137  {
138    return isCanceled;
139  }
140
141  @Override
142  public void setVisible(boolean visible)
143  {
144    cancelButton.setEnabled(true);
145    okButton.setEnabled(true);
146    if (visible)
147    {
148      tfPwd.setText("");
149      tfPwd.requestFocusInWindow();
150      UIFactory.setTextStyle(lHostName,
151          UIFactory.TextStyle.PRIMARY_FIELD_VALID);
152      UIFactory.setTextStyle(lUid,
153          UIFactory.TextStyle.PRIMARY_FIELD_VALID);
154      UIFactory.setTextStyle(lPwd,
155          UIFactory.TextStyle.PRIMARY_FIELD_VALID);
156      getRootPane().setDefaultButton(okButton);
157    }
158    super.setVisible(visible);
159  }
160
161  /**
162   * Returns the Host Name as is referenced in other servers.
163   * @return the Host Name as is referenced in other servers.
164   */
165  public String getHostName()
166  {
167    return tfHostName.getText();
168  }
169
170  /**
171   * Returns the Administrator UID provided by the user.
172   * @return the Administrator UID provided by the user.
173   */
174  public String getAdministratorUid()
175  {
176    return tfUid.getText();
177  }
178
179  /**
180   * Returns the Administrator password provided by the user.
181   * @return the Administrator password provided by the user.
182   */
183  public String getAdministratorPwd()
184  {
185    return tfPwd.getText();
186  }
187
188  /**
189   * Returns the connection we got with the provided authentication.
190   *
191   * @return the connection
192   */
193  public ConnectionWrapper getConnection()
194  {
195    return connWrapper;
196  }
197
198  /**
199   * Creates and returns the panel of the dialog.
200   * @return the panel of the dialog.
201   */
202  private JPanel createPanel()
203  {
204    JPanel p1 = new JPanel(new GridBagLayout());
205    p1.setBackground(UIFactory.CURRENT_STEP_PANEL_BACKGROUND);
206    p1.setBorder(UIFactory.DIALOG_PANEL_BORDER);
207    GridBagConstraints gbc = new GridBagConstraints();
208    gbc.gridwidth = GridBagConstraints.RELATIVE;
209    gbc.anchor = GridBagConstraints.NORTHWEST;
210    gbc.insets = UIFactory.getCurrentStepPanelInsets();
211    p1.add(UIFactory.makeJLabel(UIFactory.IconType.INFORMATION_LARGE, null,
212        UIFactory.TextStyle.NO_STYLE), gbc);
213    gbc.weightx = 1.0;
214    gbc.fill = GridBagConstraints.BOTH;
215    gbc.gridwidth = GridBagConstraints.REMAINDER;
216    gbc.insets.left = 0;
217    LocalizableMessage msg = INFO_UNINSTALL_LOGIN_DIALOG_MSG.get();
218
219    JTextComponent textPane =
220      UIFactory.makeHtmlPane(msg, UIFactory.INSTRUCTIONS_FONT);
221    textPane.setOpaque(false);
222    textPane.setEditable(false);
223    p1.add(textPane, gbc);
224
225    JPanel p2 = new JPanel(new GridBagLayout());
226    p2.setOpaque(false);
227
228    gbc.gridwidth = GridBagConstraints.RELATIVE;
229    gbc.weightx = 0.0;
230    gbc.insets = UIFactory.getEmptyInsets();
231    gbc.anchor = GridBagConstraints.WEST;
232    gbc.fill = GridBagConstraints.HORIZONTAL;
233    lHostName = UIFactory.makeJLabel(UIFactory.IconType.NO_ICON,
234        INFO_UNINSTALL_LOGIN_HOST_NAME_LABEL.get(),
235        UIFactory.TextStyle.PRIMARY_FIELD_VALID);
236    p2.add(lHostName, gbc);
237    gbc.weightx = 1.0;
238    gbc.insets.left = UIFactory.LEFT_INSET_PRIMARY_FIELD;
239    gbc.gridwidth = GridBagConstraints.REMAINDER;
240    tfHostName = UIFactory.makeJTextField(
241        LocalizableMessage.raw(UserData.getDefaultHostName()),
242        INFO_UNINSTALL_LOGIN_HOST_NAME_TOOLTIP.get(),
243        UIFactory.HOST_FIELD_SIZE, UIFactory.TextStyle.TEXTFIELD);
244    p2.add(tfHostName, gbc);
245
246    gbc.gridwidth = GridBagConstraints.RELATIVE;
247    gbc.weightx = 0.0;
248    gbc.insets.left = 0;
249    gbc.insets.top = UIFactory.TOP_INSET_PRIMARY_FIELD;
250    gbc.anchor = GridBagConstraints.WEST;
251    gbc.fill = GridBagConstraints.HORIZONTAL;
252    lUid = UIFactory.makeJLabel(UIFactory.IconType.NO_ICON,
253        INFO_GLOBAL_ADMINISTRATOR_UID_LABEL.get(),
254        UIFactory.TextStyle.PRIMARY_FIELD_VALID);
255    p2.add(lUid, gbc);
256    gbc.weightx = 1.0;
257    gbc.insets.left = UIFactory.LEFT_INSET_PRIMARY_FIELD;
258    gbc.gridwidth = GridBagConstraints.REMAINDER;
259    tfUid = UIFactory.makeJTextField(LocalizableMessage.raw(Constants.GLOBAL_ADMIN_UID),
260        INFO_UNINSTALL_LOGIN_UID_TOOLTIP.get(),
261        UIFactory.DN_FIELD_SIZE, UIFactory.TextStyle.TEXTFIELD);
262    p2.add(tfUid, gbc);
263
264    gbc.gridwidth = GridBagConstraints.RELATIVE;
265    gbc.weightx = 0.0;
266    gbc.insets.left = 0;
267    lPwd = UIFactory.makeJLabel(UIFactory.IconType.NO_ICON,
268        INFO_GLOBAL_ADMINISTRATOR_PWD_LABEL.get(),
269        UIFactory.TextStyle.PRIMARY_FIELD_VALID);
270    p2.add(lPwd, gbc);
271    gbc.insets.left = UIFactory.LEFT_INSET_PRIMARY_FIELD;
272    gbc.fill = GridBagConstraints.HORIZONTAL;
273    gbc.gridwidth = GridBagConstraints.REMAINDER;
274    JPanel p3 = new JPanel(new GridBagLayout());
275    p3.setOpaque(false);
276    tfPwd = UIFactory.makeJPasswordField(null,
277        INFO_UNINSTALL_LOGIN_PWD_TOOLTIP.get(),
278        UIFactory.PASSWORD_FIELD_SIZE, UIFactory.TextStyle.PASSWORD_FIELD);
279    p2.add(p3, gbc);
280    gbc.insets = UIFactory.getEmptyInsets();
281    gbc.gridwidth = GridBagConstraints.RELATIVE;
282    gbc.weightx = 0.0;
283    p3.add(tfPwd, gbc);
284    gbc.gridwidth = GridBagConstraints.REMAINDER;
285    gbc.weightx = 1.0;
286    p3.add(Box.createHorizontalGlue(), gbc);
287
288
289    gbc.fill = GridBagConstraints.HORIZONTAL;
290    gbc.insets = UIFactory.getEmptyInsets();
291    gbc.gridwidth = GridBagConstraints.RELATIVE;
292    gbc.weightx = 0.0;
293    gbc.insets.top = 0;
294    p1.add(Box.createHorizontalGlue(), gbc);
295    gbc.weightx = 1.0;
296    gbc.gridwidth = GridBagConstraints.REMAINDER;
297    gbc.insets.right = UIFactory.getCurrentStepPanelInsets().right;
298    p1.add(p2, gbc);
299    gbc.weighty = 1.0;
300    gbc.fill = GridBagConstraints.VERTICAL;
301    gbc.insets.bottom = UIFactory.getCurrentStepPanelInsets().bottom;
302    p1.add(Box.createVerticalGlue(), gbc);
303
304
305    JPanel buttonPanel = new JPanel(new GridBagLayout());
306    buttonPanel.setOpaque(false);
307    gbc.fill = GridBagConstraints.HORIZONTAL;
308    gbc.weightx = 1.0;
309    gbc.insets = UIFactory.getEmptyInsets();
310    gbc.gridwidth = 3;
311    buttonPanel.add(Box.createHorizontalGlue(), gbc);
312    gbc.gridwidth = GridBagConstraints.RELATIVE;
313    gbc.fill = GridBagConstraints.NONE;
314    gbc.weightx = 0.0;
315    okButton =
316      UIFactory.makeJButton(INFO_OK_BUTTON_LABEL.get(),
317          INFO_UNINSTALL_LOGIN_OK_BUTTON_TOOLTIP.get());
318    buttonPanel.add(okButton, gbc);
319    okButton.addActionListener(new ActionListener()
320    {
321      @Override
322      public void actionPerformed(ActionEvent ev)
323      {
324        okClicked();
325      }
326    });
327
328    gbc.gridwidth = GridBagConstraints.REMAINDER;
329    gbc.insets.left = UIFactory.HORIZONTAL_INSET_BETWEEN_BUTTONS;
330    cancelButton =
331      UIFactory.makeJButton(INFO_CANCEL_BUTTON_LABEL.get(),
332          INFO_UNINSTALL_LOGIN_CANCEL_BUTTON_TOOLTIP.get());
333    buttonPanel.add(cancelButton, gbc);
334    cancelButton.addActionListener(new ActionListener()
335    {
336      @Override
337      public void actionPerformed(ActionEvent ev)
338      {
339        cancelClicked();
340      }
341    });
342
343    JPanel p = new JPanel(new GridBagLayout());
344    p.setBackground(UIFactory.DEFAULT_BACKGROUND);
345    gbc.insets = UIFactory.getEmptyInsets();
346    gbc.fill = GridBagConstraints.BOTH;
347    gbc.gridwidth = GridBagConstraints.REMAINDER;
348    gbc.weightx = 1.0;
349    gbc.weighty = 1.0;
350    p.add(p1, gbc);
351    gbc.weighty = 0.0;
352    gbc.insets = UIFactory.getButtonsPanelInsets();
353    p.add(buttonPanel, gbc);
354
355    return p;
356  }
357
358  /** Method called when user clicks on cancel. */
359  private void cancelClicked()
360  {
361    isCanceled = true;
362    dispose();
363  }
364
365  /** Method called when user clicks on OK. */
366  private void okClicked()
367  {
368    BackgroundTask<Boolean> worker = new BackgroundTask<Boolean>()
369    {
370      @Override
371      public Boolean processBackgroundTask() throws NamingException, ApplicationException
372      {
373        connWrapper = null;
374        try
375        {
376          ControlPanelInfo info = ControlPanelInfo.getInstance();
377          info.setTrustManager(getTrustManager());
378          info.setConnectTimeout(timeout);
379          info.regenerateDescriptor();
380          ConfigFromFile conf = new ConfigFromFile();
381          conf.readConfiguration();
382          String dn = ADSContext.getAdministratorDN(tfUid.getText());
383          String pwd = tfPwd.getText();
384          info.setConnectionPolicy(ConnectionProtocolPolicy.USE_ADMIN);
385          usedUrl = info.getAdminConnectorURL();
386          if (usedUrl == null)
387          {
388            throw new ApplicationException(ReturnCode.APPLICATION_ERROR,
389                ERR_COULD_NOT_FIND_VALID_LDAPURL.get(), null);
390          }
391          connWrapper = org.opends.guitools.controlpanel.util.Utilities.getAdminDirContext(info, dn, pwd);
392          return true; // server is running
393        } catch (NamingException ne)
394        {
395          if (isServerRunning())
396          {
397            throw ne;
398          }
399          return false;
400        } catch (ApplicationException | IllegalStateException e)
401        {
402          throw e;
403        } catch (Throwable t)
404        {
405          throw new IllegalStateException("Unexpected throwable.", t);
406        }
407      }
408
409      @Override
410      public void backgroundTaskCompleted(Boolean returnValue,
411          Throwable throwable)
412      {
413        if (throwable != null)
414        {
415          logger.info(LocalizableMessage.raw("Error connecting: " + throwable, throwable));
416          if (isCertificateException(throwable))
417          {
418            ApplicationTrustManager.Cause cause =
419              trustManager.getLastRefusedCause();
420
421            logger.info(LocalizableMessage.raw("Certificate exception cause: "+cause));
422            UserDataCertificateException.Type excType = null;
423            if (cause == ApplicationTrustManager.Cause.NOT_TRUSTED)
424            {
425              excType = UserDataCertificateException.Type.NOT_TRUSTED;
426            }
427            else if (cause ==
428              ApplicationTrustManager.Cause.HOST_NAME_MISMATCH)
429            {
430              excType = UserDataCertificateException.Type.HOST_NAME_MISMATCH;
431            }
432            else
433            {
434              LocalizableMessage msg = getThrowableMsg(
435                  INFO_ERROR_CONNECTING_TO_LOCAL.get(), throwable);
436              displayError(msg, INFO_ERROR_TITLE.get());
437            }
438
439            if (excType != null)
440            {
441              String h;
442              int p;
443              try
444              {
445                URI uri = new URI(usedUrl);
446                h = uri.getHost();
447                p = uri.getPort();
448              }
449              catch (Throwable t)
450              {
451                logger.warn(LocalizableMessage.raw(
452                    "Error parsing ldap url of ldap url.", t));
453                h = INFO_NOT_AVAILABLE_LABEL.get().toString();
454                p = -1;
455              }
456              UserDataCertificateException udce =
457              new UserDataCertificateException(Step.REPLICATION_OPTIONS,
458                  INFO_CERTIFICATE_EXCEPTION.get(h, p),
459                  throwable, h, p,
460                  getTrustManager().getLastRefusedChain(),
461                  getTrustManager().getLastRefusedAuthType(), excType);
462
463              handleCertificateException(udce);
464            }
465          }
466          else if (throwable instanceof NamingException)
467          {
468            boolean uidInvalid = false;
469            boolean pwdInvalid = false;
470
471            String uid = tfUid.getText();
472            ArrayList<LocalizableMessage> possibleCauses = new ArrayList<>();
473            if ("".equals(uid.trim()))
474            {
475              uidInvalid = true;
476              possibleCauses.add(INFO_EMPTY_ADMINISTRATOR_UID.get());
477            }
478
479            if ("".equals(tfPwd.getText()))
480            {
481              pwdInvalid = true;
482              possibleCauses.add(INFO_EMPTY_PWD.get());
483            }
484            if (uidInvalid)
485            {
486              UIFactory.setTextStyle(lUid,
487                UIFactory.TextStyle.PRIMARY_FIELD_INVALID);
488            }
489            else
490            {
491              UIFactory.setTextStyle(lUid,
492                  UIFactory.TextStyle.PRIMARY_FIELD_VALID);
493              pwdInvalid = true;
494            }
495            if (pwdInvalid)
496            {
497              UIFactory.setTextStyle(lPwd,
498                UIFactory.TextStyle.PRIMARY_FIELD_INVALID);
499            }
500            else
501            {
502              UIFactory.setTextStyle(lPwd,
503                  UIFactory.TextStyle.PRIMARY_FIELD_VALID);
504            }
505            if (possibleCauses.size() > 0)
506            {
507              // LocalizableMessage with causes
508              displayError(
509                  ERR_CANNOT_CONNECT_TO_LOGIN_WITH_CAUSE.get(
510                          Utils.getMessageFromCollection(possibleCauses, "\n")),
511                  INFO_ERROR_TITLE.get());
512            }
513            else
514            {
515              // Generic message
516              displayError(
517                  Utils.getMessageForException((NamingException)throwable),
518                  INFO_ERROR_TITLE.get());
519            }
520          }
521          else if (throwable instanceof ApplicationException)
522          {
523            displayError(((ApplicationException)throwable).getMessageObject(),
524                    INFO_ERROR_TITLE.get());
525          }
526          else
527          {
528            // This is a bug
529            logger.error(LocalizableMessage.raw("Unexpected throwable: "+throwable,
530                throwable));
531            displayError(
532                getThrowableMsg(INFO_BUG_MSG.get(), throwable),
533                INFO_ERROR_TITLE.get());
534          }
535          cancelButton.setEnabled(true);
536          okButton.setEnabled(true);
537        } else
538        {
539          if (Boolean.FALSE.equals(returnValue))
540          {
541            displayInformationMessage(
542                INFO_LOGIN_DIALOG_SERVER_NOT_RUNNING_MSG.get(),
543                INFO_LOGIN_DIALOG_SERVER_NOT_RUNNING_TITLE.get());
544          }
545          else
546          {
547            String hostName = tfHostName.getText();
548            if (hostName == null || hostName.trim().length() == 0)
549            {
550              displayError(INFO_EMPTY_REMOTE_HOST.get(),
551                  INFO_ERROR_TITLE.get());
552              UIFactory.setTextStyle(lHostName,
553                  UIFactory.TextStyle.PRIMARY_FIELD_INVALID);
554            }
555            else
556            {
557              UIFactory.setTextStyle(lHostName,
558                UIFactory.TextStyle.PRIMARY_FIELD_VALID);
559            }
560          }
561          UIFactory.setTextStyle(lUid,
562              UIFactory.TextStyle.PRIMARY_FIELD_VALID);
563          UIFactory.setTextStyle(lPwd,
564              UIFactory.TextStyle.PRIMARY_FIELD_VALID);
565
566          isCanceled = false;
567          cancelButton.setEnabled(true);
568          okButton.setEnabled(true);
569          dispose();
570        }
571      }
572    };
573    cancelButton.setEnabled(false);
574    okButton.setEnabled(false);
575    worker.startBackgroundTask();
576  }
577
578  /**
579   * Displays an error message dialog.
580   *
581   * @param msg
582   *          the error message.
583   * @param title
584   *          the title for the dialog.
585   */
586  private void displayError(LocalizableMessage msg, LocalizableMessage title)
587  {
588    Utilities.displayError(parent, msg, title);
589    toFront();
590
591  }
592
593  /**
594   * Displays an information message dialog.
595   *
596   * @param msg
597   *          the information message.
598   * @param title
599   *          the title for the dialog.
600   */
601  private void displayInformationMessage(LocalizableMessage msg, LocalizableMessage title)
602  {
603    Utilities.displayInformationMessage(parent, msg, title);
604    toFront();
605  }
606
607  /**
608   * Returns whether the server is running or not.
609   * @return <CODE>true</CODE> if the server is running and <CODE>false</CODE>
610   * otherwise.
611   */
612  private boolean isServerRunning()
613  {
614    return Installation.getLocal().getStatus().isServerRunning();
615  }
616
617  /**
618   * Returns the trust manager that can be used to establish secure connections.
619   * @return the trust manager that can be used to establish secure connections.
620   */
621  private ApplicationTrustManager getTrustManager()
622  {
623    return trustManager;
624  }
625
626  /**
627   * Displays a dialog asking the user to accept a certificate if the user
628   * accepts it, we update the trust manager and simulate a click on "OK" to
629   * re-check the authentication.
630   * This method assumes that we are being called from the event thread.
631   */
632  private void handleCertificateException(UserDataCertificateException ce)
633  {
634    CertificateDialog dlg = new CertificateDialog(parent, ce);
635    dlg.pack();
636    dlg.setVisible(true);
637    if (dlg.getUserAnswer() != CertificateDialog.ReturnType.NOT_ACCEPTED)
638    {
639      X509Certificate[] chain = ce.getChain();
640      String authType = ce.getAuthType();
641      String host = ce.getHost();
642
643      if (chain != null && authType != null && host != null)
644      {
645        logger.info(LocalizableMessage.raw("Accepting certificate presented by host "+host));
646        getTrustManager().acceptCertificate(chain, authType, host);
647        /* Simulate a click on the OK by calling in the okClicked method. */
648        SwingUtilities.invokeLater(new Runnable()
649        {
650          @Override
651          public void run()
652          {
653            okClicked();
654          }
655        });
656      }
657      else
658      {
659        if (chain == null)
660        {
661          logger.warn(LocalizableMessage.raw(
662              "The chain is null for the UserDataCertificateException"));
663        }
664        if (authType == null)
665        {
666          logger.warn(LocalizableMessage.raw(
667              "The auth type is null for the UserDataCertificateException"));
668        }
669        if (host == null)
670        {
671          logger.warn(LocalizableMessage.raw(
672              "The host is null for the UserDataCertificateException"));
673        }
674      }
675    }
676    if (dlg.getUserAnswer() ==
677      CertificateDialog.ReturnType.ACCEPTED_PERMANENTLY)
678    {
679      X509Certificate[] chain = ce.getChain();
680      if (chain != null)
681      {
682        try
683        {
684          UIKeyStore.acceptCertificate(chain);
685        }
686        catch (Throwable t)
687        {
688          logger.warn(LocalizableMessage.raw("Error accepting certificate: "+t, t));
689        }
690      }
691    }
692  }
693
694  /**
695   * Method written for testing purposes.
696   * @param args the arguments to be passed to the test program.
697   */
698  public static void main(String[] args)
699  {
700    try
701    {
702      LoginDialog dlg = new LoginDialog(
703          org.opends.guitools.controlpanel.util.Utilities.createFrame(),
704          new ApplicationTrustManager(null),
705          5000);
706      dlg.pack();
707      dlg.setVisible(true);
708    } catch (Exception ex)
709    {
710      ex.printStackTrace();
711    }
712  }
713}