Search in sources :

Example 1 with CredentialFactory

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

the class JNDIBase method getJndiEnv.

protected Hashtable getJndiEnv() throws NamingException {
    Properties jndiEnv = new Properties();
    if (StringUtils.isNotEmpty(getJndiProperties())) {
        URL url = ClassUtils.getResourceURL(classLoader, getJndiProperties());
        if (url == null) {
            throw new NamingException("cannot find jndiProperties from [" + getJndiProperties() + "]");
        }
        try {
            jndiEnv.load(url.openStream());
        } catch (IOException e) {
            throw new NamingException("cannot load jndiProperties [" + getJndiProperties() + "] from url [" + url.toString() + "]");
        }
    }
    if (getInitialContextFactoryName() != null)
        jndiEnv.put(Context.INITIAL_CONTEXT_FACTORY, getInitialContextFactoryName());
    if (getProviderURL() != null)
        jndiEnv.put(Context.PROVIDER_URL, getProviderURL());
    if (getAuthentication() != null)
        jndiEnv.put(Context.SECURITY_AUTHENTICATION, getAuthentication());
    if (getPrincipal() != null || getCredentials() != null || getJndiAuthAlias() != null) {
        CredentialFactory jndiCf = new CredentialFactory(getJndiAuthAlias(), getPrincipal(), getCredentials());
        if (StringUtils.isNotEmpty(jndiCf.getUsername()))
            jndiEnv.put(Context.SECURITY_PRINCIPAL, jndiCf.getUsername());
        if (StringUtils.isNotEmpty(jndiCf.getPassword()))
            jndiEnv.put(Context.SECURITY_CREDENTIALS, jndiCf.getPassword());
    }
    if (getUrlPkgPrefixes() != null)
        jndiEnv.put(Context.URL_PKG_PREFIXES, getUrlPkgPrefixes());
    if (getSecurityProtocol() != null)
        jndiEnv.put(Context.SECURITY_PROTOCOL, getSecurityProtocol());
    if (log.isDebugEnabled()) {
        for (Iterator it = jndiEnv.keySet().iterator(); it.hasNext(); ) {
            String key = (String) it.next();
            String value = jndiEnv.getProperty(key);
            log.debug("jndiEnv [" + key + "] = [" + value + "]");
        }
    }
    return jndiEnv;
}
Also used : CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Iterator(java.util.Iterator) NamingException(javax.naming.NamingException) IOException(java.io.IOException) Properties(java.util.Properties) URL(java.net.URL)

Example 2 with CredentialFactory

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

the class ShowSecurityItems method addAuthEntries.

private ArrayList<Object> addAuthEntries() {
    ArrayList<Object> authEntries = new ArrayList<Object>();
    Collection<Node> entries = null;
    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.getOriginalConfiguration();
                configString = StringResolver.substVars(configString, AppConstants.getInstance());
                configString = ConfigurationUtils.getActivatedConfiguration(configuration, configString);
                String ae = XmlUtils.transformXml(t, configString);
                Element authEntriesElement = XmlUtils.buildElement(ae);
                if (entries == null) {
                    entries = XmlUtils.getChildTags(authEntriesElement, "entry");
                } else {
                    entries.addAll(XmlUtils.getChildTags(authEntriesElement, "entry"));
                }
            }
        }
    } catch (Exception e) {
        authEntries.add("*** ERROR ***");
    }
    if (entries != null) {
        Iterator<Node> iter = entries.iterator();
        while (iter.hasNext()) {
            Map<String, Object> ae = new HashMap<String, Object>();
            Element itemElement = (Element) iter.next();
            String alias = itemElement.getAttribute("alias");
            ae.put("alias", alias);
            CredentialFactory cf = new CredentialFactory(alias, null, null);
            String userName;
            String passWord;
            try {
                userName = cf.getUsername();
                passWord = StringUtils.repeat("*", cf.getPassword().length());
            } catch (Exception e) {
                userName = "*** ERROR ***";
                passWord = "*** ERROR ***";
            }
            ae.put("username", userName);
            ae.put("password", passWord);
            authEntries.add(ae);
        }
    }
    return authEntries;
}
Also used : Transformer(javax.xml.transform.Transformer) Configuration(nl.nn.adapterframework.configuration.Configuration) HashMap(java.util.HashMap) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) URL(java.net.URL) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) JmsException(nl.nn.adapterframework.jms.JmsException) IOException(java.io.IOException)

Example 3 with CredentialFactory

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

the class ShowSecurityItems method addRegisteredAdapters.

private void addRegisteredAdapters(XmlBuilder securityItems) {
    XmlBuilder registeredAdapters = new XmlBuilder("registeredAdapters");
    securityItems.addSubElement(registeredAdapters);
    for (IAdapter iAdapter : ibisManager.getRegisteredAdapters()) {
        Adapter adapter = (Adapter) iAdapter;
        XmlBuilder adapterXML = new XmlBuilder("adapter");
        registeredAdapters.addSubElement(adapterXML);
        adapterXML.addAttribute("name", adapter.getName());
        Iterator recIt = adapter.getReceiverIterator();
        if (recIt.hasNext()) {
            XmlBuilder receiversXML = new XmlBuilder("receivers");
            while (recIt.hasNext()) {
                IReceiver receiver = (IReceiver) recIt.next();
                XmlBuilder receiverXML = new XmlBuilder("receiver");
                receiversXML.addSubElement(receiverXML);
                receiverXML.addAttribute("name", receiver.getName());
                if (receiver instanceof HasSender) {
                    ISender sender = ((HasSender) receiver).getSender();
                    if (sender != null) {
                        receiverXML.addAttribute("senderName", sender.getName());
                    }
                }
            }
            adapterXML.addSubElement(receiversXML);
        }
        // make list of pipes to be displayed in configuration status
        XmlBuilder pipesElem = new XmlBuilder("pipes");
        adapterXML.addSubElement(pipesElem);
        PipeLine pipeline = adapter.getPipeLine();
        for (int i = 0; i < pipeline.getPipes().size(); i++) {
            IPipe pipe = pipeline.getPipe(i);
            String pipename = pipe.getName();
            if (pipe instanceof MessageSendingPipe) {
                MessageSendingPipe msp = (MessageSendingPipe) pipe;
                XmlBuilder pipeElem = new XmlBuilder("pipe");
                pipeElem.addAttribute("name", pipename);
                ISender sender = msp.getSender();
                pipeElem.addAttribute("sender", ClassUtils.nameOf(sender));
                pipesElem.addSubElement(pipeElem);
                if (sender instanceof WebServiceSender) {
                    WebServiceSender s = (WebServiceSender) sender;
                    String certificate = s.getCertificate();
                    if (StringUtils.isNotEmpty(certificate)) {
                        XmlBuilder certElem = new XmlBuilder("certificate");
                        certElem.addAttribute("name", certificate);
                        String certificateAuthAlias = s.getCertificateAuthAlias();
                        certElem.addAttribute("authAlias", certificateAuthAlias);
                        URL certificateUrl = ClassUtils.getResourceURL(this, certificate);
                        if (certificateUrl == null) {
                            certElem.addAttribute("url", "");
                            pipeElem.addSubElement(certElem);
                            XmlBuilder infoElem = new XmlBuilder("info");
                            infoElem.setCdataValue("*** ERROR ***");
                            certElem.addSubElement(infoElem);
                        } else {
                            certElem.addAttribute("url", certificateUrl.toString());
                            pipeElem.addSubElement(certElem);
                            String certificatePassword = s.getCertificatePassword();
                            CredentialFactory certificateCf = new CredentialFactory(certificateAuthAlias, null, certificatePassword);
                            String keystoreType = s.getKeystoreType();
                            addCertificateInfo(certElem, certificateUrl, certificateCf.getPassword(), keystoreType, "Certificate chain");
                        }
                    }
                } else {
                    if (sender instanceof HttpSender) {
                        HttpSender s = (HttpSender) sender;
                        String certificate = s.getCertificate();
                        if (StringUtils.isNotEmpty(certificate)) {
                            XmlBuilder certElem = new XmlBuilder("certificate");
                            certElem.addAttribute("name", certificate);
                            String certificateAuthAlias = s.getCertificateAuthAlias();
                            certElem.addAttribute("authAlias", certificateAuthAlias);
                            URL certificateUrl = ClassUtils.getResourceURL(this, certificate);
                            if (certificateUrl == null) {
                                certElem.addAttribute("url", "");
                                pipeElem.addSubElement(certElem);
                                XmlBuilder infoElem = new XmlBuilder("info");
                                infoElem.setCdataValue("*** ERROR ***");
                                certElem.addSubElement(infoElem);
                            } else {
                                certElem.addAttribute("url", certificateUrl.toString());
                                pipeElem.addSubElement(certElem);
                                String certificatePassword = s.getCertificatePassword();
                                CredentialFactory certificateCf = new CredentialFactory(certificateAuthAlias, null, certificatePassword);
                                String keystoreType = s.getKeystoreType();
                                addCertificateInfo(certElem, certificateUrl, certificateCf.getPassword(), keystoreType, "Certificate chain");
                            }
                        }
                    } else {
                        if (sender instanceof FtpSender) {
                            FtpSender s = (FtpSender) sender;
                            String certificate = s.getCertificate();
                            if (StringUtils.isNotEmpty(certificate)) {
                                XmlBuilder certElem = new XmlBuilder("certificate");
                                certElem.addAttribute("name", certificate);
                                String certificateAuthAlias = s.getCertificateAuthAlias();
                                certElem.addAttribute("authAlias", certificateAuthAlias);
                                URL certificateUrl = ClassUtils.getResourceURL(this, certificate);
                                if (certificateUrl == null) {
                                    certElem.addAttribute("url", "");
                                    pipeElem.addSubElement(certElem);
                                    XmlBuilder infoElem = new XmlBuilder("info");
                                    infoElem.setCdataValue("*** ERROR ***");
                                    certElem.addSubElement(infoElem);
                                } else {
                                    certElem.addAttribute("url", certificateUrl.toString());
                                    pipeElem.addSubElement(certElem);
                                    String certificatePassword = s.getCertificatePassword();
                                    CredentialFactory certificateCf = new CredentialFactory(certificateAuthAlias, null, certificatePassword);
                                    String keystoreType = s.getCertificateType();
                                    addCertificateInfo(certElem, certificateUrl, certificateCf.getPassword(), keystoreType, "Certificate chain");
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MessageSendingPipe(nl.nn.adapterframework.pipes.MessageSendingPipe) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Adapter(nl.nn.adapterframework.core.Adapter) IAdapter(nl.nn.adapterframework.core.IAdapter) FtpSender(nl.nn.adapterframework.ftp.FtpSender) HttpSender(nl.nn.adapterframework.http.HttpSender) HasSender(nl.nn.adapterframework.core.HasSender) URL(java.net.URL) IReceiver(nl.nn.adapterframework.core.IReceiver) ISender(nl.nn.adapterframework.core.ISender) Iterator(java.util.Iterator) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) WebServiceSender(nl.nn.adapterframework.http.WebServiceSender) PipeLine(nl.nn.adapterframework.core.PipeLine) IAdapter(nl.nn.adapterframework.core.IAdapter) IPipe(nl.nn.adapterframework.core.IPipe)

Example 4 with CredentialFactory

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

the class NetStorageSender method configure.

public void configure() throws ConfigurationException {
    super.configure();
    // Safety checks
    if (getAction() == null)
        throw new ConfigurationException(getLogPrefix() + "action must be specified");
    if (!actions.contains(getAction()))
        throw new ConfigurationException(getLogPrefix() + "unknown or invalid action [" + getAction() + "] supported actions are " + actions.toString() + "");
    if (getCpCode() == null)
        throw new ConfigurationException(getLogPrefix() + "cpCode must be specified");
    if (!getUrl().startsWith("http"))
        throw new ConfigurationException(getLogPrefix() + "url must be start with http(s)");
    if (hashAlgorithm != null && !hashAlgorithms.contains(hashAlgorithm))
        throw new ConfigurationException(getLogPrefix() + "unknown authenticationMethod [" + hashAlgorithm + "] supported methods are " + hashAlgorithms.toString() + "");
    if (getSignVersion() < 3 || getSignVersion() > 5)
        throw new ConfigurationException(getLogPrefix() + "signVersion must be either 3, 4 or 5");
    ParameterList parameterList = getParameterList();
    if (getAction().equals("upload") && parameterList.findParameter("file") == null)
        throw new ConfigurationException(getLogPrefix() + "the upload action requires a file parameter to be present");
    if (getAction().equals("rename") && parameterList.findParameter("destination") == null)
        throw new ConfigurationException(getLogPrefix() + "the rename action requires a destination parameter to be present");
    if (getAction().equals("mtime") && parameterList.findParameter("mtime") == null)
        throw new ConfigurationException(getLogPrefix() + "the mtime action requires a mtime parameter to be present");
    accessTokenCf = new CredentialFactory(getAuthAlias(), getNonce(), getAccessToken());
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) ParameterList(nl.nn.adapterframework.parameters.ParameterList)

Example 5 with CredentialFactory

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

the class CmisSender method getSession.

public Session getSession() {
    if (session == null || !isKeepSession()) {
        CredentialFactory cf = new CredentialFactory(getAuthAlias(), getUserName(), getPassword());
        session = connect(cf.getUsername(), cf.getPassword());
    }
    return session;
}
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