Search in sources :

Example 21 with CredentialFactory

use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.

the class HttpSenderBase method configure.

public void configure() throws ConfigurationException {
    super.configure();
    if (!getMethodType().equals("POST")) {
        if (!isParamsInUrl()) {
            throw new ConfigurationException(getLogPrefix() + "paramsInUrl can only be set to false for methodType POST");
        }
        if (StringUtils.isNotEmpty(getInputMessageParam())) {
            throw new ConfigurationException(getLogPrefix() + "inputMessageParam can only be set for methodType POST");
        }
    }
    Builder requestConfig = RequestConfig.custom();
    requestConfig.setConnectTimeout(getTimeout());
    requestConfig.setConnectionRequestTimeout(getTimeout());
    requestConfig.setSocketTimeout(getTimeout());
    if (paramList != null) {
        paramList.configure();
        if (StringUtils.isNotEmpty(getUrlParam())) {
            urlParameter = paramList.findParameter(getUrlParam());
            addParameterToSkip(urlParameter);
        }
    }
    if (getMaxConnections() <= 0) {
        throw new ConfigurationException(getLogPrefix() + "maxConnections is set to [" + getMaxConnections() + "], which is not enough for adequate operation");
    }
    try {
        if (urlParameter == null) {
            if (StringUtils.isEmpty(getUrl())) {
                throw new ConfigurationException(getLogPrefix() + "url must be specified, either as attribute, or as parameter");
            }
            staticUri = getURI(getUrl());
        }
        URL certificateUrl = null;
        URL truststoreUrl = null;
        if (!StringUtils.isEmpty(getCertificate())) {
            certificateUrl = ClassUtils.getResourceURL(classLoader, getCertificate());
            if (certificateUrl == null) {
                throw new ConfigurationException(getLogPrefix() + "cannot find URL for certificate resource [" + getCertificate() + "]");
            }
            log.info(getLogPrefix() + "resolved certificate-URL to [" + certificateUrl.toString() + "]");
        }
        if (!StringUtils.isEmpty(getTruststore())) {
            truststoreUrl = ClassUtils.getResourceURL(classLoader, getTruststore());
            if (truststoreUrl == null) {
                throw new ConfigurationException(getLogPrefix() + "cannot find URL for truststore resource [" + getTruststore() + "]");
            }
            log.info(getLogPrefix() + "resolved truststore-URL to [" + truststoreUrl.toString() + "]");
        }
        if (certificateUrl != null || truststoreUrl != null || allowSelfSignedCertificates) {
            AuthSSLProtocolSocketFactoryBase socketfactory;
            try {
                CredentialFactory certificateCf = new CredentialFactory(getCertificateAuthAlias(), null, getCertificatePassword());
                CredentialFactory truststoreCf = new CredentialFactory(getTruststoreAuthAlias(), null, getTruststorePassword());
                if (isJdk13Compatibility()) {
                    socketfactory = new AuthSSLProtocolSocketFactoryForJsse10x(certificateUrl, certificateCf.getPassword(), getKeystoreType(), getKeyManagerAlgorithm(), truststoreUrl, truststoreCf.getPassword(), getTruststoreType(), getTrustManagerAlgorithm(), isAllowSelfSignedCertificates(), isVerifyHostname(), isIgnoreCertificateExpiredException());
                } else {
                    socketfactory = new AuthSSLProtocolSocketFactory(certificateUrl, certificateCf.getPassword(), getKeystoreType(), getKeyManagerAlgorithm(), truststoreUrl, truststoreCf.getPassword(), getTruststoreType(), getTrustManagerAlgorithm(), isAllowSelfSignedCertificates(), isVerifyHostname(), isIgnoreCertificateExpiredException());
                }
                if (StringUtils.isNotEmpty(getProtocol())) {
                    socketfactory.setProtocol(getProtocol());
                }
                socketfactory.initSSLContext();
                SSLContext sslContext = (SSLContext) socketfactory.sslContext;
                SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext);
                httpClientBuilder.setSSLSocketFactory(socketFactory);
            } catch (Throwable t) {
                throw new ConfigurationException(getLogPrefix() + "cannot create or initialize SocketFactory", t);
            }
        }
        credentials = new CredentialFactory(getAuthAlias(), getUserName(), getPassword());
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        if (!StringUtils.isEmpty(credentials.getUsername())) {
            String uname;
            if (StringUtils.isNotEmpty(getAuthDomain())) {
                uname = getAuthDomain() + "\\" + credentials.getUsername();
            } else {
                uname = credentials.getUsername();
            }
            credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(uname, credentials.getPassword()));
        }
        if (StringUtils.isNotEmpty(getProxyHost())) {
            HttpHost proxy = new HttpHost(getProxyHost(), getProxyPort());
            AuthScope scope = new AuthScope(proxy, getProxyRealm(), AuthScope.ANY_SCHEME);
            CredentialFactory pcf = new CredentialFactory(getProxyAuthAlias(), getProxyUserName(), getProxyPassword());
            if (StringUtils.isNotEmpty(pcf.getUsername())) {
                Credentials credentials = new UsernamePasswordCredentials(pcf.getUsername(), pcf.getPassword());
                credentialsProvider.setCredentials(scope, credentials);
            }
            log.trace("setting credentialProvider [" + credentialsProvider.toString() + "]");
            requestConfig.setProxy(proxy);
            requestConfig.setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC));
            AuthCache authCache = httpClientContext.getAuthCache();
            if (authCache == null)
                authCache = new BasicAuthCache();
            authCache.put(proxy, new BasicScheme());
            httpClientContext.setAuthCache(authCache);
            httpClientBuilder.setProxy(proxy);
        }
        httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
    } catch (URISyntaxException e) {
        throw new ConfigurationException(getLogPrefix() + "cannot interpret uri [" + getUrl() + "]");
    }
    if (StringUtils.isNotEmpty(getStyleSheetName())) {
        try {
            URL stylesheetURL = ClassUtils.getResourceURL(classLoader, getStyleSheetName());
            if (stylesheetURL == null) {
                throw new ConfigurationException(getLogPrefix() + "cannot find stylesheet [" + getStyleSheetName() + "]");
            }
            transformerPool = TransformerPool.getInstance(stylesheetURL);
        } catch (IOException e) {
            throw new ConfigurationException(getLogPrefix() + "cannot retrieve [" + getStyleSheetName() + "]", e);
        } catch (TransformerConfigurationException te) {
            throw new ConfigurationException(getLogPrefix() + "got error creating transformer from file [" + getStyleSheetName() + "]", te);
        }
    }
    httpClientBuilder.setDefaultRequestConfig(requestConfig.build());
}
Also used : BasicScheme(org.apache.http.impl.auth.BasicScheme) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Builder(org.apache.http.client.config.RequestConfig.Builder) URIBuilder(org.apache.http.client.utils.URIBuilder) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) AuthCache(org.apache.http.client.AuthCache) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) SSLContext(javax.net.ssl.SSLContext) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) URL(java.net.URL) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 22 with CredentialFactory

use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.

the class WebServiceNtlmSender method configure.

public void configure() throws ConfigurationException {
    super.configure();
    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, getTimeout());
    HttpConnectionParams.setSoTimeout(httpParameters, getTimeout());
    httpClient = new DefaultHttpClient(connectionManager, httpParameters);
    httpClient.getAuthSchemes().register("NTLM", new NTLMSchemeFactory());
    CredentialFactory cf = new CredentialFactory(getAuthAlias(), getUserName(), getPassword());
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new NTCredentials(cf.getUsername(), cf.getPassword(), Misc.getHostname(), getAuthDomain()));
    if (StringUtils.isNotEmpty(getProxyHost())) {
        HttpHost proxy = new HttpHost(getProxyHost(), getProxyPort());
        httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope) BasicHttpParams(org.apache.http.params.BasicHttpParams) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) NTCredentials(org.apache.http.auth.NTCredentials)

Example 23 with CredentialFactory

use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.

the class WebServiceSender method configure.

@Override
public void configure() throws ConfigurationException {
    super.configure();
    setMethodType("POST");
    setContentType("text/xml; charset=" + Misc.DEFAULT_INPUT_STREAM_ENCODING);
    if (isSoap()) {
    // ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
    // String msg = getLogPrefix()+"the use of attribute soap=true has been deprecated. Please change to SoapWrapperPipe";
    // configWarnings.add(log, msg);
    }
    soapWrapper = SoapWrapper.getInstance();
    if (paramList != null && StringUtils.isNotEmpty(getSoapActionParam())) {
        soapActionParameter = paramList.findParameter(getSoapActionParam());
        serviceNamespaceURIParameter = paramList.findParameter(getServiceNamespaceParam());
        addParameterToSkip(soapActionParameter);
        addParameterToSkip(serviceNamespaceURIParameter);
    }
    if (StringUtils.isNotEmpty(getWssAuthAlias()) || StringUtils.isNotEmpty(getWssUserName())) {
        wsscf = new CredentialFactory(getWssAuthAlias(), getWssUserName(), getWssPassword());
        log.debug(getLogPrefix() + "created CredentialFactory for username=[" + wsscf.getUsername() + "]");
    }
}
Also used : CredentialFactory(nl.nn.adapterframework.util.CredentialFactory)

Example 24 with CredentialFactory

use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.

the class AuthSSLProtocolSocketFactoryBase method createSocketFactory.

public static AuthSSLProtocolSocketFactoryBase createSocketFactory(final URL certificateUrl, final String certificateAuthAlias, final String certificatePassword, final String certificateType, final String keyManagerAlgorithm, final URL truststoreUrl, final String truststoreAuthAlias, final String truststorePassword, final String truststoreType, final String trustManagerAlgorithm, final boolean allowSelfSignedCertificates, final boolean verifyHostname, final boolean ignoreCertificateExpiredException, boolean jdk13Compatible) throws NoSuchAlgorithmException, KeyStoreException, GeneralSecurityException, IOException {
    CredentialFactory certificateCf = new CredentialFactory(certificateAuthAlias, null, certificatePassword);
    CredentialFactory truststoreCf = new CredentialFactory(truststoreAuthAlias, null, truststorePassword);
    AuthSSLProtocolSocketFactoryBase factory;
    if (jdk13Compatible) {
        addProvider("sun.security.provider.Sun");
        addProvider("com.sun.net.ssl.internal.ssl.Provider");
        System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
        factory = new AuthSSLProtocolSocketFactoryForJsse10x(certificateUrl, certificatePassword, certificateType, keyManagerAlgorithm, truststoreUrl, certificateCf.getPassword(), truststoreType, trustManagerAlgorithm, allowSelfSignedCertificates, verifyHostname, ignoreCertificateExpiredException);
    } else {
        factory = new AuthSSLProtocolSocketFactory(certificateUrl, certificatePassword, certificateType, keyManagerAlgorithm, truststoreUrl, truststoreCf.getPassword(), truststoreType, trustManagerAlgorithm, allowSelfSignedCertificates, verifyHostname, ignoreCertificateExpiredException);
    }
    return factory;
}
Also used : CredentialFactory(nl.nn.adapterframework.util.CredentialFactory)

Example 25 with CredentialFactory

use of nl.nn.adapterframework.util.CredentialFactory in project iaf by ibissource.

the class GetTibcoQueues method doPipeWithTimeoutGuarded.

public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
    String result;
    String url_work;
    String authAlias_work;
    String userName_work;
    String password_work;
    String queueName_work = null;
    ParameterValueList pvl = null;
    if (getParameterList() != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        try {
            pvl = prc.getValues(getParameterList());
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception on extracting parameters", e);
        }
    }
    url_work = getParameterValue(pvl, "url");
    if (url_work == null) {
        url_work = getUrl();
    }
    authAlias_work = getParameterValue(pvl, "authAlias");
    if (authAlias_work == null) {
        authAlias_work = getAuthAlias();
    }
    userName_work = getParameterValue(pvl, "userName");
    if (userName_work == null) {
        userName_work = getUserName();
    }
    password_work = getParameterValue(pvl, "password");
    if (password_work == null) {
        password_work = getPassword();
    }
    CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work);
    Connection connection = null;
    Session jSession = null;
    TibjmsAdmin admin = null;
    try {
        admin = TibcoUtils.getActiveServerAdmin(url_work, cf);
        if (admin == null) {
            throw new PipeRunException(this, "could not find an active server");
        }
        String ldapUrl = getParameterValue(pvl, "ldapUrl");
        LdapSender ldapSender = null;
        if (StringUtils.isNotEmpty(ldapUrl)) {
            ldapSender = retrieveLdapSender(ldapUrl, cf);
        }
        queueName_work = getParameterValue(pvl, "queueName");
        if (StringUtils.isNotEmpty(queueName_work)) {
            String countOnly_work = getParameterValue(pvl, "countOnly");
            boolean countOnly = ("true".equalsIgnoreCase(countOnly_work) ? true : false);
            if (countOnly) {
                return getQueueMessageCountOnly(admin, queueName_work);
            }
        }
        ConnectionFactory factory = new com.tibco.tibjms.TibjmsConnectionFactory(url_work);
        connection = factory.createConnection(cf.getUsername(), cf.getPassword());
        jSession = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
        if (StringUtils.isNotEmpty(queueName_work)) {
            String queueItem_work = getParameterValue(pvl, "queueItem");
            int qi;
            if (StringUtils.isNumeric(queueItem_work)) {
                qi = Integer.parseInt(queueItem_work);
            } else {
                qi = 1;
            }
            result = getQueueMessage(jSession, admin, queueName_work, qi, ldapSender);
        } else {
            String showAge_work = getParameterValue(pvl, "showAge");
            boolean showAge = ("true".equalsIgnoreCase(showAge_work) ? true : false);
            result = getQueuesInfo(jSession, admin, showAge, ldapSender);
        }
    } catch (Exception e) {
        String msg = getLogPrefix(session) + "exception on showing Tibco queues, url [" + url_work + "]" + (StringUtils.isNotEmpty(queueName_work) ? " queue [" + queueName_work + "]" : "");
        throw new PipeRunException(this, msg, e);
    } finally {
        if (admin != null) {
            try {
                admin.close();
            } catch (TibjmsAdminException e) {
                log.warn(getLogPrefix(session) + "exception on closing Tibjms Admin", e);
            }
        }
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                log.warn(getLogPrefix(session) + "exception on closing connection", e);
            }
        }
    }
    return result;
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) LdapSender(nl.nn.adapterframework.ldap.LdapSender) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) TibjmsAdmin(com.tibco.tibjms.admin.TibjmsAdmin) PipeRunException(nl.nn.adapterframework.core.PipeRunException) TibjmsAdminInvalidNameException(com.tibco.tibjms.admin.TibjmsAdminInvalidNameException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) UnknownHostException(java.net.UnknownHostException) JMSException(javax.jms.JMSException) TibjmsAdminException(com.tibco.tibjms.admin.TibjmsAdminException) ParameterException(nl.nn.adapterframework.core.ParameterException) ConnectionFactory(javax.jms.ConnectionFactory) TibjmsAdminException(com.tibco.tibjms.admin.TibjmsAdminException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Session(javax.jms.Session) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession)

Aggregations

CredentialFactory (nl.nn.adapterframework.util.CredentialFactory)33 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)11 IOException (java.io.IOException)9 URL (java.net.URL)9 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)4 ParameterException (nl.nn.adapterframework.core.ParameterException)4 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)4 GeneralSecurityException (java.security.GeneralSecurityException)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 ConnectionFactory (javax.jms.ConnectionFactory)3 JMSException (javax.jms.JMSException)3 Transformer (javax.xml.transform.Transformer)3 JmsException (nl.nn.adapterframework.jms.JmsException)3 TibjmsAdmin (com.tibco.tibjms.admin.TibjmsAdmin)2 TibjmsAdminException (com.tibco.tibjms.admin.TibjmsAdminException)2 URISyntaxException (java.net.URISyntaxException)2