Search in sources :

Example 1 with Credentials

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;
}
Also used : FileURL(com.mucommander.commons.file.FileURL) Credentials(com.mucommander.commons.file.Credentials)

Example 2 with Credentials

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);
}
Also used : AuthException(com.mucommander.commons.file.AuthException) StringTokenizer(java.util.StringTokenizer) Jets3tProperties(org.jets3t.service.Jets3tProperties) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) RestS3Service(org.jets3t.service.impl.rest.httpclient.RestS3Service) S3Service(org.jets3t.service.S3Service) AWSCredentials(org.jets3t.service.security.AWSCredentials) GSCredentials(org.jets3t.service.security.GSCredentials) Credentials(com.mucommander.commons.file.Credentials) ProviderCredentials(org.jets3t.service.security.ProviderCredentials)

Example 3 with Credentials

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());
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) FileURL(com.mucommander.commons.file.FileURL) IOException(java.io.IOException) JSch(com.jcraft.jsch.JSch) Credentials(com.mucommander.commons.file.Credentials)

Example 4 with Credentials

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;
}
Also used : FileURL(com.mucommander.commons.file.FileURL) Credentials(com.mucommander.commons.file.Credentials)

Example 5 with Credentials

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;
}
Also used : FileURL(com.mucommander.commons.file.FileURL) 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