Search in sources :

Example 11 with CredentialFactory

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

the class SapSystemDataProvider method getDestinationProperties.

public Properties getDestinationProperties(String destinationName) {
    SapSystem sapSystem = SapSystem.getSystem(destinationName);
    if (sapSystem == null) {
        log.warn("Could not find destination name");
        return null;
    } else {
        CredentialFactory cf = new CredentialFactory(sapSystem.getAuthAlias(), sapSystem.getUserid(), sapSystem.getPasswd());
        Properties destinationProperties = new Properties();
        // See Javadoc DestinationDataProvider for available properties and their description.
        if (StringUtils.isEmpty(sapSystem.getGroup())) {
            destinationProperties.setProperty(DestinationDataProvider.JCO_ASHOST, sapSystem.getAshost());
            destinationProperties.setProperty(DestinationDataProvider.JCO_SYSNR, sapSystem.getSystemnr());
        } else {
            destinationProperties.setProperty(DestinationDataProvider.JCO_R3NAME, sapSystem.getR3name());
            destinationProperties.setProperty(DestinationDataProvider.JCO_MSHOST, sapSystem.getMshost());
            destinationProperties.setProperty(DestinationDataProvider.JCO_MSSERV, sapSystem.getMsserv());
            destinationProperties.setProperty(DestinationDataProvider.JCO_GROUP, sapSystem.getGroup());
        }
        destinationProperties.setProperty(DestinationDataProvider.JCO_CLIENT, sapSystem.getMandant());
        if (cf.getUsername() != null) {
            destinationProperties.setProperty(DestinationDataProvider.JCO_USER, cf.getUsername());
            destinationProperties.setProperty(DestinationDataProvider.JCO_PASSWD, cf.getPassword());
        }
        destinationProperties.setProperty(DestinationDataProvider.JCO_LANG, sapSystem.getLanguage());
        destinationProperties.setProperty(DestinationDataProvider.JCO_PCS, sapSystem.isUnicode() ? "2" : "1");
        destinationProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "" + sapSystem.getMaxConnections());
        if (sapSystem.isSncEncrypted()) {
            destinationProperties.setProperty(DestinationDataProvider.JCO_SNC_MODE, "1");
            destinationProperties.setProperty(DestinationDataProvider.JCO_SNC_LIBRARY, sapSystem.getSncLibrary());
            destinationProperties.setProperty(DestinationDataProvider.JCO_SNC_QOP, sapSystem.getSncQop());
            destinationProperties.setProperty(DestinationDataProvider.JCO_SNC_SSO, sapSystem.getSncAuthMethod());
            destinationProperties.setProperty(DestinationDataProvider.JCO_SNC_PARTNERNAME, sapSystem.getPartnerName());
            destinationProperties.setProperty(DestinationDataProvider.JCO_SNC_MYNAME, sapSystem.getMyName());
            if (sapSystem.getSncAuthMethod().equals("1")) {
                // Automatically order a SSO ticket after logon
                destinationProperties.setProperty(DestinationDataProvider.JCO_GETSSO2, sapSystem.getSncAuthMethod());
                if (sapSystem.getSncSSO2().equals("1"))
                    destinationProperties.setProperty(DestinationDataProvider.JCO_MYSAPSSO2, sapSystem.getSncSSO2());
            }
        }
        return destinationProperties;
    }
}
Also used : CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Properties(java.util.Properties)

Example 12 with CredentialFactory

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

the class SendTibcoMessage method doPipeWithTimeoutGuarded.

public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
    Connection connection = null;
    Session jSession = null;
    MessageProducer msgProducer = null;
    Destination destination = null;
    String url_work;
    String authAlias_work;
    String userName_work;
    String password_work;
    String queueName_work;
    String messageProtocol_work;
    int replyTimeout_work;
    String soapAction_work;
    String result = 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();
    }
    queueName_work = getParameterValue(pvl, "queueName");
    if (queueName_work == null) {
        queueName_work = getQueueName();
    }
    messageProtocol_work = getParameterValue(pvl, "messageProtocol");
    if (messageProtocol_work == null) {
        messageProtocol_work = getMessageProtocol();
    }
    String replyTimeout_work_str = getParameterValue(pvl, "replyTimeout");
    if (replyTimeout_work_str == null) {
        replyTimeout_work = getReplyTimeout();
    } else {
        replyTimeout_work = Integer.parseInt(replyTimeout_work_str);
    }
    soapAction_work = getParameterValue(pvl, "soapAction");
    if (soapAction_work == null)
        soapAction_work = getSoapAction();
    if (StringUtils.isEmpty(soapAction_work) && !StringUtils.isEmpty(queueName_work)) {
        String[] q = queueName_work.split("\\.");
        if (q.length > 0) {
            if (q[0].equalsIgnoreCase("P2P") && q.length >= 4) {
                soapAction_work = q[3];
            } else if (q[0].equalsIgnoreCase("ESB") && q.length == 8) {
                soapAction_work = q[5] + "_" + q[6];
            } else if (q[0].equalsIgnoreCase("ESB") && q.length > 8) {
                soapAction_work = q[6] + "_" + q[7];
            }
        }
    }
    if (StringUtils.isEmpty(soapAction_work)) {
        log.debug(getLogPrefix(session) + "deriving default soapAction");
        try {
            URL resource = ClassUtils.getResourceURL(this, "/xml/xsl/esb/soapAction.xsl");
            TransformerPool tp = TransformerPool.getInstance(resource, true);
            soapAction_work = tp.transform(input.toString(), null);
        } catch (Exception e) {
            log.error(getLogPrefix(session) + "failed to execute soapAction.xsl");
        }
    }
    if (messageProtocol_work == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "messageProtocol must be set");
    }
    if (!messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY) && !messageProtocol_work.equalsIgnoreCase(FIRE_AND_FORGET)) {
        throw new PipeRunException(this, getLogPrefix(session) + "illegal value for messageProtocol [" + messageProtocol_work + "], must be '" + REQUEST_REPLY + "' or '" + FIRE_AND_FORGET + "'");
    }
    CredentialFactory cf = new CredentialFactory(authAlias_work, userName_work, password_work);
    try {
        TibjmsAdmin admin;
        try {
            admin = TibcoUtils.getActiveServerAdmin(url_work, cf);
        } catch (TibjmsAdminException e) {
            log.debug(getLogPrefix(session) + "caught exception", e);
            admin = null;
        }
        if (admin != null) {
            QueueInfo queueInfo;
            try {
                queueInfo = admin.getQueue(queueName_work);
            } catch (Exception e) {
                throw new PipeRunException(this, getLogPrefix(session) + " exception on getting queue info", e);
            }
            if (queueInfo == null) {
                throw new PipeRunException(this, getLogPrefix(session) + " queue [" + queueName_work + "] does not exist");
            }
            try {
                admin.close();
            } catch (TibjmsAdminException e) {
                log.warn(getLogPrefix(session) + "exception on closing Tibjms Admin", e);
            }
        }
        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);
        destination = jSession.createQueue(queueName_work);
        msgProducer = jSession.createProducer(destination);
        TextMessage msg = jSession.createTextMessage();
        msg.setText(input.toString());
        Destination replyQueue = null;
        if (messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY)) {
            replyQueue = jSession.createTemporaryQueue();
            msg.setJMSReplyTo(replyQueue);
            msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
            msgProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            msgProducer.setTimeToLive(replyTimeout_work);
        } else {
            msg.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
            msgProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
        }
        if (StringUtils.isNotEmpty(soapAction_work)) {
            log.debug(getLogPrefix(session) + "setting [SoapAction] property to value [" + soapAction_work + "]");
            msg.setStringProperty("SoapAction", soapAction_work);
        }
        msgProducer.send(msg);
        if (log.isDebugEnabled()) {
            log.debug(getLogPrefix(session) + "sent message [" + msg.getText() + "] " + "to [" + msgProducer.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "replyTo [" + msg.getJMSReplyTo() + "]");
        } else {
            if (log.isInfoEnabled()) {
                log.info(getLogPrefix(session) + "sent message to [" + msgProducer.getDestination() + "] " + "msgID [" + msg.getJMSMessageID() + "] " + "correlationID [" + msg.getJMSCorrelationID() + "] " + "replyTo [" + msg.getJMSReplyTo() + "]");
            }
        }
        if (messageProtocol_work.equalsIgnoreCase(REQUEST_REPLY)) {
            String replyCorrelationId = msg.getJMSMessageID();
            MessageConsumer msgConsumer = jSession.createConsumer(replyQueue, "JMSCorrelationID='" + replyCorrelationId + "'");
            log.debug(getLogPrefix(session) + "] start waiting for reply on [" + replyQueue + "] selector [" + replyCorrelationId + "] for [" + replyTimeout_work + "] ms");
            try {
                connection.start();
                Message rawReplyMsg = msgConsumer.receive(replyTimeout_work);
                if (rawReplyMsg == null) {
                    throw new PipeRunException(this, getLogPrefix(session) + "did not receive reply on [" + replyQueue + "] replyCorrelationId [" + replyCorrelationId + "] within [" + replyTimeout_work + "] ms");
                }
                TextMessage replyMsg = (TextMessage) rawReplyMsg;
                result = replyMsg.getText();
            } finally {
            }
        } else {
            result = msg.getJMSMessageID();
        }
    } catch (JMSException e) {
        throw new PipeRunException(this, getLogPrefix(session) + " exception on sending message to Tibco queue", e);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (JMSException e) {
                log.warn(getLogPrefix(session) + "exception on closing connection", e);
            }
        }
    }
    return result;
}
Also used : QueueInfo(com.tibco.tibjms.admin.QueueInfo) Destination(javax.jms.Destination) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) JMSException(javax.jms.JMSException) URL(java.net.URL) TransformerPool(nl.nn.adapterframework.util.TransformerPool) ConnectionFactory(javax.jms.ConnectionFactory) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) MessageConsumer(javax.jms.MessageConsumer) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) Connection(javax.jms.Connection) TibjmsAdmin(com.tibco.tibjms.admin.TibjmsAdmin) PipeRunException(nl.nn.adapterframework.core.PipeRunException) JMSException(javax.jms.JMSException) TibjmsAdminException(com.tibco.tibjms.admin.TibjmsAdminException) ParameterException(nl.nn.adapterframework.core.ParameterException) TibjmsAdminException(com.tibco.tibjms.admin.TibjmsAdminException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession)

Example 13 with CredentialFactory

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

the class LdapFindMemberPipe method configure.

public void configure() throws ConfigurationException {
    super.configure();
    if (getHost() == null) {
        throw new ConfigurationException(getLogPrefix(null) + "host must be set");
    }
    cf = new CredentialFactory(getAuthAlias(), getUserName(), getPassword());
    if (StringUtils.isNotEmpty(getNotFoundForwardName())) {
        notFoundForward = findForward(getNotFoundForwardName());
    }
    if (StringUtils.isNotEmpty(getExceptionForwardName())) {
        exceptionForward = findForward(getExceptionForwardName());
    }
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory)

Example 14 with CredentialFactory

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

the class CredentialCheckingPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    CredentialFactory cf = new CredentialFactory(getAuthAlias(), getDefaultUserid(), getDefaultPassword());
    String result = "";
    if (!getTargetUserid().equals(cf.getUsername())) {
        result += "username does not match target";
    }
    if (!getTargetPassword().equals(cf.getPassword())) {
        result += "password does not match target";
    }
    if (StringUtils.isEmpty(result)) {
        result = "OK";
    }
    return new PipeRunResult(getForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory)

Example 15 with CredentialFactory

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

the class HashPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String message = (String) input;
    String authAlias = getAuthAlias();
    String secret = getSecret();
    try {
        ParameterList parameterList = getParameterList();
        ParameterResolutionContext prc = new ParameterResolutionContext(message, session);
        ParameterValueList pvl = prc.getValues(parameterList);
        if (pvl != null) {
            Parameter authAliasParam = parameterList.findParameter("authAlias");
            if (authAliasParam != null)
                authAlias = (String) authAliasParam.getValue(pvl, prc);
            Parameter secretParam = parameterList.findParameter("secret");
            if (secretParam != null)
                secret = (String) secretParam.getValue(pvl, prc);
        }
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + "exception extracting authAlias", e);
    }
    CredentialFactory accessTokenCf = new CredentialFactory(authAlias, "", secret);
    String cfSecret = accessTokenCf.getPassword();
    if (cfSecret == null || cfSecret.isEmpty())
        throw new PipeRunException(this, getLogPrefix(session) + "empty secret, unable to hash");
    try {
        Mac mac = Mac.getInstance(getAlgorithm());
        SecretKeySpec secretkey = new SecretKeySpec(cfSecret.getBytes(getEncoding()), "algorithm");
        mac.init(secretkey);
        String hash = Base64.encodeBase64String(mac.doFinal(message.getBytes()));
        return new PipeRunResult(getForward(), hash);
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + "error creating hash", e);
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) CredentialFactory(nl.nn.adapterframework.util.CredentialFactory) SecretKeySpec(javax.crypto.spec.SecretKeySpec) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Mac(javax.crypto.Mac)

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