aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/securityconfig/masterpassword/SavedPasswordsPanel.java
blob: f98a69ca0c877ef44c93be4c77388766bc215c90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.plugin.securityconfig.masterpassword;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import net.java.sip.communicator.plugin.securityconfig.*;
import net.java.sip.communicator.service.credentialsstorage.*;
import net.java.sip.communicator.util.swing.*;

/**
 * Panel containing the saved passwords button.
 *
 * @author Dmitri Melnikov
 */
public class SavedPasswordsPanel
    extends TransparentPanel
{
    /**
     * The {@link CredentialsStorageService}.
     */
    private static final CredentialsStorageService credentialsStorageService
        = SecurityConfigActivator.getCredentialsStorageService();

    /**
     * Builds the panel.
     */
    public SavedPasswordsPanel() {
        this.setLayout(new BorderLayout(10, 10));
        this.setAlignmentX(0.0f);
        
        initComponents();
    }

    /**
     * Initializes the UI components.
     */
    private void initComponents()
    {
        JButton savedPasswordsButton = new JButton();
        savedPasswordsButton.setText(
                SecurityConfigActivator
                    .getResources()
                        .getI18NString(
                            "plugin.securityconfig.masterpassword.SAVED_PASSWORDS"));
        savedPasswordsButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                if (credentialsStorageService.isUsingMasterPassword())
                {
                    showSavedPasswordsDialog();
                } else 
                {
                    SavedPasswordsDialog.getInstance().setVisible(true);
                }
            }
        });
        this.add(savedPasswordsButton, BorderLayout.EAST);
    }

    /**
     * Displays a master password prompt to the user, verifies the entered
     * password and then shows the <tt>SavedPasswordsDialog</tt>.
     */
    private void showSavedPasswordsDialog()
    {
        String master;
        boolean correct = true;

        do
        {
            master = MasterPasswordInputDialog.showInput(correct);
            if (master == null)
                return;
            correct
                = (master.length() != 0)
                    && credentialsStorageService.verifyMasterPassword(master);
        }
        while (!correct);
        SavedPasswordsDialog.getInstance().setVisible(true);
    }
}