use of org.apache.http.auth.NTCredentials in project manifoldcf by apache.
the class SharePointAuthority method getSharePointSession.
protected void getSharePointSession() throws ManifoldCFException {
if (proxy == null) {
// Set up server URL
try {
if (serverPortString == null || serverPortString.length() == 0) {
if (serverProtocol.equals("https"))
this.serverPort = 443;
else
this.serverPort = 80;
} else
this.serverPort = Integer.parseInt(serverPortString);
} catch (NumberFormatException e) {
throw new ManifoldCFException(e.getMessage(), e);
}
int proxyPort = 8080;
if (proxyPortString != null && proxyPortString.length() > 0) {
try {
proxyPort = Integer.parseInt(proxyPortString);
} catch (NumberFormatException e) {
throw new ManifoldCFException(e.getMessage(), e);
}
}
serverUrl = serverProtocol + "://" + serverName;
if (serverProtocol.equals("https")) {
if (serverPort != 443)
serverUrl += ":" + Integer.toString(serverPort);
} else {
if (serverPort != 80)
serverUrl += ":" + Integer.toString(serverPort);
}
fileBaseUrl = serverUrl + encodedServerLocation;
int connectionTimeout = 60000;
int socketTimeout = 900000;
// Set up ssl if indicated
SSLConnectionSocketFactory myFactory = null;
if (keystoreData != null) {
keystoreManager = KeystoreManagerFactory.make("", keystoreData);
myFactory = new SSLConnectionSocketFactory(keystoreManager.getSecureSocketFactory(), new DefaultHostnameVerifier());
} else {
myFactory = SSLConnectionSocketFactory.getSocketFactory();
}
PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", myFactory).build());
poolingConnectionManager.setDefaultMaxPerRoute(1);
poolingConnectionManager.setValidateAfterInactivity(2000);
poolingConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build());
connectionManager = poolingConnectionManager;
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
if (strippedUserName != null) {
credentialsProvider.setCredentials(new AuthScope(serverName, serverPort), new NTCredentials(strippedUserName, password, currentHost, ntlmDomain));
}
RequestConfig.Builder requestBuilder = RequestConfig.custom().setCircularRedirectsAllowed(true).setSocketTimeout(socketTimeout).setExpectContinueEnabled(false).setConnectTimeout(connectionTimeout).setConnectionRequestTimeout(socketTimeout);
// If there's a proxy, set that too.
if (proxyHost != null && proxyHost.length() > 0) {
// Configure proxy authentication
if (proxyUsername != null && proxyUsername.length() > 0) {
if (proxyPassword == null)
proxyPassword = "";
if (proxyDomain == null)
proxyDomain = "";
credentialsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUsername, proxyPassword, currentHost, proxyDomain));
}
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
requestBuilder.setProxy(proxy);
}
HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager).disableAutomaticRetries().setDefaultRequestConfig(requestBuilder.build()).setDefaultCredentialsProvider(credentialsProvider);
builder.setRequestExecutor(new HttpRequestExecutor(socketTimeout)).setRedirectStrategy(new LaxRedirectStrategy());
httpClient = builder.build();
proxy = new SPSProxyHelper(serverUrl, encodedServerLocation, serverLocation, serverUserName, password, org.apache.manifoldcf.connectorcommon.common.CommonsHTTPSender.class, "client-config.wsdd", httpClient, isClaimSpace);
}
sharepointSessionTimeout = System.currentTimeMillis() + SharePointExpirationInterval;
}
use of org.apache.http.auth.NTCredentials in project manifoldcf by apache.
the class RocketChatSession method addProxySettings.
private void addProxySettings(RequestConfig.Builder requestBuilder, ProxySettings proxySettingsOrNull) {
if (proxySettingsOrNull.hasUsername()) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(proxySettingsOrNull.getHost(), proxySettingsOrNull.getPort()), new NTCredentials(proxySettingsOrNull.getUsername(), (proxySettingsOrNull.getPassword() == null) ? "" : proxySettingsOrNull.getPassword(), currentHost, (proxySettingsOrNull.getDomain() == null) ? "" : proxySettingsOrNull.getDomain()));
}
HttpHost proxy = new HttpHost(proxySettingsOrNull.getHost(), proxySettingsOrNull.getPort());
requestBuilder.setProxy(proxy);
}
use of org.apache.http.auth.NTCredentials in project manifoldcf by apache.
the class WikiConnector method getSession.
protected void getSession() throws ManifoldCFException, ServiceInterruption {
if (hasBeenSetup == false) {
String emailAddress = params.getParameter(WikiConfig.PARAM_EMAIL);
if (emailAddress != null)
userAgent = "Mozilla/5.0 (ApacheManifoldCFWikiReader; " + ((emailAddress == null) ? "" : emailAddress) + ")";
else
userAgent = null;
String protocol = params.getParameter(WikiConfig.PARAM_PROTOCOL);
if (protocol == null || protocol.length() == 0)
protocol = "http";
String portString = params.getParameter(WikiConfig.PARAM_PORT);
if (portString == null || portString.length() == 0)
portString = null;
String path = params.getParameter(WikiConfig.PARAM_PATH);
if (path == null)
path = "/w";
baseURL = protocol + "://" + server + ((portString != null) ? ":" + portString : "") + path + "/api.php?format=xml&";
int socketTimeout = 900000;
int connectionTimeout = 300000;
javax.net.ssl.SSLSocketFactory httpsSocketFactory = KeystoreManagerFactory.getTrustingSecureSocketFactory();
SSLConnectionSocketFactory myFactory = new SSLConnectionSocketFactory(new InterruptibleSocketFactory(httpsSocketFactory, connectionTimeout), NoopHostnameVerifier.INSTANCE);
// Set up connection manager
PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", myFactory).build());
poolingConnectionManager.setDefaultMaxPerRoute(1);
poolingConnectionManager.setValidateAfterInactivity(2000);
poolingConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build());
connectionManager = poolingConnectionManager;
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
if (accessUser != null && accessUser.length() > 0 && accessPassword != null) {
Credentials credentials = new UsernamePasswordCredentials(accessUser, accessPassword);
if (accessRealm != null && accessRealm.length() > 0)
credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, accessRealm), credentials);
else
credentialsProvider.setCredentials(AuthScope.ANY, credentials);
}
RequestConfig.Builder requestBuilder = RequestConfig.custom().setCircularRedirectsAllowed(true).setSocketTimeout(socketTimeout).setExpectContinueEnabled(true).setConnectTimeout(connectionTimeout).setConnectionRequestTimeout(socketTimeout);
// If there's a proxy, set that too.
if (proxyHost != null && proxyHost.length() > 0) {
int proxyPortInt;
if (proxyPort != null && proxyPort.length() > 0) {
try {
proxyPortInt = Integer.parseInt(proxyPort);
} catch (NumberFormatException e) {
throw new ManifoldCFException("Bad number: " + e.getMessage(), e);
}
} else
proxyPortInt = 8080;
// Configure proxy authentication
if (proxyUsername != null && proxyUsername.length() > 0) {
if (proxyPassword == null)
proxyPassword = "";
if (proxyDomain == null)
proxyDomain = "";
credentialsProvider.setCredentials(new AuthScope(proxyHost, proxyPortInt), new NTCredentials(proxyUsername, proxyPassword, currentHost, proxyDomain));
}
HttpHost proxy = new HttpHost(proxyHost, proxyPortInt);
requestBuilder.setProxy(proxy);
}
httpClient = HttpClients.custom().setConnectionManager(connectionManager).disableAutomaticRetries().setDefaultRequestConfig(requestBuilder.build()).setDefaultCredentialsProvider(credentialsProvider).setSSLSocketFactory(myFactory).setRequestExecutor(new HttpRequestExecutor(socketTimeout)).build();
/*
BasicHttpParams params = new BasicHttpParams();
params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE,true);
params.setIntParameter(CoreProtocolPNames.WAIT_FOR_CONTINUE,socketTimeout);
params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY,true);
params.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK,true);
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,socketTimeout);
params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,connectionTimeout);
params.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS,true);
DefaultHttpClient localHttpClient = new DefaultHttpClient(connectionManager,params);
// No retries
localHttpClient.setHttpRequestRetryHandler(new HttpRequestRetryHandler()
{
public boolean retryRequest(
IOException exception,
int executionCount,
HttpContext context)
{
return false;
}
});
*/
loginToAPI();
hasBeenSetup = true;
}
}
use of org.apache.http.auth.NTCredentials in project manifoldcf by apache.
the class CswsConnector method getSession.
protected void getSession() throws ManifoldCFException, ServiceInterruption {
getSessionParameters();
if (hasConnected == false) {
int socketTimeout = 900000;
int connectionTimeout = 300000;
// Set up ingest ssl if indicated
final SSLConnectionSocketFactory myFactory;
final javax.net.ssl.SSLSocketFactory mySslFactory;
if (serverHTTPSKeystore != null) {
mySslFactory = new InterruptibleSocketFactory(serverHTTPSKeystore.getSecureSocketFactory(), connectionTimeout);
myFactory = new SSLConnectionSocketFactory(mySslFactory, NoopHostnameVerifier.INSTANCE);
} else {
mySslFactory = null;
myFactory = SSLConnectionSocketFactory.getSocketFactory();
}
// Set up connection manager
PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", myFactory).build());
poolingConnectionManager.setDefaultMaxPerRoute(1);
poolingConnectionManager.setValidateAfterInactivity(2000);
poolingConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build());
connectionManager = poolingConnectionManager;
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
// Set up authentication to use
if (serverHTTPNTLMDomain != null) {
credentialsProvider.setCredentials(AuthScope.ANY, new NTCredentials(serverHTTPNTLMUsername, serverHTTPNTLMPassword, currentHost, serverHTTPNTLMDomain));
}
HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager).disableAutomaticRetries().setDefaultRequestConfig(RequestConfig.custom().setCircularRedirectsAllowed(true).setSocketTimeout(socketTimeout).setExpectContinueEnabled(true).setConnectTimeout(connectionTimeout).setConnectionRequestTimeout(socketTimeout).build()).setDefaultCredentialsProvider(credentialsProvider).setRequestExecutor(new HttpRequestExecutor(socketTimeout)).setRedirectStrategy(new LaxRedirectStrategy());
httpClient = builder.build();
// Construct the various URLs we need
final String baseURL = serverProtocol + "://" + serverName + ":" + serverPort;
final String authenticationServiceURL = baseURL + authenticationServicePath;
final String documentManagementServiceURL = baseURL + documentManagementServicePath;
final String contentServiceServiceURL = baseURL + contentServiceServicePath;
final String memberServiceServiceURL = baseURL + memberServiceServicePath;
final String searchServiceServiceURL = baseURL + searchServiceServicePath;
// Build web services connection management object
if (Logging.connectors.isDebugEnabled()) {
String passwordExists = (serverPassword != null && serverPassword.length() > 0) ? "password exists" : "";
Logging.connectors.debug("Csws: Csws Session: Server='" + serverName + "'; port='" + serverPort + "'; user name='" + serverUsername + "'; " + passwordExists);
}
// Construct a new csws session object for setting up this session
cswsSession = new CswsSession(serverUsername, serverPassword, serverHTTPSKeystore, 1000L * 60L * 15L, authenticationServiceURL, documentManagementServiceURL, contentServiceServiceURL, memberServiceServiceURL, searchServiceServiceURL);
final GetSessionThread t = new GetSessionThread();
try {
t.start();
t.finishUp();
hasConnected = true;
} catch (InterruptedException e) {
t.interrupt();
throw new ManifoldCFException("Interrupted: " + e.getMessage(), e, ManifoldCFException.INTERRUPTED);
}
}
expirationTime = System.currentTimeMillis() + expirationInterval;
}
use of org.apache.http.auth.NTCredentials in project manifoldcf by apache.
the class LivelinkConnector method getSession.
protected void getSession() throws ManifoldCFException, ServiceInterruption {
getSessionParameters();
if (hasConnected == false) {
int socketTimeout = 900000;
int connectionTimeout = 300000;
// Set up ingest ssl if indicated
SSLConnectionSocketFactory myFactory = null;
if (ingestKeystoreManager != null) {
myFactory = new SSLConnectionSocketFactory(new InterruptibleSocketFactory(ingestKeystoreManager.getSecureSocketFactory(), connectionTimeout), NoopHostnameVerifier.INSTANCE);
} else {
myFactory = SSLConnectionSocketFactory.getSocketFactory();
}
// Set up connection manager
PoolingHttpClientConnectionManager poolingConnectionManager = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", myFactory).build());
poolingConnectionManager.setDefaultMaxPerRoute(1);
poolingConnectionManager.setValidateAfterInactivity(2000);
poolingConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build());
connectionManager = poolingConnectionManager;
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
// Set up authentication to use
if (ingestNtlmDomain != null) {
credentialsProvider.setCredentials(AuthScope.ANY, new NTCredentials(ingestNtlmUsername, ingestNtlmPassword, currentHost, ingestNtlmDomain));
}
HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager).disableAutomaticRetries().setDefaultRequestConfig(RequestConfig.custom().setCircularRedirectsAllowed(true).setSocketTimeout(socketTimeout).setExpectContinueEnabled(true).setConnectTimeout(connectionTimeout).setConnectionRequestTimeout(socketTimeout).build()).setDefaultCredentialsProvider(credentialsProvider).setRequestExecutor(new HttpRequestExecutor(socketTimeout)).setRedirectStrategy(new LaxRedirectStrategy());
httpClient = builder.build();
// System.out.println("Connection server object = "+llServer.toString());
// Establish the actual connection
int sanityRetryCount = FAILURE_RETRY_COUNT;
while (true) {
GetSessionThread t = new GetSessionThread();
try {
t.start();
t.finishUp();
hasConnected = true;
break;
} catch (InterruptedException e) {
t.interrupt();
throw new ManifoldCFException("Interrupted: " + e.getMessage(), e, ManifoldCFException.INTERRUPTED);
} catch (RuntimeException e2) {
sanityRetryCount = handleLivelinkRuntimeException(e2, sanityRetryCount, true);
}
}
}
expirationTime = System.currentTimeMillis() + expirationInterval;
}
Aggregations