private String toURL(final Host host) { StringBuilder url = new StringBuilder(host.getProtocol().getScheme().toString()); url.append("://"); url.append(new PunycodeConverter().convert(host.getHostname())); url.append(":").append(host.getPort()); return url.toString(); } }
/** * @return URL */ public String get(final Host bookmark) { final Scheme scheme = bookmark.getProtocol().getScheme(); final int port = bookmark.getPort(); final String username = bookmark.getCredentials().getUsername(); final String hostname = bookmark.getHostname(); final String path = bookmark.getDefaultPath(); return this.get(scheme, port, username, hostname, path); }
switch(name) { case "site": current = new Host(protocols.forScheme(Scheme.ftp), attrs.getValue("hName")); current.setNickname(attrs.getValue("name")); current.getCredentials().setUsername(attrs.getValue("un")); current.setWebURL(attrs.getValue("wURL")); current.setComment(attrs.getValue("comm")); current.setDefaultPath(attrs.getValue("path")); String protocol = attrs.getValue("ftpPType"); try { switch(Integer.valueOf(protocol)) { case 1: current.setProtocol(protocols.forScheme(Scheme.ftp)); break; case 2: case 3: case 4: current.setProtocol(protocols.forScheme(Scheme.ftps)); break; case 6: current.setProtocol(protocols.forScheme(Scheme.dav)); break; case 7: current.setProtocol(protocols.forScheme(Scheme.davs)); break; case 8: case 9: current.setProtocol(protocols.forScheme(Scheme.s3)); break;
@Override public String getEndpoint() { return String.format("%s:%d", bookmark.getHostname(), bookmark.getPort()); }
@Override public void change(final Host bookmark) { updateField(pathField, bookmark.getDefaultPath()); pathField.setEnabled(bookmark.getProtocol().isPathConfigurable()); } });
@Action public void hostFieldDidChange(final NSNotification sender) { final String input = hostField.stringValue(); if(Scheme.isURL(input)) { final Host parsed = HostParser.parse(input); bookmark.setHostname(parsed.getHostname()); bookmark.setProtocol(parsed.getProtocol()); bookmark.setPort(parsed.getPort()); bookmark.setDefaultPath(parsed.getDefaultPath()); } else { bookmark.setHostname(input); final Credentials auto = CredentialsConfiguratorFactory.get(bookmark.getProtocol()).configure(bookmark); final Credentials credentials = bookmark.getCredentials(); credentials.setUsername(auto.getUsername()); credentials.setPassword(auto.getPassword()); credentials.setIdentity(auto.getIdentity()); credentials.setToken(auto.getToken()); credentials.setCertificate(auto.getCertificate()); } this.update(); }
if(StringUtils.isNotBlank(bookmark.getComment())) { comment.append(bookmark.getComment()); if(!comment.toString().endsWith(".")) { comment.append("."); bookmark.setComment(comment.toString()); if(log.isDebugEnabled()) { log.debug(String.format("Create new bookmark from import %s", bookmark)); final Credentials credentials = bookmark.getCredentials(); if(StringUtils.isNotBlank(credentials.getPassword())) { if(credentials.isPublicKeyAuthentication()) { keychain.addPassword(bookmark.getHostname(), credentials.getIdentity().getAbbreviatedPath(), credentials.getPassword()); keychain.addPassword(bookmark.getProtocol().getScheme(), bookmark.getPort(), bookmark.getHostname(), credentials.getUsername(), credentials.getPassword());
log.debug(String.format("Protocol selection changed to %s", selected)); bookmark.setPort(selected.getDefaultPort()); if(!bookmark.getProtocol().isHostnameConfigurable()) { bookmark.setHostname(selected.getDefaultHostname()); bookmark.setHostname(selected.getDefaultHostname()); bookmark.setHostname(selected.getDefaultHostname()); if(Objects.equals(bookmark.getDefaultPath(), bookmark.getProtocol().getDefaultPath()) || !selected.isPathConfigurable()) { bookmark.setDefaultPath(selected.getDefaultPath()); bookmark.setProtocol(selected); final int port = HostnameConfiguratorFactory.get(selected).getPort(bookmark.getHostname()); if(port != -1) { bookmark.setPort(port);
@Override public String getEndpoint() { return host.getHostname(); } }.createSignedUrlUsingSignatureVersion(
private void read(final ProtocolFactory protocols, final String entry) { final Host current = new Host(protocols.forScheme(Scheme.ftp)); current.getCredentials().setUsername( PreferencesFactory.get().getProperty("connection.login.anon.name")); for(String attribute : entry.split(", ")) { switch(name) { case "host": current.setHostname(value); break; case "port": try { current.setPort(Integer.parseInt(value)); current.setDefaultPath(value); break; case "webhost": current.setWebURL(value); break; case "encoding": current.setEncoding(value); break; case "notes": current.setComment(value); break; case "account": current.setNickname(value); break; case "privatekey": current.getCredentials().setIdentity(LocalFactory.get(value));
public MantaSession(final Host host, final X509TrustManager trust, final X509KeyManager key) { super(host, new ThreadLocalHostnameDelegatingTrustManager(new DisabledX509TrustManager(), host.getHostname()), key); config = new AuthAwareConfigContext(new ChainedConfigContext( new DefaultsConfigContext(), new StandardConfigContext() .setNoAuth(true) .setMantaKeyPath(null) .setHttpsProtocols(PreferencesFactory.get().getProperty("connection.ssl.protocols")) .setDisableNativeSignatures(true) .setMantaUser(host.getCredentials().getUsername()) .setMantaURL(String.format("%s://%s", host.getProtocol().getScheme().name(), host.getHostname())) )); }
connection.setRemoteCharset(Charset.forName(host.getEncoding())); disconnectListener = new StateDisconnectListener(); final Transport transport = connection.getTransport(); transport.setDisconnectListener(disconnectListener); connection.connect(HostnameConfiguratorFactory.get(host.getProtocol()).getHostname(host.getHostname()), host.getPort()); final KeepAlive keepalive = connection.getConnection().getKeepAlive(); keepalive.setKeepAliveInterval(preferences.getInteger("ssh.heartbeat.seconds"));
final Host host = new Host(protocols.forScheme(Scheme.ftp), server); final String port = bookmark.stringForKey("Port"); if(StringUtils.isNotBlank(port)) { host.setPort(Integer.parseInt(port)); host.setDefaultPath(path); host.setNickname(name); host.getCredentials().setUsername(user); host.getCredentials().setUsername( PreferencesFactory.get().getProperty("connection.login.anon.name")); if(StringUtils.isNotBlank(mode)) { if("Passive".equals(mode)) { host.setFTPConnectMode(FTPConnectMode.passive); host.setFTPConnectMode(FTPConnectMode.active); switch(Integer.parseInt(protocol)) { case 0: host.setProtocol(protocols.forScheme(Scheme.ftp)); break; case 1: host.setProtocol(protocols.forScheme(Scheme.sftp)); break; case 3: host.setProtocol(protocols.forScheme(Scheme.s3));
current.setHostname(elementText); break; case "Protocol": switch(Integer.parseInt(elementText)) { case 1: current.setProtocol(protocols.forScheme(Scheme.ftp)); break; case 2: case 3: current.setProtocol(protocols.forScheme(Scheme.ftps)); break; case 4: current.setProtocol(protocols.forScheme(Scheme.sftp)); break; current.setPort(-1); case "Port": try { current.setPort(Integer.parseInt(elementText)); case "LastConnect": try { current.setTimestamp(new ISO8601DateParser().parse(elementText)); current.getCredentials().setUsername(elementText); break; case "Name":
switch(name) { case "Host": current.setHostname(elementText); break; case "Protocol": switch(Integer.parseInt(elementText)) { case 0: current.setProtocol(protocols.forScheme(Scheme.ftp)); break; case 3: case 4: current.setProtocol(protocols.forScheme(Scheme.ftps)); break; case 1: current.setProtocol(protocols.forScheme(Scheme.sftp)); break; current.setPort(-1); case "Port": try { current.setPort(Integer.parseInt(elementText)); current.getCredentials().setUsername(elementText); break; case "Logontype": switch(Integer.parseInt(elementText)) {
protected boolean userIsOwner() { final MantaAccountHomeInfo account = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath()); return StringUtils.equals(host.getCredentials().getUsername(), account.getAccountOwner()); }
@Override public Set<Name> getLocations() { if(StringUtils.isNotBlank(session.getHost().getRegion())) { return Collections.singleton(new S3Region(session.getHost().getRegion())); } // Only for AWS if(session.getHost().getHostname().endsWith(PreferencesFactory.get().getProperty("s3.hostname.default"))) { return session.getHost().getProtocol().getRegions(); } return Collections.emptySet(); }
@Override public int compare(Host o1, Host o2) { return comparator.compare(o1.getProtocol().getIdentifier(), o2.getProtocol().getIdentifier()); } });
@Override public void change(final Host bookmark) { updateField(hostField, bookmark.getHostname()); hostField.setEnabled(bookmark.getProtocol().isHostnameConfigurable()); hostField.cell().setPlaceholderString(bookmark.getProtocol().getDefaultHostname()); } });
@Override public boolean accept(Host host) { return StringUtils.lowerCase(BookmarkNameProvider.toString(host)).contains(searchString.toLowerCase(Locale.ROOT)) || ((null != host.getComment()) && StringUtils.lowerCase(host.getComment()).contains(searchString.toLowerCase(Locale.ROOT))) || ((null != host.getCredentials().getUsername()) && StringUtils.lowerCase(host.getCredentials().getUsername()).contains(searchString.toLowerCase(Locale.ROOT))) || StringUtils.lowerCase(host.getHostname()).contains(searchString.toLowerCase(Locale.ROOT)); } });