View Javadoc
1   /*
2    * DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
3    * Copyright (C) 2010  Mickael Guessant
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18   */
19  
20  package davmail.ui;
21  
22  import davmail.BundleMessage;
23  import davmail.ui.tray.DavGatewayTray;
24  
25  import javax.swing.*;
26  import java.awt.*;
27  
28  /**
29   * Display number matching value during O365 MFA process.
30   */
31  public class NumberMatchingFrame extends JFrame {
32  
33      /**
34       * Number matching dialog.
35       *
36       * @param entropy number matching value from Azure AD
37       */
38      public NumberMatchingFrame(String entropy) {
39          setAlwaysOnTop(true);
40  
41          setTitle(BundleMessage.format("UI_O365_MFA_NUMBER_MATCHING"));
42          try {
43              setIconImages(DavGatewayTray.getFrameIcons());
44          } catch (NoSuchMethodError error) {
45              DavGatewayTray.debug(new BundleMessage("LOG_UNABLE_TO_SET_ICON_IMAGE"));
46          }
47  
48  
49          JPanel infoPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
50          JLabel imageLabel = new JLabel();
51          imageLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon"));
52          imageLabel.setText(BundleMessage.format("UI_O365_MFA_NUMBER_MATCHING_PROMPT", entropy));
53          infoPanel.add(imageLabel);
54          add(infoPanel, BorderLayout.NORTH);
55          add(getButtonPanel(), BorderLayout.SOUTH);
56  
57          pack();
58          // center frame
59          setLocation(getToolkit().getScreenSize().width / 2 -
60                          getSize().width / 2,
61                  getToolkit().getScreenSize().height / 2 -
62                          getSize().height / 2);
63          setAlwaysOnTop(true);
64  
65          // auto close after 1 minute
66          Timer timer = new Timer(60000, evt -> {
67              NumberMatchingFrame.this.setVisible(false);
68              NumberMatchingFrame.this.dispose();
69          });
70          timer.start();
71          setVisible(true);
72      }
73  
74      protected JPanel getButtonPanel() {
75          JPanel buttonPanel = new JPanel();
76          JButton okButton = new JButton(BundleMessage.format("UI_BUTTON_OK"));
77          okButton.addActionListener(evt -> {
78              setVisible(false);
79              dispose();
80          });
81  
82          buttonPanel.add(okButton);
83          return buttonPanel;
84      }
85  
86  }