Search in sources :

Example 31 with CredentialFactory

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

the class ShowSecurityItems method addAuthEntries.

private void addAuthEntries(XmlBuilder securityItems) {
    XmlBuilder aes = new XmlBuilder("authEntries");
    securityItems.addSubElement(aes);
    List entries = new ArrayList();
    try {
        URL url = ClassUtils.getResourceURL(this, AUTHALIAS_XSLT);
        if (url != null) {
            for (Configuration configuration : ibisManager.getConfigurations()) {
                Transformer t = XmlUtils.createTransformer(url, true);
                String configString = configuration.getLoadedConfiguration();
                String authEntries = XmlUtils.transformXml(t, configString);
                log.debug("authentication aliases for configuration [" + configuration.getName() + "] found [" + authEntries.trim() + "]");
                Collection<String> c = XmlUtils.evaluateXPathNodeSet(authEntries, "authEntries/entry/@alias");
                if (c != null && c.size() > 0) {
                    for (Iterator<String> cit = c.iterator(); cit.hasNext(); ) {
                        String entry = cit.next();
                        if (!entries.contains(entry)) {
                            entries.add(entry);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        XmlBuilder ae = new XmlBuilder("entry");
        aes.addSubElement(ae);
        ae.addAttribute("alias", "*** ERROR ***");
    }
    if (entries != null) {
        Collections.sort(entries);
        Iterator iter = entries.iterator();
        while (iter.hasNext()) {
            String alias = (String) iter.next();
            CredentialFactory cf = new CredentialFactory(alias, null, null);
            XmlBuilder ae = new XmlBuilder("entry");
            aes.addSubElement(ae);
            ae.addAttribute("alias", alias);
            String userName;
            String passWord;
            try {
                userName = cf.getUsername();
                passWord = StringUtils.repeat("*", cf.getPassword().length());
            } catch (Exception e) {
                userName = "*** ERROR ***";
                passWord = "*** ERROR ***";
            }
            ae.addAttribute("userName", userName);
            ae.addAttribute("passWord", passWord);
        }
    }
}
Also used : Transformer(javax.xml.transform.Transformer) Configuration(nl.nn.adapterframework.configuration.Configuration) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) URL(java.net.URL) ServletException(javax.servlet.ServletException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) TransformerException(javax.xml.transform.TransformerException) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) JmsException(nl.nn.adapterframework.jms.JmsException) IOException(java.io.IOException)

Example 32 with CredentialFactory

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

the class MailSender method putOnTransport.

protected void putOnTransport(Message msg) throws SenderException {
    // connect to the transport
    Transport transport = null;
    try {
        CredentialFactory cf = new CredentialFactory(getSmtpAuthAlias(), getSmtpUserid(), getSmtpPassword());
        transport = session.getTransport("smtp");
        transport.connect(getSmtpHost(), cf.getUsername(), cf.getPassword());
        if (log.isDebugEnabled()) {
            log.debug("MailSender [" + getName() + "] connected transport to URL [" + transport.getURLName() + "]");
        }
        transport.sendMessage(msg, msg.getAllRecipients());
        transport.close();
    } catch (Exception e) {
        throw new SenderException("MailSender [" + getName() + "] cannot connect send message to smtpHost [" + getSmtpHost() + "]", e);
    } finally {
        if (transport != null) {
            try {
                transport.close();
            } catch (MessagingException e1) {
                log.warn("MailSender [" + getName() + "] got exception closing connection", e1);
            }
        }
    }
}
Also used : MessagingException(javax.mail.MessagingException) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Transport(javax.mail.Transport) SenderException(nl.nn.adapterframework.core.SenderException) MessagingException(javax.mail.MessagingException) MalformedURLException(java.net.MalformedURLException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 33 with CredentialFactory

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

the class XComSender method getCommand.

private String getCommand(IPipeLineSession session, File localFile, boolean inclPasswd) throws SenderException {
    try {
        StringBuffer sb = new StringBuffer();
        sb.append(xcomtcp).append(" -c1");
        if (StringUtils.isNotEmpty(configFile)) {
            sb.append(" -f ").append(configFile);
        }
        if (StringUtils.isNotEmpty(remoteSystem)) {
            sb.append(" REMOTE_SYSTEM=").append(remoteSystem);
        }
        if (localFile != null) {
            sb.append(" LOCAL_FILE=").append(localFile.getAbsolutePath());
            sb.append(" REMOTE_FILE=");
            if (!StringUtils.isEmpty(remoteDirectory))
                sb.append(remoteDirectory);
            if (StringUtils.isEmpty(remoteFilePattern))
                sb.append(localFile.getName());
            else
                sb.append(FileUtils.getFilename(paramList, session, localFile, remoteFilePattern));
        }
        CredentialFactory cf = new CredentialFactory(getAuthAlias(), getUserid(), password);
        // optional parameters
        if (StringUtils.isNotEmpty(fileOption))
            sb.append(" FILE_OPTION=").append(fileOption);
        if (queue != null)
            sb.append(" QUEUE=").append(queue.booleanValue() ? "YES" : "NO");
        if (tracelevel != null)
            sb.append(" TRACE=").append(tracelevel.intValue());
        if (truncation != null)
            sb.append(" TRUNCATION=").append(truncation.booleanValue() ? "YES" : "NO");
        if (!StringUtils.isEmpty(port))
            sb.append(" PORT=" + port);
        if (!StringUtils.isEmpty(logfile))
            sb.append(" XLOGFILE=" + logfile);
        if (!StringUtils.isEmpty(compress))
            sb.append(" COMPRESS=").append(compress);
        if (!StringUtils.isEmpty(codeflag))
            sb.append(" CODE_FLAG=").append(codeflag);
        if (!StringUtils.isEmpty(carriageflag))
            sb.append(" CARRIAGE_FLAG=").append(carriageflag);
        if (!StringUtils.isEmpty(cf.getUsername()))
            sb.append(" USERID=").append(cf.getUsername());
        if (inclPasswd && !StringUtils.isEmpty(cf.getPassword()))
            sb.append(" PASSWORD=").append(cf.getPassword());
        return sb.toString();
    } catch (ParameterException e) {
        throw new SenderException(e);
    }
}
Also used : CredentialFactory(nl.nn.adapterframework.util.CredentialFactory)

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