Search in sources :

Example 21 with Credentials

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

the class VSpherePanel method getServerURL.

// //////////////////////////////
// ServerPanel implementation //
// //////////////////////////////
@Override
public FileURL getServerURL() throws MalformedURLException {
    updateValues();
    FileURL url = FileURL.getFileURL(FileProtocols.VSPHERE + "://" + lastVsphere + "/" + lastGuest + "/" + PathUtils.removeLeadingSeparator(lastDir));
    url.setCredentials(new Credentials(lastUsername, new String(passwordField.getPassword())));
    url.setProperty(VSphereFile.GUEST_CREDENTIALS, lastGuestUsername + ":" + new String(guestPasswordField.getPassword()));
    return url;
}
Also used : FileURL(com.mucommander.commons.file.FileURL) Credentials(com.mucommander.commons.file.Credentials)

Example 22 with Credentials

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

the class HTTPPanel method getServerURL.

// //////////////////////////////
// ServerPanel implementation //
// //////////////////////////////
@Override
public FileURL getServerURL() throws MalformedURLException {
    updateValues();
    if (!(lastURL.toLowerCase().startsWith(FileProtocols.HTTP + "://") || lastURL.toLowerCase().startsWith(FileProtocols.HTTPS + "://")))
        lastURL = FileProtocols.HTTP + "://" + lastURL;
    FileURL fileURL = FileURL.getFileURL(lastURL);
    fileURL.setCredentials(new Credentials(lastUsername, lastPassword));
    return fileURL;
}
Also used : FileURL(com.mucommander.commons.file.FileURL) Credentials(com.mucommander.commons.file.Credentials)

Example 23 with Credentials

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

the class SFTPPanel method getServerURL.

// //////////////////////////////
// ServerPanel implementation //
// //////////////////////////////
@Override
public FileURL getServerURL() throws MalformedURLException {
    updateValues();
    if (!lastInitialDir.startsWith("/"))
        lastInitialDir = "/" + lastInitialDir;
    FileURL url = FileURL.getFileURL(FileProtocols.SFTP + "://" + lastServer + lastInitialDir);
    // Set credentials
    url.setCredentials(new Credentials(lastUsername, lastPassword));
    if (!"".equals(lastKeyPath.trim()))
        url.setProperty(SFTPFile.PRIVATE_KEY_PATH_PROPERTY_NAME, lastKeyPath);
    // Set port
    url.setPort(lastPort);
    return url;
}
Also used : FileURL(com.mucommander.commons.file.FileURL) Credentials(com.mucommander.commons.file.Credentials)

Example 24 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 "smb";
        }

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

        @Override
        public SchemeHandler getSchemeHandler() {
            return new DefaultSchemeHandler(new DefaultSchemeParser(), -1, "/", AuthenticationType.AUTHENTICATION_REQUIRED, new Credentials("GUEST", "")) {

                @Override
                public FileURL getRealm(FileURL location) {
                    FileURL realm = new FileURL(this);
                    String newPath = location.getPath();
                    // Find first path token (share)
                    int pos = newPath.indexOf('/', 1);
                    newPath = newPath.substring(0, pos == -1 ? newPath.length() : pos + 1);
                    realm.setPath(newPath);
                    realm.setScheme(location.getScheme());
                    realm.setHost(location.getHost());
                    realm.setPort(location.getPort());
                    // Copy properties (if any)
                    realm.importProperties(location);
                    return realm;
                }
            };
        }
    };
    ProtocolPanelProvider panelProvider = new ProtocolPanelProvider() {

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

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

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

        @Override
        public Class<? extends ServerPanel> getPanelClass() {
            return SMBPanel.class;
        }
    };
    serviceRegistration = context.registerService(FileProtocolService.class, service, null);
    uiServiceRegistration = context.registerService(ProtocolPanelProvider.class, panelProvider, null);
}
Also used : FileURL(com.mucommander.commons.file.FileURL) 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 25 with Credentials

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

the class ConnectionPool method getConnectionHandler.

public static ConnectionHandler getConnectionHandler(ConnectionHandlerFactory connectionHandlerFactory, FileURL url, boolean acquireLock) throws InterruptedIOException {
    FileURL realm = url.getRealm();
    while (true) {
        synchronized (connectionHandlers) {
            // Ensures that monitor thread is not currently changing the list while we access it
            Credentials urlCredentials = url.getCredentials();
            int matchingConnHandlers = 0;
            // Try and find an appropriate existing ConnectionHandler
            for (ConnectionHandler connHandler : connectionHandlers) {
                // ConnectionHandler must match the realm and credentials and must not be locked
                if (connHandler.equals(realm, urlCredentials)) {
                    matchingConnHandlers++;
                    synchronized (connHandler) {
                        // Ensures that lock remains unchanged while we access/update it
                        if (!connHandler.isLocked()) {
                            // Try to acquire lock if a lock was requested
                            if (!acquireLock || connHandler.acquireLock()) {
                                LOGGER.info("returning ConnectionHandler {}, realm = {}", connHandler, realm);
                                // Update last activity timestamp to now
                                connHandler.updateLastActivityTimestamp();
                                return connHandler;
                            }
                        }
                    }
                }
                if (matchingConnHandlers == MAX_CONNECTIONS_PER_REALM) {
                    LOGGER.info("Maximum number of connection per realm reached, waiting for one to be removed or released...");
                    try {
                        // Wait for a ConnectionHandler to be released or removed from the pool
                        // relinquishes the lock on connectionHandlers
                        connectionHandlers.wait();
                        break;
                    } catch (InterruptedException e) {
                        LOGGER.info("Interrupted while waiting on a connection for {}", url, e);
                        throw new InterruptedIOException();
                    }
                }
            }
            if (matchingConnHandlers == MAX_CONNECTIONS_PER_REALM)
                continue;
            // No suitable ConnectionHandler found, create a new one
            ConnectionHandler connHandler = connectionHandlerFactory.createConnectionHandler(url);
            // Acquire lock if a lock was requested
            if (acquireLock)
                connHandler.acquireLock();
            LOGGER.info("adding new ConnectionHandler {}, realm = {}", connHandler, connHandler.getRealm());
            // Insert new ConnectionHandler at first position as if it has more chances to be accessed again soon
            connectionHandlers.add(0, connHandler);
            // Start monitor thread if it is not currently running (if there previously was no registered ConnectionHandler)
            if (monitorThread == null) {
                LOGGER.info("starting monitor thread");
                monitorThread = new Thread(instance);
                monitorThread.start();
            }
            // Update last activity timestamp to now
            connHandler.updateLastActivityTimestamp();
            return connHandler;
        }
    }
}
Also used : FileURL(com.mucommander.commons.file.FileURL) InterruptedIOException(java.io.InterruptedIOException) 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