Search in sources :

Example 16 with NTCredentials

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;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpRequestExecutor(org.apache.http.protocol.HttpRequestExecutor) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) NTCredentials(org.apache.http.auth.NTCredentials) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) DefaultHostnameVerifier(org.apache.http.conn.ssl.DefaultHostnameVerifier) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy)

Example 17 with NTCredentials

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);
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) NTCredentials(org.apache.http.auth.NTCredentials)

Example 18 with NTCredentials

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;
    }
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpRequestExecutor(org.apache.http.protocol.HttpRequestExecutor) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) NTCredentials(org.apache.http.auth.NTCredentials) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) NTCredentials(org.apache.http.auth.NTCredentials) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 19 with NTCredentials

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;
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpRequestExecutor(org.apache.http.protocol.HttpRequestExecutor) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) InterruptibleSocketFactory(org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) NTCredentials(org.apache.http.auth.NTCredentials) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) CswsSession(org.apache.manifoldcf.csws.CswsSession) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy)

Example 20 with NTCredentials

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;
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpRequestExecutor(org.apache.http.protocol.HttpRequestExecutor) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) InterruptibleSocketFactory(org.apache.manifoldcf.connectorcommon.common.InterruptibleSocketFactory) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) NTCredentials(org.apache.http.auth.NTCredentials) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) ConnectionSocketFactory(org.apache.http.conn.socket.ConnectionSocketFactory) PlainConnectionSocketFactory(org.apache.http.conn.socket.PlainConnectionSocketFactory) LaxRedirectStrategy(org.apache.http.impl.client.LaxRedirectStrategy)

Aggregations

NTCredentials (org.apache.http.auth.NTCredentials)58 AuthScope (org.apache.http.auth.AuthScope)38 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)30 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)27 CredentialsProvider (org.apache.http.client.CredentialsProvider)24 HttpHost (org.apache.http.HttpHost)20 Credentials (org.apache.http.auth.Credentials)20 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)10 RequestConfig (org.apache.http.client.config.RequestConfig)9 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)9 ConnectionSocketFactory (org.apache.http.conn.socket.ConnectionSocketFactory)8 PlainConnectionSocketFactory (org.apache.http.conn.socket.PlainConnectionSocketFactory)8 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)6 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)5 LaxRedirectStrategy (org.apache.http.impl.client.LaxRedirectStrategy)5 HttpRequestExecutor (org.apache.http.protocol.HttpRequestExecutor)5 AuthSchemeProvider (org.apache.http.auth.AuthSchemeProvider)4 AuthenticationException (org.apache.http.auth.AuthenticationException)4 InvalidCredentialsException (org.apache.http.auth.InvalidCredentialsException)4 BufferedHeader (org.apache.http.message.BufferedHeader)4