Search in sources :

Example 16 with Parameter

use of nl.nn.adapterframework.parameters.Parameter in project iaf by ibissource.

the class GetTibcoQueues method retrieveLdapSender.

private LdapSender retrieveLdapSender(String ldapUrl, CredentialFactory cf) {
    try {
        LdapSender ldapSender = new LdapSender();
        ldapSender.setProviderURL(ldapUrl);
        ldapSender.setAttributesToReturn("cn,description");
        if (StringUtils.isNotEmpty(cf.getAlias())) {
            ldapSender.setJndiAuthAlias(cf.getAlias());
        }
        if (StringUtils.isNotEmpty(cf.getUsername())) {
            ldapSender.setPrincipal(cf.getUsername());
        }
        if (StringUtils.isNotEmpty(cf.getPassword())) {
            ldapSender.setCredentials(cf.getPassword());
        }
        Parameter p = new Parameter();
        p.setName("entryName");
        p.setXpathExpression("concat('cn=',*)");
        p.configure();
        ldapSender.addParameter(p);
        ldapSender.configure();
        return ldapSender;
    } catch (ConfigurationException e) {
        log.warn(getLogPrefix(null) + "exception on retrieving ldapSender", e);
    }
    return null;
}
Also used : LdapSender(nl.nn.adapterframework.ldap.LdapSender) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Parameter(nl.nn.adapterframework.parameters.Parameter)

Example 17 with Parameter

use of nl.nn.adapterframework.parameters.Parameter in project iaf by ibissource.

the class LdapChallengePipe method doPipe.

/**
 * Checks to see if the supplied parameteres of the pipe can login to LDAP
 * @see nl.nn.adapterframework.core.IPipe#doPipe(java.lang.Object, nl.nn.adapterframework.core.PipeLineSession)
 */
public PipeRunResult doPipe(Object msg, IPipeLineSession pls) throws PipeRunException {
    LdapSender ldapSender = new LdapSender();
    String ldapProviderURL;
    String credentials;
    String principal;
    ParameterResolutionContext prc;
    try {
        prc = new ParameterResolutionContext((String) msg, pls);
        Map paramMap = prc.getValueMap(getParameterList());
        if (StringUtils.isNotEmpty(getLdapProviderURL())) {
            ldapProviderURL = getLdapProviderURL();
        } else {
            ldapProviderURL = (String) paramMap.get("ldapProviderURL");
        }
        credentials = (String) paramMap.get("credentials");
        principal = (String) paramMap.get("principal");
    } catch (ParameterException e) {
        throw new PipeRunException(this, "Invalid parameter", e);
    }
    ldapSender.setErrorSessionKey(getErrorSessionKey());
    if (StringUtils.isEmpty(ldapProviderURL)) {
        throw new PipeRunException(this, "ldapProviderURL is empty");
    }
    if (StringUtils.isEmpty(principal)) {
        // throw new PipeRunException(this, "principal is empty");
        handleError(ldapSender, prc, 34, "Principal is Empty");
        return new PipeRunResult(findForward("invalid"), msg);
    }
    if (StringUtils.isEmpty(credentials)) {
        // throw new PipeRunException(this, "credentials are empty");
        handleError(ldapSender, prc, 49, "Credentials are Empty");
        return new PipeRunResult(findForward("invalid"), msg);
    }
    Parameter dummyEntryName = new Parameter();
    dummyEntryName.setName("entryName");
    dummyEntryName.setValue(principal);
    ldapSender.addParameter(dummyEntryName);
    ldapSender.setUsePooling(false);
    ldapSender.setLdapProviderURL(ldapProviderURL);
    if (StringUtils.isNotEmpty(getInitialContextFactoryName())) {
        ldapSender.setInitialContextFactoryName(getInitialContextFactoryName());
    }
    ldapSender.setPrincipal(principal);
    ldapSender.setCredentials(credentials);
    ldapSender.setOperation(LdapSender.OPERATION_READ);
    try {
        log.debug("Looking up context for principal [" + principal + "]");
        ldapSender.configure();
        log.debug("Succesfully looked up context for principal [" + principal + "]");
    } catch (Exception e) {
        if (StringUtils.isNotEmpty(getErrorSessionKey())) {
            ldapSender.storeLdapException(e, prc);
        } else {
            log.warn("LDAP error looking up context for principal [" + principal + "]", e);
        }
        return new PipeRunResult(findForward("invalid"), msg);
    }
    return new PipeRunResult(findForward("success"), msg);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 18 with Parameter

use of nl.nn.adapterframework.parameters.Parameter in project iaf by ibissource.

the class LdapSender method configure.

@Override
public void configure() throws ConfigurationException {
    if (paramList == null || (paramList.findParameter(ENTRYNAME) == null && !getOperation().equals(OPERATION_CHALLENGE))) {
        throw new ConfigurationException("[" + getName() + "] Required parameter with the name [entryName] not found!");
    }
    paramList.configure();
    if (getOperation() == null || !(getOperation().equals(OPERATION_READ) || getOperation().equals(OPERATION_SEARCH) || getOperation().equals(OPERATION_DEEP_SEARCH) || getOperation().equals(OPERATION_CREATE) || getOperation().equals(OPERATION_UPDATE) || getOperation().equals(OPERATION_DELETE) || getOperation().equals(OPERATION_SUB_CONTEXTS) || getOperation().equals(OPERATION_GET_TREE) || getOperation().equals(OPERATION_CHALLENGE) || getOperation().equals(OPERATION_CHANGE_UNICODE_PWD))) {
        throw new ConfigurationException("attribute opereration [" + getOperation() + "] must be one of (" + OPERATION_READ + "," + OPERATION_CREATE + "," + OPERATION_UPDATE + "," + OPERATION_DELETE + "," + OPERATION_SEARCH + "," + OPERATION_DEEP_SEARCH + "," + OPERATION_SUB_CONTEXTS + "," + OPERATION_GET_TREE + "," + OPERATION_CHALLENGE + "," + OPERATION_CHANGE_UNICODE_PWD + ")");
    }
    if (getOperation().equals(OPERATION_CREATE) || getOperation().equals(OPERATION_DELETE)) {
        if (!(getManipulationSubject().equals(MANIPULATION_ENTRY) || getManipulationSubject().equals(MANIPULATION_ATTRIBUTE)))
            throw new ConfigurationException("[" + getClass().getName() + "] manipulationSubject invalid (must be one of [" + MANIPULATION_ATTRIBUTE + ", " + MANIPULATION_ENTRY + "])");
    }
    if (getOperation().equals(OPERATION_UPDATE)) {
        if (!(getManipulationSubject().equals(MANIPULATION_ATTRIBUTE)))
            throw new ConfigurationException("[" + getClass().getName() + "] manipulationSubject invalid for update operation (must be ['" + MANIPULATION_ATTRIBUTE + "'], which is default - remove from <pipe>)");
    }
    if (getOperation().equals(OPERATION_CHALLENGE)) {
        if (paramList.findParameter("principal") == null)
            throw new ConfigurationException("principal should be specified using a parameter when using operation challenge");
    }
    Parameter credentials = paramList.findParameter("credentials");
    if (credentials != null && !credentials.isHidden()) {
        ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
        configWarnings.add(log, "It's advised to set attribute hidden to true for parameter credentials.");
    }
    Parameter oldPassword = paramList.findParameter("oldPassword");
    if (oldPassword != null && !oldPassword.isHidden()) {
        ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
        configWarnings.add(log, "It's advised to set attribute hidden to true for parameter oldPassword.");
    }
    Parameter newPassword = paramList.findParameter("newPassword");
    if (newPassword != null && !newPassword.isHidden()) {
        ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
        configWarnings.add(log, "It's advised to set attribute hidden to true for parameter newPassword.");
    }
    if (paramList.findParameter("principal") != null) {
        if (paramList.findParameter("credentials") == null) {
            throw new ConfigurationException("principal set as parameter, but no credentials parameter found");
        }
        principalParameterFound = true;
        setUsePooling(false);
    } else {
        DirContext dirContext = null;
        try {
            dirContext = getDirContext(null);
        } catch (Exception e) {
            throw new ConfigurationException("[" + getClass().getName() + "] Context could not be found ", e);
        } finally {
            closeDirContext(dirContext);
        }
    }
}
Also used : ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Parameter(nl.nn.adapterframework.parameters.Parameter) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) NamingException(javax.naming.NamingException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 19 with Parameter

use of nl.nn.adapterframework.parameters.Parameter in project iaf by ibissource.

the class CreateRestViewPipe method configure.

public void configure() throws ConfigurationException {
    ParameterList parameterList = getParameterList();
    if (parameterList.findParameter(SRCPREFIX) == null) {
        Parameter p = new Parameter();
        p.setName(SRCPREFIX);
        p.setSessionKey(SRCPREFIX);
        addParameter(p);
    }
    appConstants = AppConstants.getInstance(classLoader);
    super.configure();
}
Also used : ParameterList(nl.nn.adapterframework.parameters.ParameterList) Parameter(nl.nn.adapterframework.parameters.Parameter)

Example 20 with Parameter

use of nl.nn.adapterframework.parameters.Parameter 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

Parameter (nl.nn.adapterframework.parameters.Parameter)41 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)19 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)15 ParameterList (nl.nn.adapterframework.parameters.ParameterList)13 PipeRunException (nl.nn.adapterframework.core.PipeRunException)12 IOException (java.io.IOException)7 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)7 ParameterException (nl.nn.adapterframework.core.ParameterException)6 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)6 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)5 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)4 Map (java.util.Map)4 Test (org.junit.Test)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2