use of ch.cyberduck.core.Credentials in project cyberduck by iterate-ch.
the class MicrosoftIISDAVLockFeatureTest method testLock.
@Test
public void testLock() throws Exception {
final Host host = new Host(new DAVProtocol(), "winbuild.iterate.ch", new Credentials(System.getProperties().getProperty("webdav.iis.user"), System.getProperties().getProperty("webdav.iis.password")));
host.setDefaultPath("/WebDAV");
final DAVSession session = new DAVSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager());
session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback());
final TransferStatus status = new TransferStatus();
final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
final byte[] content = "test".getBytes(StandardCharsets.UTF_8);
final OutputStream out = local.getOutputStream(false);
IOUtils.write(content, out);
out.close();
status.setLength(content.length);
final Path test = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final HttpUploadFeature upload = new DAVUploadFeature(session);
upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledConnectionCallback());
final String lock = new DAVLockFeature(session).lock(test);
assertTrue(new MicrosoftIISDAVFindFeature(session).find(test));
final PathAttributes attributes = new MicrosoftIISDAVListService(session, new MicrosoftIISDAVAttributesFinderFeature(session)).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes();
assertEquals(content.length, attributes.getSize(), 0L);
assertEquals(content.length, new DAVWriteFeature(session).append(test, status.withRemote(attributes)).size, 0L);
{
final byte[] buffer = new byte[content.length];
IOUtils.readFully(new MicrosoftIISDAVReadFeature(session).read(test, new TransferStatus(), new DisabledConnectionCallback()), buffer);
assertArrayEquals(content, buffer);
}
{
final byte[] buffer = new byte[content.length - 1];
final InputStream in = new MicrosoftIISDAVReadFeature(session).read(test, new TransferStatus().withLength(content.length - 1L).append(true).withOffset(1L), new DisabledConnectionCallback());
IOUtils.readFully(in, buffer);
in.close();
final byte[] reference = new byte[content.length - 1];
System.arraycopy(content, 1, reference, 0, content.length - 1);
assertArrayEquals(reference, buffer);
}
new DAVLockFeature(session).unlock(test, lock);
new DAVDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.Credentials in project cyberduck by iterate-ch.
the class MicrosoftIISDAVReadFeatureTest method testReadMicrosoft.
@Test
public void testReadMicrosoft() throws Exception {
final Host host = new Host(new DAVProtocol(), "winbuild.iterate.ch", new Credentials(System.getProperties().getProperty("webdav.iis.user"), System.getProperties().getProperty("webdav.iis.password")));
host.setDefaultPath("/WebDAV");
final DAVSession session = new DAVSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager());
session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback());
final Path test = new DAVTouchFeature(session).touch(new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
final byte[] content = RandomUtils.nextBytes(1023);
final OutputStream out = local.getOutputStream(false);
assertNotNull(out);
IOUtils.write(content, out);
out.close();
new DAVUploadFeature(session).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
assertTrue(new MicrosoftIISDAVFindFeature(session).find(test));
assertEquals(content.length, new MicrosoftIISDAVListService(session, new MicrosoftIISDAVAttributesFinderFeature(session)).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize(), 0L);
final TransferStatus status = new TransferStatus();
status.setLength(-1L);
final InputStream in = new MicrosoftIISDAVReadFeature(session).read(test, status, new DisabledConnectionCallback());
assertNotNull(in);
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
new StreamCopier(status, status).transfer(in, buffer);
final byte[] reference = new byte[content.length];
System.arraycopy(content, 0, reference, 0, content.length);
assertArrayEquals(reference, buffer.toByteArray());
in.close();
new DAVDeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.Credentials in project cyberduck by iterate-ch.
the class TerminalLoginService method validate.
@Override
public void validate(final Host bookmark, final String message, final LoginCallback prompt, final LoginOptions options) throws LoginCanceledException, LoginFailureException {
final Credentials credentials = bookmark.getCredentials();
if (input.hasOption(TerminalOptionsBuilder.Params.anonymous.name())) {
credentials.setUsername(PreferencesFactory.get().getProperty("connection.login.anon.name"));
}
if (input.hasOption(TerminalOptionsBuilder.Params.username.name())) {
credentials.setUsername(input.getOptionValue(TerminalOptionsBuilder.Params.username.name()));
}
if (input.hasOption(TerminalOptionsBuilder.Params.password.name())) {
credentials.setPassword(input.getOptionValue(TerminalOptionsBuilder.Params.password.name()));
}
if (input.hasOption(TerminalOptionsBuilder.Params.identity.name())) {
credentials.setIdentity(LocalFactory.get(input.getOptionValue(TerminalOptionsBuilder.Params.identity.name())));
}
if (StringUtils.isNotBlank(credentials.getUsername()) && StringUtils.isNotBlank(credentials.getPassword())) {
return;
}
super.validate(bookmark, message, prompt, options);
}
use of ch.cyberduck.core.Credentials in project cyberduck by iterate-ch.
the class TerminalPasswordCallback method prompt.
@Override
public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException {
console.printf("%n%s", new StringAppender().append(title).append(reason));
try {
final char[] input = console.readPassword("%n%s: ", options.getPasswordPlaceholder());
final Credentials credentials = new Credentials();
credentials.setPassword(StringUtils.strip(String.valueOf(input)));
return this.prompt(options, credentials);
} catch (ConnectionCanceledException e) {
throw new LoginCanceledException(e);
}
}
use of ch.cyberduck.core.Credentials in project cyberduck by iterate-ch.
the class CommandLineUriParserTest method testProfile.
@Test
public void testProfile() throws Exception {
final CommandLineParser parser = new PosixParser();
final CommandLine input = parser.parse(new Options(), new String[] {});
final ProtocolFactory factory = new ProtocolFactory(new LinkedHashSet<>(Collections.singleton(new SwiftProtocol())));
factory.register(new ProfilePlistReader(factory).read(this.getClass().getResourceAsStream("/Rackspace US.cyberduckprofile")));
assertEquals(0, new Host(factory.forName("rackspace"), "identity.api.rackspacecloud.com", 443, "/cdn.cyberduck.ch", new Credentials("u", null)).compareTo(new CommandLineUriParser(input, factory).parse("rackspace://u@cdn.cyberduck.ch/")));
}
Aggregations