Search in sources :

Example 16 with CredentialFactory

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

the class EsbJmsListenerChecker method doCheck.

public static void doCheck(IbisManager ibisManager, PlatformTransactionManager txManager, String logPrefix) {
    long idleTimeout = AppConstants.getInstance().getInt("check.esbJmsListeners.idleTimeout", 300) * 1000;
    for (Configuration configuration : ibisManager.getConfigurations()) {
        String msg;
        List<String> jmsRealmNames = new ArrayList<String>();
        for (IAdapter adapter : configuration.getRegisteredAdapters()) {
            if (adapter instanceof Adapter) {
                for (Iterator receiverIt = adapter.getReceiverIterator(); receiverIt.hasNext(); ) {
                    IReceiver receiver = (IReceiver) receiverIt.next();
                    if (receiver instanceof ReceiverBase) {
                        ReceiverBase rb = (ReceiverBase) receiver;
                        if (rb.getRunState().equals(RunStateEnum.STARTED)) {
                            // if (true) {
                            long lastMessageDate = rb.getLastMessageDate();
                            if (lastMessageDate == 0 || System.currentTimeMillis() - lastMessageDate > idleTimeout) {
                                IListener listener = rb.getListener();
                                if (listener instanceof EsbJmsListener) {
                                    EsbJmsListener esbJmsListener = (EsbJmsListener) listener;
                                    if (esbJmsListener.getMessageProtocol().equals("FF")) {
                                        Object managedConnectionFactory = null;
                                        try {
                                            managedConnectionFactory = esbJmsListener.getManagedConnectionFactory();
                                            if (managedConnectionFactory == null) {
                                                msg = logPrefix + "could not get managed connection factory";
                                                warn(adapter, msg);
                                            } else {
                                                String contextFactoryClassname = getContextFactoryClassname(managedConnectionFactory);
                                                String providerURL = getProviderURL(managedConnectionFactory);
                                                String authDataAlias = getAuthDataAlias(managedConnectionFactory);
                                                String username = null;
                                                String password = null;
                                                msg = logPrefix + "found esbJmsListener [" + esbJmsListener.getName() + "] with managedConnectionFactoryClassname [" + managedConnectionFactory.getClass().getName() + "] having contextFactoryClassname [" + contextFactoryClassname + "] providerURL [" + providerURL + "] authDataAlias [" + authDataAlias + "]";
                                                if (authDataAlias != null) {
                                                    CredentialFactory cf = new CredentialFactory(authDataAlias, null, null);
                                                    username = cf.getUsername();
                                                    password = cf.getPassword();
                                                }
                                                if (contextFactoryClassname != null && contextFactoryClassname.equals("com.tibco.tibjms.naming.TibjmsInitialContextFactory")) {
                                                    log.debug(msg + ", checking...");
                                                    long age = getTibcoQueueFirstMessageAge(providerURL, authDataAlias, username, password, esbJmsListener.getPhysicalDestinationShortName(), esbJmsListener.getMessageSelector());
                                                    if (age > idleTimeout) {
                                                        msg = logPrefix + "most probably esbJmsListener [" + esbJmsListener.getName() + "] has lost connection with queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
                                                        warn(adapter, msg);
                                                    }
                                                } else {
                                                    log.debug(msg + ", ignoring...");
                                                }
                                            }
                                        } catch (Throwable t) {
                                            msg = logPrefix + "exception on checking queue [" + esbJmsListener.getPhysicalDestinationShortName() + "]";
                                            warn(adapter, msg, t);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ReceiverBase(nl.nn.adapterframework.receivers.ReceiverBase) Configuration(nl.nn.adapterframework.configuration.Configuration) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) IListener(nl.nn.adapterframework.core.IListener) ArrayList(java.util.ArrayList) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) IReceiver(nl.nn.adapterframework.core.IReceiver) Iterator(java.util.Iterator) IAdapter(nl.nn.adapterframework.core.IAdapter)

Example 17 with CredentialFactory

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

the class FtpSession method openSftpClient.

private void openSftpClient(String remoteDirectory) throws FtpConnectException {
    try {
        // Set the connection properties and if necessary the proxy properties
        SshConnectionProperties sshProp = new SshConnectionProperties();
        sshProp.setHost(host);
        sshProp.setPort(port);
        if (StringUtils.isNotEmpty(prefCSEncryption))
            sshProp.setPrefCSEncryption(prefCSEncryption);
        if (StringUtils.isNotEmpty(prefSCEncryption))
            sshProp.setPrefCSEncryption(prefSCEncryption);
        if (!StringUtils.isEmpty(proxyHost)) {
            sshProp.setTransportProvider(proxyTransportType);
            sshProp.setProxyHost(proxyHost);
            sshProp.setProxyPort(proxyPort);
            CredentialFactory pcf = new CredentialFactory(getProxyAuthAlias(), proxyUsername, proxyPassword);
            if (!StringUtils.isEmpty(pcf.getUsername())) {
                sshProp.setProxyUsername(pcf.getUsername());
                sshProp.setProxyPassword(pcf.getPassword());
            }
        }
        // make a secure connection with the remote host
        sshClient = new SshClient();
        if (StringUtils.isNotEmpty(knownHostsPath)) {
            AbstractKnownHostsKeyVerification hv = null;
            if (consoleKnownHostsVerifier) {
                hv = new ConsoleKnownHostsKeyVerification(knownHostsPath);
            } else {
                hv = new SftpHostVerification(knownHostsPath);
            }
            sshClient.connect(sshProp, hv);
        } else {
            sshClient.connect(sshProp, new IgnoreHostKeyVerification());
        }
        SshAuthenticationClient sac;
        if (!isKeyboardInteractive()) {
            // pass the authentication information
            sac = getSshAuthentication();
        } else {
            // TODO: detecteren dat sshClient.getAvailableAuthMethods("ftpmsg")
            // wel keyboard-interactive terug geeft, maar geen password en dan deze methode
            // gebruiken
            final CredentialFactory credentialFactory = new CredentialFactory(getAuthAlias(), getUsername(), getPassword());
            KBIAuthenticationClient kbiAuthenticationClient = new KBIAuthenticationClient();
            kbiAuthenticationClient.setUsername(credentialFactory.getUsername());
            kbiAuthenticationClient.setKBIRequestHandler(new KBIRequestHandler() {

                public void showPrompts(String name, String instruction, KBIPrompt[] prompts) {
                    // deze 3 regels in x.zip naar Zenz gemaild, hielp ook niet
                    if (prompts == null) {
                        return;
                    }
                    for (int i = 0; i < prompts.length; i++) {
                        prompts[i].setResponse(credentialFactory.getPassword());
                    }
                }
            });
            sac = kbiAuthenticationClient;
        }
        int result = sshClient.authenticate(sac);
        if (result != AuthenticationProtocolState.COMPLETE) {
            closeSftpClient();
            throw new IOException("Could not authenticate to sftp server " + result);
        }
        // use the connection for sftp
        sftpClient = sshClient.openSftpClient();
        if (!StringUtils.isEmpty(remoteDirectory)) {
            sftpClient.cd(remoteDirectory);
        }
    } catch (Exception e) {
        closeSftpClient();
        throw new FtpConnectException(e);
    }
}
Also used : SshAuthenticationClient(com.sshtools.j2ssh.authentication.SshAuthenticationClient) SshClient(com.sshtools.j2ssh.SshClient) AbstractKnownHostsKeyVerification(com.sshtools.j2ssh.transport.AbstractKnownHostsKeyVerification) IgnoreHostKeyVerification(com.sshtools.j2ssh.transport.IgnoreHostKeyVerification) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) KBIPrompt(com.sshtools.j2ssh.authentication.KBIPrompt) KBIAuthenticationClient(com.sshtools.j2ssh.authentication.KBIAuthenticationClient) IOException(java.io.IOException) KBIRequestHandler(com.sshtools.j2ssh.authentication.KBIRequestHandler) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SshConnectionProperties(com.sshtools.j2ssh.configuration.SshConnectionProperties) ConsoleKnownHostsKeyVerification(com.sshtools.j2ssh.transport.ConsoleKnownHostsKeyVerification)

Example 18 with CredentialFactory

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

the class FtpSession method openFtpClient.

private void openFtpClient(String remoteDirectory) throws FtpConnectException {
    try {
        // set proxy properties
        if (!StringUtils.isEmpty(proxyHost)) {
            System.getProperties().put("ftpProxySet", "true");
            System.getProperties().put("ftpProxyHost", proxyHost);
            System.getProperties().put("ftpProxyPort", "" + proxyPort);
        }
        // connect and logic using normal, non-secure ftp
        ftpClient = createFTPClient();
        ftpClient.connect(host, port);
        if (isPassive()) {
            ftpClient.enterLocalPassiveMode();
        }
        CredentialFactory usercf = new CredentialFactory(getAuthAlias(), getUsername(), getPassword());
        ftpClient.login(usercf.getUsername(), usercf.getPassword());
        if (!StringUtils.isEmpty(remoteDirectory)) {
            ftpClient.changeWorkingDirectory(remoteDirectory);
            checkReply("changeWorkingDirectory " + remoteDirectory);
        }
        if (StringUtils.isNotEmpty(fileType)) {
            ftpClient.setFileType(getFileTypeIntValue());
            checkReply("setFileType " + remoteDirectory);
        }
    } catch (Exception e) {
        closeFtpClient();
        throw new FtpConnectException(e);
    }
}
Also used : CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 19 with CredentialFactory

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

the class EsbUtils method getEsbConnectionFactoryInfo.

private static EsbConnectionFactoryInfo getEsbConnectionFactoryInfo(EsbJmsListener esbJmsListener) {
    String cfUrl = null;
    String cfUserName = null;
    String cfPassword = null;
    Object managedConnectionFactory = null;
    try {
        managedConnectionFactory = esbJmsListener.getManagedConnectionFactory();
    } catch (JmsException e) {
        log.warn("error occured during getting managed connection factory: " + e.getMessage());
    }
    if (managedConnectionFactory == null) {
        log.warn("could not get managed connection factory");
    } else {
        String contextFactoryClassname = getContextFactoryClassname(managedConnectionFactory);
        if (contextFactoryClassname == null) {
            log.warn("could not get context factory");
        } else {
            cfUrl = getProviderURL(managedConnectionFactory);
            String authDataAlias = getAuthDataAlias(managedConnectionFactory);
            if (authDataAlias != null) {
                CredentialFactory cf = new CredentialFactory(authDataAlias, null, null);
                cfUserName = cf.getUsername();
                cfPassword = cf.getPassword();
            }
            if (!contextFactoryClassname.equals("com.tibco.tibjms.naming.TibjmsInitialContextFactory")) {
                log.warn("did not expect context factory of type [" + contextFactoryClassname + "]");
            } else {
                return new EsbConnectionFactoryInfo(managedConnectionFactory, contextFactoryClassname, cfUrl, cfUserName, cfPassword);
            }
        }
    }
    return null;
}
Also used : JmsException(nl.nn.adapterframework.jms.JmsException) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory)

Example 20 with CredentialFactory

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

the class EsbUtils method getPoolingDataSource.

public static PoolingDataSource getPoolingDataSource(JdbcTransactionalStorage errorStorage) {
    String dsUrl = null;
    String dsUserName = null;
    String dsPassword = null;
    java.sql.Connection errorStorageConnection = null;
    try {
        errorStorageConnection = errorStorage.getConnection();
    } catch (JdbcException e) {
        log.warn("error occured during getting errorStorage connection: " + e.getMessage());
    }
    if (errorStorageConnection == null) {
        log.warn("could not get errorStorage connection");
    } else {
        DatabaseMetaData md;
        try {
            md = errorStorageConnection.getMetaData();
            dsUrl = md.getURL();
        // dsUserName = md.getUserName();
        // dsPassword = md.getPassword();
        } catch (SQLException e) {
            log.warn("error occured during getting errorStorage metadata: " + e.getMessage());
        }
        if (dsUrl == null) {
            log.warn("could not get errorStorage url");
        } else {
            // onderstaande is nodig omdat het niet mogelijk is het
            // password op te vragen uit het DatabaseMetaData object of
            // uit het Connection object
            String confResString = null;
            try {
                confResString = Misc.getConfigurationResources();
                if (confResString != null) {
                    confResString = XmlUtils.removeNamespaces(confResString);
                }
            } catch (IOException e) {
                log.warn("error getting configuration resources: " + e.getMessage());
            }
            String authDataAlias = null;
            if (confResString != null) {
                String dsName = null;
                try {
                    dsName = errorStorage.getDataSourceNameToUse();
                } catch (JdbcException e) {
                    log.warn("error getting datasource name to use: " + e.getMessage());
                }
                if (dsName != null) {
                    String xpathExpression = "XMI/JDBCProvider/factories[@jndiName='" + dsName + "']/@authDataAlias";
                    try {
                        Transformer t = XmlUtils.createXPathEvaluator(xpathExpression);
                        authDataAlias = XmlUtils.transformXml(t, confResString);
                    } catch (Exception e) {
                        log.warn("error getting datasource authDataAlias: " + e.getMessage());
                    }
                }
            }
            if (StringUtils.isEmpty(authDataAlias)) {
                log.warn("could not get errorStorage authDataAlias");
            } else {
                CredentialFactory cf = new CredentialFactory(authDataAlias, null, null);
                dsUserName = cf.getUsername();
                dsPassword = cf.getPassword();
                return setupJdbcDataSource(dsUrl, dsUserName, dsPassword);
            }
        }
    }
    return null;
}
Also used : Transformer(javax.xml.transform.Transformer) SQLException(java.sql.SQLException) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) IOException(java.io.IOException) DatabaseMetaData(java.sql.DatabaseMetaData) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) SQLException(java.sql.SQLException) ListenerException(nl.nn.adapterframework.core.ListenerException) JmsException(nl.nn.adapterframework.jms.JmsException) IOException(java.io.IOException) JMSException(javax.jms.JMSException)

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