Package com.mucommander.commons.file

Examples of com.mucommander.commons.file.Credentials


        yPanel.addSpace(5);
       
        this.fileURL = fileURL;

        // Retrieve guest credentials (if any)
        Credentials guestCredentials = fileURL.getGuestCredentials();
        // Fetch credentials from the specified FileURL (if any) and use them only if they're different from the guest ones
        Credentials urlCredentials = fileURL.getCredentials();
        if(urlCredentials!=null && guestCredentials!=null && urlCredentials.equals(guestCredentials))
            urlCredentials = null;
        // Retrieve a list of credentials matching the URL from CredentialsManager
        credentialsMappings = CredentialsManager.getMatchingCredentials(fileURL);

        XAlignedComponentPanel compPanel = new XAlignedComponentPanel(10);

        // Connect as Guest/User radio buttons, displayed only if the URL has guest credentials
        if(guestCredentials!=null) {
            guestRadioButton = new JRadioButton(StringUtils.capitalize(guestCredentials.getLogin()));
            guestRadioButton.addActionListener(this);
            compPanel.addRow(Translator.get("auth_dialog.connect_as"), guestRadioButton, 0);

            userRadioButton = new JRadioButton(Translator.get("user"));
            userRadioButton.addActionListener(this);
            compPanel.addRow("", userRadioButton, 15);

            ButtonGroup buttonGroup = new ButtonGroup();
            buttonGroup.add(guestRadioButton);
            buttonGroup.add(userRadioButton);
        }
        // If not, display an introduction label ("please enter a login and password")
        else {
            yPanel.add(new JLabel(Translator.get("auth_dialog.desc")));
            yPanel.addSpace(15);
        }

        // Server URL for which the user has to authenticate
        compPanel.addRow(Translator.get("auth_dialog.server"), new JLabel(fileURL.toString(false)), 10);

        // Login field: create either a text field or an editable combo box, depending on whether
        // CredentialsManager returned matches (-> combo box) or not (-> text field).
        int nbCredentials = credentialsMappings.length;
        JComponent loginComponent;
        if(nbCredentials>0) {
            // Editable combo box
            loginComboBox = new EditableComboBox();
            this.loginField = loginComboBox.getTextField();

            // Add credentials to the combo box's choices
            for(int i=0; i<nbCredentials; i++)
                loginComboBox.addItem(credentialsMappings[i].getCredentials().getLogin());

            loginComboBox.addEditableComboBoxListener(this);

            loginComponent = loginComboBox;
        }
    else {
            // Simple text field
            loginField = new JTextField();
            loginComponent = loginField;
        }

        compPanel.addRow(Translator.get("login"), loginComponent, 5);

        // Create password field
        this.passwordField = new JPasswordField();
        passwordField.addActionListener(this);
        compPanel.addRow(Translator.get("password"), passwordField, 10);

        // Contains the credentials to set in the login and password text fields
        Credentials selectedCredentials = null;
        // Whether the 'save credentials' checkbox should be enabled
        boolean saveCredentialsCheckBoxSelected = false;

        // If the provided URL contains credentials, use them
        if(urlCredentials!=null) {
            selectedCredentials = urlCredentials;
        }
        // Else if CredentialsManager had matching credentials, use the best ones 
        else if(nbCredentials>0) {
            CredentialsMapping bestCredentialsMapping = credentialsMappings[0];

            selectedCredentials = bestCredentialsMapping.getCredentials();
            saveCredentialsCheckBoxSelected = bestCredentialsMapping.isPersistent();
        }

        yPanel.add(compPanel);

        this.saveCredentialsCheckBox = new JCheckBox(Translator.get("auth_dialog.store_credentials"), saveCredentialsCheckBoxSelected);
        yPanel.add(saveCredentialsCheckBox);

        yPanel.addSpace(5);
        contentPane.add(yPanel, BorderLayout.CENTER);

        // If we have some existing credentials for this location...
        if(selectedCredentials!=null) {
            // Prefill the login and password fields with the selected credentials
            loginField.setText(selectedCredentials.getLogin());
            passwordField.setText(selectedCredentials.getPassword());

            // Select the text fields' so their content can be erased just by typing the replacement string
            loginField.selectAll();
            passwordField.selectAll();
View Full Code Here


        if(guestRadioButton!=null && guestRadioButton.isSelected()) {
            guestCredentialsSelected = true;
            selectedCredentialsMapping = new CredentialsMapping(fileURL.getGuestCredentials(), fileURL, false);
        }
        else {
            Credentials enteredCredentials = new Credentials(loginField.getText(), new String(passwordField.getPassword()));
            guestCredentialsSelected = false;

            boolean isPersistent = saveCredentialsCheckBox.isSelected();
            selectedCredentialsMapping = new CredentialsMapping(enteredCredentials, fileURL, isPersistent);
View Full Code Here

    // EditableComboBoxListener implementation //
    /////////////////////////////////////////////

    public void comboBoxSelectionChanged(SaneComboBox source) {
        CredentialsMapping selectedCredentialsMapping = credentialsMappings[loginComboBox.getSelectedIndex()];
        Credentials selectedCredentials = selectedCredentialsMapping.getCredentials();
        loginField.setText(selectedCredentials.getLogin());
        passwordField.setText(selectedCredentials.getPassword());

        // Enable/disable 'save credentials' checkbox depending on whether the selected credentials are persistent or not
        if(saveCredentialsCheckBox!=null)
            saveCredentialsCheckBox.setSelected(selectedCredentialsMapping.isPersistent());
    }
View Full Code Here

        if(!credentialsList.isSelectionEmpty() && credentials.size()>0) {
            componentsEnabled = true;

            CredentialsMapping credentialsMapping = (CredentialsMapping) credentialsList.getSelectedValue();
            Credentials credentials = credentialsMapping.getCredentials();
            loginValue = credentials.getLogin();
            passwordValue = credentials.getPassword();
        }

        loginField.setText(loginValue);
        loginField.setEnabled(componentsEnabled);
View Full Code Here

     */
    private void modifyCredentials() {
        // Make sure that the item still exists (could have been removed) before trying to modify its value
        int itemIndex = credentials.indexOf(lastSelectedItem);
        if(lastSelectedItem!=null && itemIndex!=-1) {
            credentials.setElementAt(new CredentialsMapping(new Credentials(loginField.getText(), new String(passwordField.getPassword())), lastSelectedItem.getRealm(), true), itemIndex);
        }
       
        this.lastSelectedItem = (CredentialsMapping) credentialsList.getSelectedValue();
    }
View Full Code Here

                LOGGER.info("Password could not be decrypted: "+ password +", credentials will be ignored");
                return;
            }

            // Add credentials to persistent credentials list
            CredentialsManager.getPersistentCredentialMappings().add(new CredentialsMapping(new Credentials(login, password), url, true));
        }
        else if(qName.equals(ELEMENT_URL)) {
            try {url = FileURL.getFileURL(characters.toString().trim());}
            catch(MalformedURLException e) {
                LOGGER.info("Malformed URL: "+characters+", location will be ignored");
View Full Code Here

        CredentialsMapping creds[] = getMatchingCredentials(location);
        if(creds.length>0) {
            authenticate(location, creds[0]);
        }
        else {
            Credentials guestCredentials = location.getGuestCredentials();
            if(guestCredentials!=null) {
                authenticate(location, new CredentialsMapping(guestCredentials, location.getRealm(), false));
            }
        }
    }
View Full Code Here

            // Write URL
            out.startElement(ELEMENT_URL);
            out.writeCData(realm.toString(false));
            out.endElement(ELEMENT_URL);

            Credentials credentials = credentialsMapping.getCredentials();

            // Write login
            out.startElement(ELEMENT_LOGIN);
            out.writeCData(credentials.getLogin());
            out.endElement(ELEMENT_LOGIN);

            // Write password (XOR encrypted)
            out.startElement(ELEMENT_PASSWORD);
            out.writeCData(XORCipher.encryptXORBase64(credentials.getPassword()));
            out.endElement(ELEMENT_PASSWORD);

            // Write properties, each property is stored in a separate 'property' element
            propertyKeys = realm.getPropertyNames();
            while(propertyKeys.hasMoreElements()) {
View Full Code Here

TOP

Related Classes of com.mucommander.commons.file.Credentials

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.