Search in sources :

Example 6 with CredentialFactory

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

the class CmisSender method connect.

private Session connect(String userName, String password) {
    log.debug(getLogPrefix() + "connecting with url [" + getUrl() + "] repository [" + getRepository() + "]");
    SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
    Map<String, String> parameter = new HashMap<String, String>();
    parameter.put(SessionParameter.USER, userName);
    parameter.put(SessionParameter.PASSWORD, password);
    if (getBindingType().equalsIgnoreCase("atompub")) {
        parameter.put(SessionParameter.ATOMPUB_URL, getUrl());
        parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
    } else if (getBindingType().equalsIgnoreCase("browser")) {
        parameter.put(SessionParameter.BROWSER_URL, getUrl());
        parameter.put(SessionParameter.BINDING_TYPE, BindingType.BROWSER.value());
    } else {
        parameter.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, getUrl() + "/RepositoryService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, getUrl() + "/NavigationService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, getUrl() + "/ObjectService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, getUrl() + "/VersioningService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, getUrl() + "/DiscoveryService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, getUrl() + "/RelationshipService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, getUrl() + "/MultiFilingService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, getUrl() + "/PolicyService.svc?wsdl");
        parameter.put(SessionParameter.WEBSERVICES_ACL_SERVICE, getUrl() + "/ACLService.svc?wsdl");
        parameter.put(SessionParameter.BINDING_TYPE, BindingType.WEBSERVICES.value());
    }
    parameter.put(SessionParameter.REPOSITORY_ID, getRepository());
    // SSL
    if (getCertificate() != null || getTruststore() != null || isAllowSelfSignedCertificates()) {
        CredentialFactory certificateCf = new CredentialFactory(getCertificateAuthAlias(), null, getCertificatePassword());
        CredentialFactory truststoreCf = new CredentialFactory(getTruststoreAuthAlias(), null, getTruststorePassword());
        parameter.put("certificateUrl", getCertificate());
        parameter.put("certificatePassword", certificateCf.getPassword());
        parameter.put("keystoreType", getKeystoreType());
        parameter.put("keyManagerAlgorithm", getKeyManagerAlgorithm());
        parameter.put("truststoreUrl", getTruststore());
        parameter.put("truststorePassword", truststoreCf.getPassword());
        parameter.put("truststoreType", getTruststoreType());
        parameter.put("trustManagerAlgorithm", getTrustManagerAlgorithm());
    }
    // SSL+
    parameter.put("isAllowSelfSignedCertificates", "" + isAllowSelfSignedCertificates());
    parameter.put("isVerifyHostname", "" + isVerifyHostname());
    parameter.put("isIgnoreCertificateExpiredException", "" + isIgnoreCertificateExpiredException());
    // PROXY
    if (StringUtils.isNotEmpty(getProxyHost())) {
        CredentialFactory pcf = new CredentialFactory(getProxyAuthAlias(), getProxyUserName(), getProxyPassword());
        parameter.put("proxyHost", getProxyHost());
        parameter.put("proxyPort", "" + getProxyPort());
        parameter.put("proxyUserName", pcf.getUsername());
        parameter.put("proxyPassword", pcf.getPassword());
    }
    // Custom IBIS HttpSender to support ssl connections and proxies
    parameter.put(SessionParameter.HTTP_INVOKER_CLASS, "nl.nn.adapterframework.extensions.cmis.CmisHttpInvoker");
    Session session = sessionFactory.createSession(parameter);
    log.debug(getLogPrefix() + "connected with repository [" + getRepositoryInfo(session) + "]");
    return session;
}
Also used : SessionFactory(org.apache.chemistry.opencmis.client.api.SessionFactory) HashMap(java.util.HashMap) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 7 with CredentialFactory

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

the class CmisSender method getSession.

public Session getSession(ParameterResolutionContext prc) throws SenderException {
    if (session == null || !isKeepSession()) {
        String authAlias_work = null;
        String userName_work = null;
        String password_work = null;
        ParameterValueList pvl = null;
        try {
            if (prc != null && paramList != null) {
                pvl = prc.getValues(paramList);
                if (pvl != null) {
                    ParameterValue pv = pvl.getParameterValue("authAlias");
                    if (pv != null) {
                        authAlias_work = (String) pv.getValue();
                    }
                    pv = pvl.getParameterValue("userName");
                    if (pv != null) {
                        userName_work = (String) pv.getValue();
                    }
                    pv = pvl.getParameterValue("password");
                    if (pv != null) {
                        password_work = (String) pv.getValue();
                    }
                }
            }
        } catch (ParameterException e) {
            throw new SenderException(getLogPrefix() + "Sender [" + getName() + "] caught exception evaluating parameters", e);
        }
        if (authAlias_work == null) {
            authAlias_work = getAuthAlias();
        }
        if (userName_work == null) {
            userName_work = getUserName();
        }
        if (password_work == null) {
            password_work = getPassword();
        }
        CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work);
        session = connect(cf.getUsername(), cf.getPassword());
    }
    return session;
}
Also used : ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) ParameterValue(nl.nn.adapterframework.parameters.ParameterValue) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) ParameterException(nl.nn.adapterframework.core.ParameterException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 8 with CredentialFactory

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

the class FtpSession method getSshAuthentication.

private SshAuthenticationClient getSshAuthentication() throws Exception {
    if (StringUtils.isNotEmpty(privateKeyFilePath)) {
        PublicKeyAuthenticationClient pk = new PublicKeyAuthenticationClient();
        CredentialFactory pkcf = new CredentialFactory(getPrivateKeyAuthAlias(), getUsername(), getPrivateKeyPassword());
        pk.setUsername(pkcf.getUsername());
        SshPrivateKeyFile pkFile = SshPrivateKeyFile.parse(new File(privateKeyFilePath));
        pk.setKey(pkFile.toPrivateKey(pkcf.getPassword()));
        return pk;
    }
    CredentialFactory usercf = new CredentialFactory(getAuthAlias(), getUsername(), getPassword());
    if (StringUtils.isNotEmpty(usercf.getPassword())) {
        PasswordAuthenticationClient pac = new PasswordAuthenticationClient();
        pac.setUsername(usercf.getUsername());
        pac.setPassword(usercf.getPassword());
        return pac;
    }
    throw new Exception("Unknown authentication type, either the password or the privateKeyFile must be filled");
}
Also used : SshPrivateKeyFile(com.sshtools.j2ssh.transport.publickey.SshPrivateKeyFile) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) SshPrivateKeyFile(com.sshtools.j2ssh.transport.publickey.SshPrivateKeyFile) SftpFile(com.sshtools.j2ssh.sftp.SftpFile) File(java.io.File) PasswordAuthenticationClient(com.sshtools.j2ssh.authentication.PasswordAuthenticationClient) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PublicKeyAuthenticationClient(com.sshtools.j2ssh.authentication.PublicKeyAuthenticationClient)

Example 9 with CredentialFactory

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

the class MqttFacade method configure.

public void configure() throws ConfigurationException {
    if (StringUtils.isEmpty(getClientId())) {
        throw new ConfigurationException("clientId must be specified");
    }
    if (StringUtils.isEmpty(getBrokerUrl())) {
        throw new ConfigurationException("brokerUrl must be specified");
    }
    if (StringUtils.isEmpty(getTopic())) {
        throw new ConfigurationException("topic must be specified");
    }
    if (StringUtils.isEmpty(getPersistenceDirectory())) {
        throw new ConfigurationException("persistenceDirectory must be specified");
    }
    connectOptions = new MqttConnectOptions();
    connectOptions.setCleanSession(isCleanSession());
    connectOptions.setAutomaticReconnect(isAutomaticReconnect());
    connectOptions.setConnectionTimeout(getTimeout());
    connectOptions.setKeepAliveInterval(getKeepAliveInterval());
    // Default: 0, V3.1: 3, V3.1.1: 4
    connectOptions.setMqttVersion(MqttConnectOptions.MQTT_VERSION_DEFAULT);
    if (!StringUtils.isEmpty(getAuthAlias()) || (!StringUtils.isEmpty(getUsername()) && !StringUtils.isEmpty(getPassword()))) {
        CredentialFactory credentialFactory = new CredentialFactory(getAuthAlias(), getUsername(), getPassword());
        connectOptions.setUserName(credentialFactory.getUsername());
        connectOptions.setPassword(credentialFactory.getPassword().toCharArray());
    }
    MqttDefaultFilePersistence dataStore = new MqttDefaultFilePersistence(getPersistenceDirectory());
    try {
        client = new MqttClient(brokerUrl, clientId, dataStore);
    } catch (MqttException e) {
        throw new ConfigurationException("Could not create client", e);
    }
}
Also used : MqttClient(org.eclipse.paho.client.mqttv3.MqttClient) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) MqttConnectOptions(org.eclipse.paho.client.mqttv3.MqttConnectOptions) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) MqttException(org.eclipse.paho.client.mqttv3.MqttException) MqttDefaultFilePersistence(org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence)

Example 10 with CredentialFactory

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

the class ExchangeMailListener method configure.

public void configure() throws ConfigurationException {
    try {
        exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        CredentialFactory cf = new CredentialFactory(getAuthAlias(), getUserName(), getPassword());
        ExchangeCredentials credentials = new WebCredentials(cf.getUsername(), cf.getPassword());
        exchangeService.setCredentials(credentials);
        if (StringUtils.isNotEmpty(getMailAddress())) {
            exchangeService.autodiscoverUrl(getMailAddress());
        } else {
            exchangeService.setUrl(new URI(getUrl()));
        }
        FolderId inboxId;
        if (StringUtils.isNotEmpty(getMailAddress())) {
            Mailbox mailbox = new Mailbox(getMailAddress());
            inboxId = new FolderId(WellKnownFolderName.Inbox, mailbox);
        } else {
            inboxId = new FolderId(WellKnownFolderName.Inbox);
        }
        FindFoldersResults findFoldersResultsIn;
        FolderView folderViewIn = new FolderView(10);
        if (StringUtils.isNotEmpty(getInputFolder())) {
            SearchFilter searchFilterIn = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, getInputFolder());
            findFoldersResultsIn = exchangeService.findFolders(inboxId, searchFilterIn, folderViewIn);
            if (findFoldersResultsIn.getTotalCount() == 0) {
                throw new ConfigurationException("no (in) folder found with name [" + getInputFolder() + "]");
            } else if (findFoldersResultsIn.getTotalCount() > 1) {
                throw new ConfigurationException("multiple (in) folders found with name [" + getInputFolder() + "]");
            }
        } else {
            findFoldersResultsIn = exchangeService.findFolders(inboxId, folderViewIn);
        }
        folderIn = findFoldersResultsIn.getFolders().get(0);
        if (StringUtils.isNotEmpty(getFilter())) {
            if (!getFilter().equalsIgnoreCase("NDR")) {
                throw new ConfigurationException("illegal value for filter [" + getFilter() + "], must be 'NDR' or empty");
            }
        }
        if (StringUtils.isNotEmpty(getOutputFolder())) {
            SearchFilter searchFilterOut = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, getOutputFolder());
            FolderView folderViewOut = new FolderView(10);
            FindFoldersResults findFoldersResultsOut = exchangeService.findFolders(inboxId, searchFilterOut, folderViewOut);
            if (findFoldersResultsOut.getTotalCount() == 0) {
                throw new ConfigurationException("no (out) folder found with name [" + getOutputFolder() + "]");
            } else if (findFoldersResultsOut.getTotalCount() > 1) {
                throw new ConfigurationException("multiple (out) folders found with name [" + getOutputFolder() + "]");
            }
            folderOut = findFoldersResultsOut.getFolders().get(0);
        }
    } catch (Exception e) {
        throw new ConfigurationException(e);
    }
}
Also used : FolderView(microsoft.exchange.webservices.data.search.FolderView) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) FindFoldersResults(microsoft.exchange.webservices.data.search.FindFoldersResults) SearchFilter(microsoft.exchange.webservices.data.search.filter.SearchFilter) FolderId(microsoft.exchange.webservices.data.property.complex.FolderId) URI(java.net.URI) ServiceLocalException(microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException) ListenerException(nl.nn.adapterframework.core.ListenerException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ExchangeService(microsoft.exchange.webservices.data.core.ExchangeService) Mailbox(microsoft.exchange.webservices.data.property.complex.Mailbox) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ExchangeCredentials(microsoft.exchange.webservices.data.credential.ExchangeCredentials) WebCredentials(microsoft.exchange.webservices.data.credential.WebCredentials)

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