Search in sources :

Example 66 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class LdapSender method performOperationDelete.

private String performOperationDelete(String entryName, ParameterResolutionContext prc, Map paramValueMap, Attributes attrs) throws SenderException, ParameterException {
    if (manipulationSubject.equals(MANIPULATION_ATTRIBUTE)) {
        String result = null;
        NamingEnumeration na = attrs.getAll();
        while (na.hasMoreElements()) {
            Attribute a = (Attribute) na.nextElement();
            log.debug("Delete attribute: " + a.getID());
            NamingEnumeration values;
            try {
                values = a.getAll();
            } catch (NamingException e1) {
                storeLdapException(e1, prc);
                throw new SenderException("cannot obtain values of Attribute [" + a.getID() + "]", e1);
            }
            while (values.hasMoreElements()) {
                Attributes partialAttrs = new BasicAttributes();
                Attribute singleValuedAttribute;
                String id = a.getID();
                Object value = values.nextElement();
                if (log.isDebugEnabled()) {
                    if (id.toLowerCase().contains("password") || id.toLowerCase().contains("pwd")) {
                        log.debug("Delete value: ***");
                    } else {
                        log.debug("Delete value: " + value);
                    }
                }
                if (unicodePwd && "unicodePwd".equalsIgnoreCase(id)) {
                    singleValuedAttribute = new BasicAttribute(id, encodeUnicodePwd(value));
                } else {
                    singleValuedAttribute = new BasicAttribute(id, value);
                }
                partialAttrs.put(singleValuedAttribute);
                DirContext dirContext = null;
                try {
                    dirContext = getDirContext(paramValueMap);
                    dirContext.modifyAttributes(entryName, DirContext.REMOVE_ATTRIBUTE, partialAttrs);
                } catch (NamingException e) {
                    // [LDAP: error code 16 - 00002085: AtrErr: DSID-03151F03, #1...
                    if (e.getMessage().startsWith("[LDAP: error code 16 - ") || e.getMessage().startsWith("[LDAP: error code 32 - ")) {
                        if (log.isDebugEnabled())
                            log.debug("Operation [" + getOperation() + "] successful: " + e.getMessage());
                        result = DEFAULT_RESULT_DELETE;
                    } else {
                        storeLdapException(e, prc);
                        throw new SenderException("Exception in operation [" + getOperation() + "] entryName [" + entryName + "]", e);
                    }
                } finally {
                    closeDirContext(dirContext);
                }
            }
        }
        if (result != null) {
            return result;
        }
        return DEFAULT_RESULT;
    } else {
        DirContext dirContext = null;
        try {
            dirContext = getDirContext(paramValueMap);
            dirContext.unbind(entryName);
            return DEFAULT_RESULT;
        } catch (NamingException e) {
            // [LDAP: error code 32 - No Such Object...
            if (e.getMessage().startsWith("[LDAP: error code 32 - ")) {
                if (log.isDebugEnabled())
                    log.debug("Operation [" + getOperation() + "] successful: " + e.getMessage());
                return DEFAULT_RESULT_DELETE;
            } else {
                storeLdapException(e, prc);
                throw new SenderException("Exception in operation [" + getOperation() + "] entryName [" + entryName + "]", e);
            }
        } finally {
            closeDirContext(dirContext);
        }
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) NamingEnumeration(javax.naming.NamingEnumeration) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) SenderException(nl.nn.adapterframework.core.SenderException)

Example 67 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class LdapSender method performOperationSearch.

// Constructs a search constraints using arguments.
// public SearchControls(int scope,long countlim,int timelim, String[] attrs, boolean retobj,boolean deref)
// Parameters:
// scope - The search scope. One of: OBJECT_SCOPE, ONELEVEL_SCOPE, SUBTREE_SCOPE.
// timelim - The number of milliseconds to wait before returning. If 0, wait indefinitely.
// deref - If true, dereference links during search.
// countlim - The maximum number of entries to return. If 0, return all entries that satisfy filter.
// retobj - If true, return the object bound to the name of the entry; if false, do not return object.
// attrs - The identifiers of the attributes to return along with the entry. If null, return all attributes. If empty return no attributes.
private String performOperationSearch(String entryName, ParameterResolutionContext prc, Map paramValueMap, String filterExpression, int scope) throws SenderException, ParameterException {
    int timeout = getSearchTimeout();
    SearchControls controls = new SearchControls(scope, getMaxEntriesReturned(), timeout, getAttributesReturnedParameter(), false, false);
    // attrs = parseAttributesFromMessage(message);
    DirContext dirContext = null;
    try {
        dirContext = getDirContext(paramValueMap);
        return searchResultsToXml(dirContext.search(entryName, filterExpression, controls)).toXML();
    } catch (NamingException e) {
        if (isReplyNotFound() && e.getMessage().equals("Unprocessed Continuation Reference(s)")) {
            if (log.isDebugEnabled())
                log.debug("Searching object not found using filter[" + filterExpression + "]");
            return DEFAULT_RESULT_SEARCH;
        } else {
            storeLdapException(e, prc);
            throw new SenderException("Exception searching using filter [" + filterExpression + "]", e);
        }
    } finally {
        closeDirContext(dirContext);
    }
}
Also used : SearchControls(javax.naming.directory.SearchControls) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) SenderException(nl.nn.adapterframework.core.SenderException)

Example 68 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class LdapSender method parseAttributesFromMessage.

/**
 * Digests the input message and creates a <code>BasicAttributes</code> object, containing <code>BasicAttribute</code> objects,
 * which represent the attributes of the specified entry.
 *
 * <pre>
 * BasicAttributes implements Attributes
 * contains
 * BasicAttribute implements Attribute
 * </pre>
 *
 * @see javax.naming.directory.Attributes
 * @see javax.naming.directory.BasicAttributes
 * @see javax.naming.directory.Attribute
 * @see javax.naming.directory.BasicAttribute
 */
private Attributes parseAttributesFromMessage(String message) throws SenderException {
    Digester digester = new Digester();
    digester.addObjectCreate("*/attributes", BasicAttributes.class);
    digester.addFactoryCreate("*/attributes/attribute", BasicAttributeFactory.class);
    digester.addSetNext("*/attributes/attribute", "put");
    digester.addCallMethod("*/attributes/attribute/value", "add", 0);
    try {
        return (Attributes) digester.parse(new StringReader(message));
    } catch (Exception e) {
        throw new SenderException("[" + this.getClass().getName() + "] exception in digesting", e);
    }
}
Also used : Digester(org.apache.commons.digester.Digester) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) StringReader(java.io.StringReader) SenderException(nl.nn.adapterframework.core.SenderException) 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 69 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class LdapSender method encodeUnicodePwd.

/**
 * For more information see:
 * http://msdn.microsoft.com/en-us/library/cc223248.aspx and
 * http://stackoverflow.com/questions/15335614/changing-active-directory-user-password-from-java-program
 * http://blogs.msdn.com/b/alextch/archive/2012/05/15/how-to-set-active-directory-password-from-java-application.aspx
 * @throws SenderException
 */
private byte[] encodeUnicodePwd(Object value) throws SenderException {
    log.debug("Encode unicodePwd value");
    String quotedPassword = "\"" + value + "\"";
    try {
        return quotedPassword.getBytes("UTF-16LE");
    } catch (UnsupportedEncodingException e) {
        throw new SenderException(e);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 70 with SenderException

use of nl.nn.adapterframework.core.SenderException in project iaf by ibissource.

the class LdapSender method performOperationCreate.

private String performOperationCreate(String entryName, ParameterResolutionContext prc, Map paramValueMap, Attributes attrs) throws SenderException, ParameterException {
    if (manipulationSubject.equals(MANIPULATION_ATTRIBUTE)) {
        String result = null;
        NamingEnumeration na = attrs.getAll();
        while (na.hasMoreElements()) {
            Attribute a = (Attribute) na.nextElement();
            log.debug("Create attribute: " + a.getID());
            NamingEnumeration values;
            try {
                values = a.getAll();
            } catch (NamingException e1) {
                storeLdapException(e1, prc);
                throw new SenderException("cannot obtain values of Attribute [" + a.getID() + "]", e1);
            }
            while (values.hasMoreElements()) {
                Attributes partialAttrs = new BasicAttributes();
                Attribute singleValuedAttribute;
                String id = a.getID();
                Object value = values.nextElement();
                if (log.isDebugEnabled()) {
                    if (id.toLowerCase().contains("password") || id.toLowerCase().contains("pwd")) {
                        log.debug("Create value: ***");
                    } else {
                        log.debug("Create value: " + value);
                    }
                }
                if (unicodePwd && "unicodePwd".equalsIgnoreCase(id)) {
                    singleValuedAttribute = new BasicAttribute(id, encodeUnicodePwd(value));
                } else {
                    singleValuedAttribute = new BasicAttribute(id, value);
                }
                partialAttrs.put(singleValuedAttribute);
                DirContext dirContext = null;
                try {
                    dirContext = getDirContext(paramValueMap);
                    dirContext.modifyAttributes(entryName, DirContext.ADD_ATTRIBUTE, partialAttrs);
                } catch (NamingException e) {
                    // [LDAP: error code 20 - Attribute Or Value Exists]
                    if (e.getMessage().startsWith("[LDAP: error code 20 - ")) {
                        if (log.isDebugEnabled())
                            log.debug("Operation [" + getOperation() + "] successful: " + e.getMessage());
                        result = DEFAULT_RESULT_CREATE_OK;
                    } else {
                        storeLdapException(e, prc);
                        throw new SenderException("Exception in operation [" + getOperation() + "] entryName [" + entryName + "]", e);
                    }
                } finally {
                    closeDirContext(dirContext);
                }
            }
        }
        if (result != null) {
            return result;
        }
        return DEFAULT_RESULT;
    } else {
        DirContext dirContext = null;
        try {
            if (unicodePwd) {
                Enumeration enumeration = attrs.getIDs();
                while (enumeration.hasMoreElements()) {
                    String id = (String) enumeration.nextElement();
                    if ("unicodePwd".equalsIgnoreCase(id)) {
                        Attribute attr = attrs.get(id);
                        for (int i = 0; i < attr.size(); i++) {
                            attr.set(i, encodeUnicodePwd(attr.get(i)));
                        }
                    }
                }
            }
            dirContext = getDirContext(paramValueMap);
            dirContext.bind(entryName, null, attrs);
            return DEFAULT_RESULT;
        } catch (NamingException e) {
            // if (log.isDebugEnabled()) log.debug("Exception in operation [" + getOperation()+ "] entryName ["+entryName+"]", e);
            if (log.isDebugEnabled())
                log.debug("Exception in operation [" + getOperation() + "] entryName [" + entryName + "]: " + e.getMessage());
            // [LDAP: error code 68 - Entry Already Exists]
            if (e.getMessage().startsWith("[LDAP: error code 68 - ")) {
                return DEFAULT_RESULT_CREATE_OK;
            } else {
                storeLdapException(e, prc);
                throw new SenderException(e);
            }
        } finally {
            closeDirContext(dirContext);
        }
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) Enumeration(java.util.Enumeration) NamingEnumeration(javax.naming.NamingEnumeration) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) NamingEnumeration(javax.naming.NamingEnumeration) NamingException(javax.naming.NamingException) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

SenderException (nl.nn.adapterframework.core.SenderException)130 TimeOutException (nl.nn.adapterframework.core.TimeOutException)41 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)37 IOException (java.io.IOException)36 SQLException (java.sql.SQLException)25 HashMap (java.util.HashMap)21 ParameterException (nl.nn.adapterframework.core.ParameterException)21 PreparedStatement (java.sql.PreparedStatement)20 Map (java.util.Map)20 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)18 Iterator (java.util.Iterator)17 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)16 InputStream (java.io.InputStream)15 ResultSet (java.sql.ResultSet)13 Element (org.w3c.dom.Element)13 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)12 Date (java.util.Date)10 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)10 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9