use of com.mucommander.commons.file.Credentials in project mucommander by mucommander.
the class S3Panel method getServerURL.
// //////////////////////////////
// ServerPanel implementation //
// //////////////////////////////
@Override
public FileURL getServerURL() throws MalformedURLException {
updateValues();
if (!lastInitialDir.startsWith("/"))
lastInitialDir = "/" + lastInitialDir;
FileURL url = FileURL.getFileURL(FileProtocols.S3 + "://" + lastServer + lastInitialDir);
// Set credentials
url.setCredentials(new Credentials(lastUsername, lastPassword));
// Set port
url.setPort(lastPort);
url.setProperty(S3File.STORAGE_TYPE, lastStorageType);
url.setProperty(S3File.DISABLE_DNS_BUCKETS, String.valueOf(lastDisableDnsBuckets));
url.setProperty(S3File.SECUTRE_HTTP, String.valueOf(lastSecureHttp));
url.setProperty(S3File.DEFAULT_BUCKET_LOCATION, lastLocation);
return url;
}
use of com.mucommander.commons.file.Credentials in project mucommander by mucommander.
the class S3ProtocolProvider method getFile.
public AbstractFile getFile(FileURL url, Map<String, Object> instantiationParams) throws IOException {
Credentials credentials = url.getCredentials();
if (credentials == null || credentials.getLogin().equals("") || credentials.getPassword().equals(""))
throw new AuthException(url);
S3Service service;
String bucketName;
if (instantiationParams.isEmpty()) {
Jets3tProperties props = new Jets3tProperties();
props.setProperty("s3service.s3-endpoint", url.getHost());
boolean secure = Boolean.parseBoolean(url.getProperty(S3File.SECUTRE_HTTP));
if (url.getPort() > 0)
props.setProperty(secure ? "s3service.s3-endpoint-https-port" : "s3service.s3-endpoint-http-port", String.valueOf(url.getPort()));
props.setProperty("s3service.https-only", String.valueOf(secure));
props.setProperty("s3service.disable-dns-buckets", url.getProperty(S3File.DISABLE_DNS_BUCKETS));
props.setProperty("s3service.default-bucket-location", url.getProperty(S3File.DEFAULT_BUCKET_LOCATION));
service = new RestS3Service(getProviderCredentials(url), null, null, props);
} else {
service = (S3Service) instantiationParams.get("service");
}
String path = url.getPath();
// Root resource
if (("/").equals(path))
return new S3Root(url, service);
// Fetch the bucket name from the URL
StringTokenizer st = new StringTokenizer(path, "/");
bucketName = st.nextToken();
// Object resource
if (st.hasMoreTokens()) {
org.jets3t.service.model.S3Object obj = (org.jets3t.service.model.S3Object) instantiationParams.get("object");
if (obj != null)
return new S3Object(url, service, bucketName, obj);
return new S3Object(url, service, bucketName);
}
// Bucket resource
org.jets3t.service.model.S3Bucket bucket = (org.jets3t.service.model.S3Bucket) instantiationParams.get("bucket");
if (bucket != null)
return new S3Bucket(url, service, bucket);
return new S3Bucket(url, service, bucketName);
}
use of com.mucommander.commons.file.Credentials in project mucommander by mucommander.
the class SFTPConnectionHandler method startConnection.
// ////////////////////////////////////
// ConnectionHandler implementation //
// ////////////////////////////////////
@Override
public void startConnection() throws IOException {
LOGGER.info("starting connection to {}", realm);
try {
FileURL realm = getRealm();
// Retrieve credentials to be used to authenticate
final Credentials credentials = getCredentials();
// Throw an AuthException if no auth information, required for SSH
if (credentials == null)
// Todo: localize this entry
throwAuthException("Login and password required");
LOGGER.trace("creating SshClient");
JSch jsch = new JSch();
// Override default port (22) if a custom port was specified in the URL
int port = realm.getPort();
if (port == -1)
port = 22;
String privateKeyPath = realm.getProperty(SFTPFile.PRIVATE_KEY_PATH_PROPERTY_NAME);
if (privateKeyPath != null) {
LOGGER.info("Using {} authentication method", PUBLIC_KEY_AUTH_METHOD);
jsch.addIdentity(privateKeyPath);
}
session = jsch.getSession(credentials.getLogin(), realm.getHost(), port);
session.setUserInfo(new PasswordAuthentication());
session.connect(5 * 1000);
// Init SFTP connections
channelSftp = (ChannelSftp) session.openChannel("sftp");
channelSftp.connect(5 * 1000);
LOGGER.info("authentication complete");
} catch (IOException e) {
LOGGER.info("IOException thrown while starting connection", e);
// Disconnect if something went wrong
if (session != null && session.isConnected())
session.disconnect();
;
session = null;
channelSftp = null;
// Re-throw exception
throw e;
} catch (JSchException e) {
LOGGER.info("Caught exception while authenticating: {}", e.getMessage());
LOGGER.debug("Exception:", e);
throwAuthException(e.getMessage());
}
}
use of com.mucommander.commons.file.Credentials in project mucommander by mucommander.
the class SMBPanel method getServerURL.
// //////////////////////////////
// ServerPanel implementation //
// //////////////////////////////
@Override
public FileURL getServerURL() throws MalformedURLException {
updateValues();
FileURL url = FileURL.getFileURL(FileProtocols.SMB + "://" + lastServer + (lastShare.startsWith("/") ? "" : "/") + lastShare);
// Insert the domain (if any) before the username, separated by a semicolon
String userInfo = lastUsername;
if (!lastDomain.equals(""))
userInfo = lastDomain + ";" + userInfo;
url.setCredentials(new Credentials(userInfo, lastPassword));
return url;
}
use of com.mucommander.commons.file.Credentials in project mucommander by mucommander.
the class RegistryPanel method getServerURL.
@Override
public FileURL getServerURL() throws MalformedURLException {
FileURL url = FileURL.getFileURL(String.format("%s://%s/%s", typeComboBox.getSelectedItem(), serverField.getText(), imageField.getText()));
url.setCredentials(new Credentials(usernameField.getText(), new String(passwordField.getPassword())));
return url;
}
Aggregations