Search in sources :

Example 11 with Credentials

use of com.mucommander.commons.file.Credentials in project mucommander by mucommander.

the class ServerConnectDialog method actionPerformed.

// //////////////////////////
// ActionListener methods //
// //////////////////////////
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if (source == cancelButton) {
        dispose();
        return;
    }
    try {
        currentServerPanel.dialogValidated();
        // Can throw a MalformedURLException
        FileURL serverURL = currentServerPanel.getServerURL();
        // Create a CredentialsMapping instance and pass to Folder so that it uses it to connect to the folder and
        // adds to CredentialsManager once the folder has been successfully changed
        Credentials credentials = serverURL.getCredentials();
        CredentialsMapping credentialsMapping;
        if (credentials != null) {
            credentialsMapping = new CredentialsMapping(credentials, serverURL, saveCredentialsCheckBox.isSelected());
        } else {
            credentialsMapping = null;
        }
        dispose();
        // Change the current folder
        folderPanel.tryChangeCurrentFolder(serverURL, credentialsMapping);
    } catch (IOException ex) {
        InformationDialog.showErrorDialog(this, Translator.get("table.folder_access_error_title"), Translator.get("folder_does_not_exist"));
    }
}
Also used : FileURL(com.mucommander.commons.file.FileURL) IOException(java.io.IOException) Credentials(com.mucommander.commons.file.Credentials) CredentialsMapping(com.mucommander.auth.CredentialsMapping)

Example 12 with Credentials

use of com.mucommander.commons.file.Credentials in project mucommander by mucommander.

the class Activator method start.

@Override
public void start(BundleContext context) throws Exception {
    FileProtocolService service = new FileProtocolService() {

        @Override
        public String getSchema() {
            return "gdrive";
        }

        @Override
        public ProtocolProvider getProtocolProvider() {
            return new GoogleDriveProtocolProvider();
        }

        @Override
        public SchemeHandler getSchemeHandler() {
            return new DefaultSchemeHandler(new DefaultSchemeParser(), 21, "/", AuthenticationType.NO_AUTHENTICATION, new Credentials("anonymous", "anonymous_coward@mucommander.com"));
        }
    };
    ProtocolPanelProvider panelProvider = new ProtocolPanelProvider() {

        @Override
        public String getSchema() {
            return "gdrive";
        }

        @Override
        public ServerPanel get(ServerPanelListener listener, JFrame mainFrame) {
            return new GoogleDrivePanel(listener, mainFrame);
        }

        @Override
        public int priority() {
            return 5000;
        }

        @Override
        public Class<? extends ServerPanel> getPanelClass() {
            return GoogleDrivePanel.class;
        }
    };
    serviceRegistration = context.registerService(FileProtocolService.class, service, null);
    uiServiceRegistration = context.registerService(ProtocolPanelProvider.class, panelProvider, null);
}
Also used : ServerPanelListener(com.mucommander.protocol.ui.ServerPanelListener) DefaultSchemeParser(com.mucommander.commons.file.DefaultSchemeParser) JFrame(javax.swing.JFrame) ProtocolPanelProvider(com.mucommander.protocol.ui.ProtocolPanelProvider) Credentials(com.mucommander.commons.file.Credentials) FileProtocolService(com.mucommander.commons.file.osgi.FileProtocolService) DefaultSchemeHandler(com.mucommander.commons.file.DefaultSchemeHandler)

Example 13 with Credentials

use of com.mucommander.commons.file.Credentials in project mucommander by mucommander.

the class DropboxPanel method getServerURL.

@Override
public FileURL getServerURL() throws MalformedURLException {
    FileURL url = FileURL.getFileURL(String.format("%s://%s", SCHEMA, accountAlias.getText()));
    url.setCredentials(new Credentials(accountAlias.getText(), token.getText()));
    return url;
}
Also used : FileURL(com.mucommander.commons.file.FileURL) Credentials(com.mucommander.commons.file.Credentials)

Example 14 with Credentials

use of com.mucommander.commons.file.Credentials in project mucommander by mucommander.

the class FTPPanel method getServerURL.

// //////////////////////////////
// ServerPanel implementation //
// //////////////////////////////
@Override
public FileURL getServerURL() throws MalformedURLException {
    updateValues();
    if (!lastInitialDir.startsWith("/"))
        lastInitialDir = "/" + lastInitialDir;
    FileURL url = FileURL.getFileURL(FileProtocols.FTP + "://" + lastServer + lastInitialDir);
    if (anonymousUser)
        url.setCredentials(new Credentials(ANONYMOUS_CREDENTIALS.getLogin(), new String(passwordField.getPassword())));
    else
        url.setCredentials(new Credentials(lastUsername, lastPassword));
    // Set port
    url.setPort(lastPort);
    // Set passiveMode property to true (default) or false
    url.setProperty(FTPFile.PASSIVE_MODE_PROPERTY_NAME, "" + passiveMode);
    // Set FTP encoding property
    url.setProperty(FTPFile.ENCODING_PROPERTY_NAME, encodingSelectBox.getSelectedEncoding());
    // Set connection retry properties
    url.setProperty(FTPFile.NB_CONNECTION_RETRIES_PROPERTY_NAME, "" + nbRetriesSpinner.getValue());
    url.setProperty(FTPFile.CONNECTION_RETRY_DELAY_PROPERTY_NAME, "" + retryDelaySpinner.getValue());
    return url;
}
Also used : FileURL(com.mucommander.commons.file.FileURL) Credentials(com.mucommander.commons.file.Credentials)

Example 15 with Credentials

use of com.mucommander.commons.file.Credentials in project mucommander by mucommander.

the class CredentialsWriter method write.

/**
 * Writes the credentials XML file in the user's preferences folder.
 * This method should only be called by {@link CredentialsManager}.
 */
static void write(OutputStream stream) throws IOException {
    XmlWriter out = new XmlWriter(stream);
    // Root element, add the encryption method used
    XmlAttributes attributes = new XmlAttributes();
    attributes.add(ATTRIBUTE_ENCRYPTION, WEAK_ENCRYPTION_METHOD);
    // Version the file
    attributes.add(ATTRIBUTE_VERSION, RuntimeConstants.VERSION);
    out.startElement(ELEMENT_ROOT, attributes);
    out.println();
    Iterator<CredentialsMapping> iterator = CredentialsManager.getPersistentCredentialMappings().iterator();
    CredentialsMapping credentialsMapping;
    FileURL realm;
    Enumeration<String> propertyKeys;
    String name;
    while (iterator.hasNext()) {
        credentialsMapping = iterator.next();
        realm = credentialsMapping.getRealm();
        // Start credentials element
        out.startElement(ELEMENT_CREDENTIALS);
        out.println();
        // 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()) {
            name = propertyKeys.nextElement();
            attributes = new XmlAttributes();
            attributes.add(ATTRIBUTE_NAME, name);
            attributes.add(ATTRIBUTE_VALUE, realm.getProperty(name));
            out.startElement(ELEMENT_PROPERTY, attributes);
            out.endElement(ELEMENT_PROPERTY);
        }
        // End credentials element
        out.endElement(ELEMENT_CREDENTIALS);
    }
    // End root element
    out.endElement(ELEMENT_ROOT);
}
Also used : FileURL(com.mucommander.commons.file.FileURL) XmlAttributes(com.mucommander.commons.util.xml.XmlAttributes) XmlWriter(com.mucommander.commons.util.xml.XmlWriter) Credentials(com.mucommander.commons.file.Credentials)

Aggregations

Credentials (com.mucommander.commons.file.Credentials)25 FileURL (com.mucommander.commons.file.FileURL)16 CredentialsMapping (com.mucommander.auth.CredentialsMapping)5 DefaultSchemeHandler (com.mucommander.commons.file.DefaultSchemeHandler)4 DefaultSchemeParser (com.mucommander.commons.file.DefaultSchemeParser)4 FileProtocolService (com.mucommander.commons.file.osgi.FileProtocolService)4 ProtocolPanelProvider (com.mucommander.protocol.ui.ProtocolPanelProvider)4 ServerPanelListener (com.mucommander.protocol.ui.ServerPanelListener)4 JFrame (javax.swing.JFrame)4 AuthException (com.mucommander.commons.file.AuthException)2 IOException (java.io.IOException)2 JSch (com.jcraft.jsch.JSch)1 JSchException (com.jcraft.jsch.JSchException)1 XmlAttributes (com.mucommander.commons.util.xml.XmlAttributes)1 XmlWriter (com.mucommander.commons.util.xml.XmlWriter)1 InterruptedIOException (java.io.InterruptedIOException)1 StringTokenizer (java.util.StringTokenizer)1 Jets3tProperties (org.jets3t.service.Jets3tProperties)1 S3Service (org.jets3t.service.S3Service)1 RestS3Service (org.jets3t.service.impl.rest.httpclient.RestS3Service)1