Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing smb protocol support #186

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
07873be
Started work on SMBJ adding
hierynomus Jul 28, 2016
dd6235f
Refactoring code to segregate remote process and data connections
adityakalia Aug 4, 2016
5cc081f
Implementing telnet, winrm, winrs connections connections for smb2
adityakalia Aug 7, 2016
e7612c9
Implementing test cases
adityakalia Aug 8, 2016
62067aa
Refactoring
adityakalia Aug 10, 2016
9ced219
Refactoring code
adityakalia Aug 10, 2016
7685d88
Reverting connection configuration
adityakalia Aug 10, 2016
371716c
Updating protocol case
adityakalia Aug 10, 2016
5e57970
Refactoring
adityakalia Aug 22, 2016
8ba25ab
temp change to validate winssh connection for itest failures
adityakalia Aug 23, 2016
e206376
Fixing test cases
adityakalia Aug 23, 2016
a4bd156
Revert "Fixing test cases"
adityakalia Sep 2, 2016
56128a3
Revert "temp change to validate winssh connection for itest failures"
adityakalia Sep 2, 2016
2152bb6
Revert "Refactoring"
adityakalia Sep 2, 2016
4fbbb85
Fixing bug in delete logic
adityakalia Sep 2, 2016
bd244ac
Add bouncy castle provider if does not exist
adityakalia Sep 2, 2016
8704cde
Minor fixes
adityakalia Sep 2, 2016
093225a
Refactoring
adityakalia Sep 6, 2016
30ece60
adding test cases for domain
adityakalia Sep 7, 2016
8b9bad2
Fixing issue
adityakalia Sep 7, 2016
5173960
DEPL-10110 Added fix for checking access mask.
Sep 7, 2016
d137222
DEPL-10110 removed eager connection from SmbTelnet and SmbWinrm conne…
Sep 9, 2016
41c97a4
Refactoring test cases
adityakalia Sep 9, 2016
dfacfad
Refactoring test cases
adityakalia Sep 9, 2016
5b6b1ed
DEPL-10110 fixed getFile to create a connection lazily at the time of…
Sep 9, 2016
f643c28
DEPL-10110 fixed checkAccessMask and file close on share.
Sep 13, 2016
8a35699
Fixing headers
adityakalia Sep 15, 2016
d0be4e2
Updating implementation for canRead, canWrite
adityakalia Sep 15, 2016
9576663
Running tests selectively
adityakalia Sep 15, 2016
2d98519
Running tests selectively
adityakalia Sep 15, 2016
5e4e06d
Running smb tests only
adityakalia Sep 15, 2016
0e82325
wip
adityakalia Sep 15, 2016
68d1582
wip
adityakalia Sep 15, 2016
6421d78
wip
adityakalia Sep 15, 2016
ce59b39
wip
adityakalia Sep 15, 2016
01f64fa
wip
adityakalia Sep 16, 2016
e4f1047
Fixing winrm domain controller config for tests
adityakalia Sep 18, 2016
6170e1b
fixing build
adityakalia Sep 18, 2016
567aacd
Re-implementing flush method for Output stream
adityakalia Sep 19, 2016
5e03e1d
Updating smbj version
adityakalia Sep 19, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ dependencies {
// CIFS
compile 'jcifs:jcifs:1.3.17'

// SMB2/3
compile 'com.hierynomus:smbj:0.0.5'
compile 'net.engio:mbassador:1.2.4.2'
compile "org.bouncycastle:bcprov-jdk15on:1.54"
compile "org.bouncycastle:bcpkix-jdk15on:1.54"

// Telnet
compile 'commons-net:commons-net:3.3'

Expand Down
23 changes: 1 addition & 22 deletions src/main/java/com/xebialabs/overthere/cifs/CifsConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,8 @@
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.CIFS_PORT;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.CONNECTION_TYPE;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.CIFS_PORT_DEFAULT;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.PORT_DEFAULT_TELNET;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_ENABLE_HTTPS_DEFAULT;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.PORT_DEFAULT_WINRM_HTTPS;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.PORT_DEFAULT_WINRM_HTTP;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.PATH_SHARE_MAPPINGS;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.PATH_SHARE_MAPPINGS_DEFAULT;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.WINRM_ENABLE_HTTPS;
import static java.net.InetSocketAddress.createUnresolved;

/**
Expand Down Expand Up @@ -98,7 +93,7 @@ public CifsConnection(String protocol, ConnectionOptions options, AddressPortMap
throw new IllegalArgumentException("Cannot open a cifs:" + cifsConnectionType.toString().toLowerCase() + ": connection through an HTTP proxy");
}
this.unmappedAddress = options.get(ADDRESS);
this.unmappedPort = options.get(PORT, getDefaultPort(options));
this.unmappedPort = options.get(PORT, this.cifsConnectionType.getDefaultPort(options));
InetSocketAddress addressPort = mapper.map(createUnresolved(unmappedAddress, unmappedPort));
this.address = addressPort.getHostName();
this.port = addressPort.getPort();
Expand All @@ -111,22 +106,6 @@ public CifsConnection(String protocol, ConnectionOptions options, AddressPortMap
this.authentication = new NtlmPasswordAuthentication(null, username, password);
}

private int getDefaultPort(ConnectionOptions options) {
switch (cifsConnectionType) {
case TELNET:
return PORT_DEFAULT_TELNET;
case WINRM_INTERNAL:
case WINRM_NATIVE:
if (!options.getBoolean(WINRM_ENABLE_HTTPS, WINRM_ENABLE_HTTPS_DEFAULT)) {
return PORT_DEFAULT_WINRM_HTTP;
} else {
return PORT_DEFAULT_WINRM_HTTPS;
}
default:
throw new IllegalArgumentException("Unknown CIFS connection type " + cifsConnectionType);
}
}

protected abstract void connect();

@Override
Expand Down
210 changes: 1 addition & 209 deletions src/main/java/com/xebialabs/overthere/cifs/CifsConnectionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,18 @@
import com.xebialabs.overthere.spi.Protocol;

import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.CIFS_PROTOCOL;
import static com.xebialabs.overthere.cifs.WinrmHttpsCertificateTrustStrategy.STRICT;
import static com.xebialabs.overthere.cifs.WinrmHttpsHostnameVerificationStrategy.BROWSER_COMPATIBLE;
import static com.xebialabs.overthere.local.LocalConnection.LOCAL_PROTOCOL;

/**
* Builds CIFS connections.
*/
@Protocol(name = CIFS_PROTOCOL)
public class CifsConnectionBuilder implements OverthereConnectionBuilder {
public class CifsConnectionBuilder extends ConnectionBuilder implements OverthereConnectionBuilder {

/**
* Name of the protocol handled by this connection builder, i.e. "cifs".
*/
public static final String CIFS_PROTOCOL = "cifs";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_connectionType">the online documentation</a>
*/
public static final String CONNECTION_TYPE = "connectionType";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_connectionType">the online documentation</a>
*/
public static final int PORT_DEFAULT_TELNET = 23;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_connectionType">the online documentation</a>
*/
public static final int PORT_DEFAULT_WINRM_HTTP = 5985;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_connectionType">the online documentation</a>
*/
public static final int PORT_DEFAULT_WINRM_HTTPS = 5986;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_cifsPort">the online documentation</a>
*/
Expand All @@ -80,191 +57,6 @@ public class CifsConnectionBuilder implements OverthereConnectionBuilder {
*/
public static final int CIFS_PORT_DEFAULT = 445;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_pathShareMappings">the online documentation</a>
*/
public static final String PATH_SHARE_MAPPINGS = "pathShareMappings";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_pathShareMappings">the online documentation</a>
*/
public static final Map<String, String> PATH_SHARE_MAPPINGS_DEFAULT = Collections.emptyMap();

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmEnableHttps">the online documentation</a>
*/
public static final String WINRM_ENABLE_HTTPS = "winrmEnableHttps";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmEnableHttps">the online documentation</a>
*/
public static final boolean WINRM_ENABLE_HTTPS_DEFAULT = false;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmContext">the online documentation</a>
*/
public static final String WINRM_CONTEXT = "winrmContext";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmContext">the online documentation</a>
*/
public static final String WINRM_CONTEXT_DEFAULT = "/wsman";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmEnvelopSize">the online documentation</a>
*/
public static final String WINRM_ENVELOP_SIZE = "winrmEnvelopSize";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmEnvelopSize">the online documentation</a>
*/
public static final int WINRM_ENVELOP_SIZE_DEFAULT = 153600;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmHttpsCertificateTrustStrategy">the online documentation</a>
*/
public static final String WINRM_HTTPS_CERTIFICATE_TRUST_STRATEGY = "winrmHttpsCertificateTrustStrategy";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmHttpsCertificateTrustStrategy">the online documentation</a>
*/
public static final WinrmHttpsCertificateTrustStrategy WINRM_HTTPS_CERTIFICATE_TRUST_STRATEGY_DEFAULT = STRICT;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmHttpsHostnameVerificationStrategy">the online documentation</a>
*/
public static final String WINRM_HTTPS_HOSTNAME_VERIFICATION_STRATEGY = "winrmHttpsHostnameVerificationStrategy";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmHttpsHostnameVerificationStrategy">the online documentation</a>
*/
public static final WinrmHttpsHostnameVerificationStrategy WINRM_HTTPS_HOSTNAME_VERIFICATION_STRATEGY_DEFAULT = BROWSER_COMPATIBLE;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmKerberosDebug">the online documentation</a>
*/
public static final String WINRM_KERBEROS_DEBUG = "winrmKerberosDebug";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmKerberosDebug">the online documentation</a>
*/
public static final boolean WINRM_KERBEROS_DEBUG_DEFAULT = false;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmKerberosTicketCache">the online documentation</a>
*/
public static final String WINRM_KERBEROS_TICKET_CACHE = "winrmKerberosTicketCache";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmKerberosTicketCache">the online documentation</a>
*/
public static final boolean WINRM_KERBEROS_TICKET_CACHE_DEFAULT = false;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmLocale">the online documentation</a>
*/
public static final String WINRM_LOCALE = "";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmLocale">the online documentation</a>
*/
public static final String WINRM_LOCALE_DEFAULT = "en-US";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmKerberosUseHttpSpn">the online documentation</a>
*/
public static final String WINRM_KERBEROS_USE_HTTP_SPN = "winrmKerberosUseHttpSpn";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmKerberosUseHttpSpn">the online documentation</a>
*/
public static final boolean WINRM_KERBEROS_USE_HTTP_SPN_DEFAULT = false;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmKerberosAddPortToSpn">the online documentation</a>
*/
public static final String WINRM_KERBEROS_ADD_PORT_TO_SPN = "winrmKerberosAddPortToSpn";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmKerberosAddPortToSpn">the online documentation</a>
*/
public static final boolean WINRM_KERBEROS_ADD_PORT_TO_SPN_DEFAULT = false;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmTimeout">the online documentation</a>
*/
public static final String WINRM_TIMEMOUT = "winrmTimeout";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrmTimeout">the online documentation</a>
*/
public static final String DEFAULT_WINRM_TIMEOUT = "PT60.000S";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsAllowDelegate">the online documentation</a>
*/
public static final String WINRS_ALLOW_DELEGATE = "winrsAllowDelegate";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsAllowDelegate">the online documentation</a>
*/
public static final boolean DEFAULT_WINRS_ALLOW_DELEGATE = false;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsCompression">the online documentation</a>
*/
public static final String WINRS_COMPRESSION = "winrsCompression";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsCompression">the online documentation</a>
*/
public static final boolean WINRS_COMPRESSION_DEFAULT = false;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsNoecho">the online documentation</a>
*/
public static final String WINRS_NOECHO = "winrsNoecho";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsNoecho">the online documentation</a>
*/
public static final boolean WINRS_NOECHO_DEFAULT = false;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsNoprofile">the online documentation</a>
*/
public static final String WINRS_NOPROFILE = "winrsNoprofile";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsNoprofile">the online documentation</a>
*/
public static final boolean WINRS_NOPROFILE_DEFAULT = false;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsProxyProtocol">the online documentation</a>
*/
public static final String WINRS_PROXY_PROTOCOL = "winrsProxyProtocol";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsProxyProtocol">the online documentation</a>
*/
public static final String WINRS_PROXY_PROTOCOL_DEFAULT = LOCAL_PROTOCOL;

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsProxyConnectionOptions">the online documentation</a>
*/
public static final String WINRS_PROXY_CONNECTION_OPTIONS = "winrsProxyConnectionOptions";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsUnencrypted">the online documentation</a>
*/
public static final String WINRS_UNENCRYPTED = "winrsUnencrypted";

/**
* See <a href="https://github.com/xebialabs/overthere/blob/master/README.md#cifs_winrsUnencrypted">the online documentation</a>
*/
public static final boolean WINRS_UNENCRYPTED_DEFAULT = false;

private CifsConnection connection;

public CifsConnectionBuilder(String type, ConnectionOptions options, AddressPortMapper mapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
*/
package com.xebialabs.overthere.cifs;

import com.xebialabs.overthere.ConnectionOptions;

import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.*;
import static com.xebialabs.overthere.cifs.CifsConnectionBuilder.PORT_DEFAULT_WINRM_HTTPS;

/**
* Enumeration of CIFS connection types.
*/
Expand All @@ -41,6 +46,22 @@ public enum CifsConnectionType {
* A CIFS connection to a Windows host that uses the <code>winrs</code> command native to Windows to execute commands.
* <em>N.B.:</em> This implementation only works when Overthere runs on Windows.
*/
WINRM_NATIVE
WINRM_NATIVE;

public int getDefaultPort(ConnectionOptions options) {
switch (this) {
case TELNET:
return PORT_DEFAULT_TELNET;
case WINRM_INTERNAL:
case WINRM_NATIVE:
if (!options.getBoolean(WINRM_ENABLE_HTTPS, WINRM_ENABLE_HTTPS_DEFAULT)) {
return PORT_DEFAULT_WINRM_HTTP;
} else {
return PORT_DEFAULT_WINRM_HTTPS;
}
default:
throw new IllegalArgumentException("Unknown CIFS connection type " + this);
}
}

}
Loading