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"));
}
}
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);
}
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;
}
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;
}
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);
}
Aggregations