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