Example usage for javax.naming NamingException getMessage

List of usage examples for javax.naming NamingException getMessage

Introduction

In this page you can find the example usage for javax.naming NamingException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:nl.nn.adapterframework.ldap.LdapSender.java

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 {//  w w w . j av a 2 s  .com
        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);
    }
}

From source file:com.netspective.axiom.schema.table.BasicTable.java

public void update(ConnectionContext cc, Row row, String whereCond, Object[] whereCondBindParams)
        throws SQLException {
    for (int i = 0; i < triggers.length; i++)
        triggers[i].beforeTableRowUpdate(cc, row);

    try {//from  ww w.  java2 s  .c o m
        cc.getDatabasePolicy().updateValues(cc,
                DatabasePolicy.DMLFLAG_EXECUTE | DatabasePolicy.DMLFLAG_USE_BIND_PARAMS, row.getColumnValues(),
                row, whereCond, whereCondBindParams);
    } catch (NamingException e) {
        log.error("Error while updating row " + row + " whereCond " + whereCond, e);
        throw new SQLException(e.getMessage());
    }

    for (int i = 0; i < triggers.length; i++)
        triggers[i].afterTableRowUpdate(cc, row);
}

From source file:org.lsc.jndi.JndiServices.java

public SearchResult readEntry(final String base, final String filter, final boolean allowError,
        final SearchControls sc) throws NamingException {
    try {/*  w  w w .j a  va 2 s.  com*/
        return doReadEntry(base, filter, allowError, sc);
    } catch (NamingException nex) {
        if (nex instanceof CommunicationException || nex instanceof ServiceUnavailableException) {
            LOGGER.info("Communication error, retrying: " + nex.getMessage());
            LOGGER.debug(nex.getMessage(), nex);
            try {
                initConnection();
            } catch (IOException ioex) {
                LOGGER.error("I/O error: " + ioex.getMessage());
                LOGGER.debug(ioex.getMessage(), ioex);
                // throw the initial communication exception
                throw nex;
            }
            return doReadEntry(base, filter, allowError, sc);
        } else {
            throw nex;
        }
    }
}

From source file:org.lsc.jndi.JndiServices.java

/**
 * Search for a list of DN./*from www. j  a v a  2  s  . c o  m*/
 *
 * This method is a simple LDAP search operation which is attended to
 * return a list of the entries DN
 *
 * @param base
 *                the base of the search operation
 * @param filter
 *                the filter of the search operation
 * @param scope
 *                the scope of the search operation
 * @return the dn of each entry that is returned by the directory
 * @throws NamingException
 *                 thrown if something goes wrong
 */
public List<String> getDnList(final String base, final String filter, final int scope) throws NamingException {
    try {
        return doGetDnList(base, filter, scope);
    } catch (NamingException nex) {
        if (nex instanceof CommunicationException || nex instanceof ServiceUnavailableException) {
            LOGGER.warn("Communication error, retrying: " + nex.getMessage());
            LOGGER.debug(nex.getMessage(), nex);
            try {
                initConnection();
            } catch (IOException ioex) {
                LOGGER.error("I/O error: " + ioex.getMessage());
                LOGGER.debug(ioex.getMessage(), ioex);
                // throw the initial communication exception
                throw nex;
            }
            return doGetDnList(base, filter, scope);
        } else {
            throw nex;
        }
    }
}

From source file:org.lsc.jndi.JndiServices.java

/**
 * Search for an entry./*from w ww  .  j a v a  2  s .  c o  m*/
 *
 * This method is a simple LDAP search operation with SUBTREE search
 * control
 *
 * @param base the base of the search operation
 * @param filter  the filter of the search operation
 * @param sc the search controls
 * @param scope the search scope to use
 * @return the entry or null if not found
 * @throws SizeLimitExceededException
 *                thrown if more than one entry is returned by the search
 * @throws NamingException
 *                 thrown if something goes wrong
 */
public SearchResult getEntry(final String base, final String filter, final SearchControls sc, final int scope)
        throws NamingException {
    try {
        return doGetEntry(base, filter, sc, scope);
    } catch (NamingException nex) {
        if (nex instanceof CommunicationException || nex instanceof ServiceUnavailableException) {
            LOGGER.warn("Communication error, retrying: " + nex.getMessage());
            LOGGER.debug(nex.getMessage(), nex);
            try {
                initConnection();
            } catch (IOException ioex) {
                LOGGER.error("I/O error: " + ioex.getMessage());
                LOGGER.debug(ioex.getMessage(), ioex);
                // throw the initial communication exception
                throw nex;
            }
            return doGetEntry(base, filter, sc, scope);
        } else {
            throw nex;
        }
    }
}

From source file:org.lsc.jndi.JndiServices.java

/**
 * Search for a list of attribute values
 *
 * This method is a simple LDAP search operation which is attended to
 * return a list of the attribute values in all returned entries
 *
 * @param base the base of the search operation
 * @param filter the filter of the search operation
 * @param scope the scope of the search operation
 * @param attrsNames table of attribute names to get
 * @return Map of DNs of all entries that are returned by the directory with an associated map of attribute names and values (never null)
 * @throws NamingException thrown if something goes wrong
 *//*  w  w  w.j a v  a2 s  . c om*/
public Map<String, LscDatasets> getAttrsList(final String base, final String filter, final int scope,
        final List<String> attrsNames) throws NamingException {
    try {
        return doGetAttrsList(base, filter, scope, attrsNames);
    } catch (NamingException nex) {
        if (nex instanceof CommunicationException || nex instanceof ServiceUnavailableException) {
            LOGGER.warn("Communication error, retrying: " + nex.getMessage());
            LOGGER.debug(nex.getMessage(), nex);
            try {
                initConnection();
            } catch (IOException ioex) {
                LOGGER.error("I/O error: " + ioex.getMessage());
                LOGGER.debug(ioex.getMessage(), ioex);
                // throw the initial communication exception
                throw nex;
            }
            return doGetAttrsList(base, filter, scope, attrsNames);
        } else {
            throw nex;
        }
    }
}

From source file:org.lsc.jndi.JndiServices.java

/**
 * Delete children recursively/*from w  ww .  j  a va2s  .  c om*/
 * @param distinguishName the tree head to delete
 * @throws NamingException thrown if an error is encountered
 */
private void deleteChildrenRecursively(String distinguishName) throws NamingException {
    try {
        doDeleteChildrenRecursively(distinguishName);
        return;
    } catch (NamingException nex) {
        if (nex instanceof CommunicationException || nex instanceof ServiceUnavailableException) {
            LOGGER.warn("Communication error, retrying: " + nex.getMessage());
            LOGGER.debug(nex.getMessage(), nex);
            try {
                initConnection();
            } catch (IOException ioex) {
                LOGGER.error("I/O error: " + ioex.getMessage());
                LOGGER.debug(ioex.getMessage(), ioex);
                // throw the initial communication exception
                throw nex;
            }
            doDeleteChildrenRecursively(distinguishName);
            return;
        } else {
            throw nex;
        }
    }
}

From source file:org.overlord.sramp.events.jms.JMSEventProducer.java

@Override
public void startup() {
    if (SrampConfig.isJmsEnabled()) {
        try {//w w  w. ja v a2 s  .c  om
            String connectionFactoryName = SrampConfig.getConfigProperty(
                    SrampConstants.SRAMP_CONFIG_EVENT_JMS_CONNECTIONFACTORY, "ConnectionFactory"); //$NON-NLS-1$

            // Note that both properties end up doing the same thing.  Technically, we could combine both into one
            // single sramp.config.events.jms.destinations, but leaving them split for readability.
            String topicNamesProp = SrampConfig.getConfigProperty(SrampConstants.SRAMP_CONFIG_EVENT_JMS_TOPICS,
                    ""); //$NON-NLS-1$
            String[] topicNames = new String[0];
            if (StringUtils.isNotEmpty(topicNamesProp)) {
                topicNames = topicNamesProp.split(","); //$NON-NLS-1$
            }
            String queueNamesProp = SrampConfig.getConfigProperty(SrampConstants.SRAMP_CONFIG_EVENT_JMS_QUEUES,
                    ""); //$NON-NLS-1$
            String[] queueNames = new String[0];
            if (StringUtils.isNotEmpty(queueNamesProp)) {
                queueNames = queueNamesProp.split(","); //$NON-NLS-1$
            }

            try {
                // First, see if a ConnectionFactory and Topic/Queue exists on JNDI.  If so, assume JMS is properly
                // setup in a Java EE container and simply use it.

                ConnectionFactory connectionFactory = (ConnectionFactory) jndiLookup(connectionFactoryName);
                connection = connectionFactory.createConnection();
                session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

                for (String topicName : topicNames) {
                    Topic topic = (Topic) jndiLookup(topicName);
                    destinations.add(topic);
                }

                for (String queueName : queueNames) {
                    Queue queue = (Queue) jndiLookup(queueName);
                    destinations.add(queue);
                }
            } catch (NamingException e) {
                // Otherwise, JMS wasn't setup. Assume we need to start an embedded
                // ActiveMQ broker and create the destinations.

                String bindAddress = "tcp://localhost:" //$NON-NLS-1$
                        + SrampConfig.getConfigProperty(SrampConstants.SRAMP_CONFIG_EVENT_JMS_PORT, "61616"); //$NON-NLS-1$

                LOG.warn(Messages.i18n.format("org.overlord.sramp.events.jms.embedded_broker", bindAddress)); //$NON-NLS-1$

                session = null;
                destinations.clear();

                BrokerService broker = new BrokerService();
                broker.addConnector(bindAddress);
                broker.start();

                // Event though we added a TCP connector, above, ActiveMQ also exposes the broker over the "vm"
                // protocol. It optimizes performance for connections on the same JVM.
                ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); //$NON-NLS-1$
                initActiveMQ(connectionFactory, topicNames, queueNames);
            }
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
    }
}

From source file:org.nuxeo.ecm.directory.ldap.LDAPReference.java

/**
 * Fetch both statically and dynamically defined references and merge the results.
 *
 * @see org.nuxeo.ecm.directory.Reference#getSourceIdsForTarget(String)
 *//*from  ww  w .jav a2s  . c o  m*/
@Override
public List<String> getSourceIdsForTarget(String targetId) throws DirectoryException {

    // container to hold merged references
    Set<String> sourceIds = new TreeSet<>();
    SearchResult targetLdapEntry = null;
    String targetDn = null;

    // step #1: resolve static references
    String staticAttributeId = getStaticAttributeId();
    if (staticAttributeId != null) {
        // step #1.1: fetch the dn of the targetId entry in the target
        // directory by the static dn valued strategy
        LDAPDirectory targetDir = getTargetLDAPDirectory();

        if (staticAttributeIdIsDn) {
            try (LDAPSession targetSession = (LDAPSession) targetDir.getSession()) {
                targetLdapEntry = targetSession.getLdapEntry(targetId, false);
                if (targetLdapEntry == null) {
                    String msg = String.format(
                            "Failed to perform inverse lookup on LDAPReference"
                                    + " resolving field '%s' of '%s' to entries of '%s'"
                                    + " using the static content of attribute '%s':"
                                    + " entry '%s' cannot be found in '%s'",
                            fieldName, sourceDirectory, targetDirectoryName, staticAttributeId, targetId,
                            targetDirectoryName);
                    throw new DirectoryEntryNotFoundException(msg);
                }
                targetDn = pseudoNormalizeDn(targetLdapEntry.getNameInNamespace());

            } catch (NamingException e) {
                throw new DirectoryException(
                        "error fetching " + targetId + " from " + targetDirectoryName + ": " + e.getMessage(),
                        e);
            }
        }

        // step #1.2: search for entries that reference that dn in the
        // source directory and collect their ids
        LDAPDirectory ldapSourceDirectory = getSourceLDAPDirectory();

        String filterExpr = String.format("(&(%s={0})%s)", staticAttributeId,
                ldapSourceDirectory.getBaseFilter());
        String[] filterArgs = new String[1];

        if (staticAttributeIdIsDn) {
            filterArgs[0] = targetDn;
        } else {
            filterArgs[0] = targetId;
        }

        String searchBaseDn = ldapSourceDirectory.getDescriptor().getSearchBaseDn();
        SearchControls sctls = ldapSourceDirectory.getSearchControls();
        try (LDAPSession sourceSession = (LDAPSession) ldapSourceDirectory.getSession()) {
            if (log.isDebugEnabled()) {
                log.debug(String.format(
                        "LDAPReference.getSourceIdsForTarget(%s): LDAP search search base='%s'"
                                + " filter='%s' args='%s' scope='%s' [%s]",
                        targetId, searchBaseDn, filterExpr, StringUtils.join(filterArgs, ", "),
                        sctls.getSearchScope(), this));
            }
            NamingEnumeration<SearchResult> results = sourceSession.dirContext.search(searchBaseDn, filterExpr,
                    filterArgs, sctls);

            try {
                while (results.hasMore()) {
                    Attributes attributes = results.next().getAttributes();
                    // NXP-2461: check that id field is filled
                    Attribute attr = attributes.get(sourceSession.idAttribute);
                    if (attr != null) {
                        Object value = attr.get();
                        if (value != null) {
                            sourceIds.add(value.toString());
                        }
                    }
                }
            } finally {
                results.close();
            }
        } catch (NamingException e) {
            throw new DirectoryException("error during reference search for " + filterArgs[0], e);
        }
    }
    // step #2: resolve dynamic references
    String dynamicAttributeId = this.dynamicAttributeId;
    if (dynamicAttributeId != null) {

        LDAPDirectory ldapSourceDirectory = getSourceLDAPDirectory();
        LDAPDirectory ldapTargetDirectory = getTargetLDAPDirectory();
        String searchBaseDn = ldapSourceDirectory.getDescriptor().getSearchBaseDn();

        try (LDAPSession sourceSession = (LDAPSession) ldapSourceDirectory.getSession();
                LDAPSession targetSession = (LDAPSession) ldapTargetDirectory.getSession()) {
            // step #2.1: fetch the target entry to apply the ldap url
            // filters of the candidate sources on it
            if (targetLdapEntry == null) {
                // only fetch the entry if not already fetched by the
                // static
                // attributes references resolution
                targetLdapEntry = targetSession.getLdapEntry(targetId, false);
            }
            if (targetLdapEntry == null) {
                String msg = String.format(
                        "Failed to perform inverse lookup on LDAPReference"
                                + " resolving field '%s' of '%s' to entries of '%s'"
                                + " using the dynamic content of attribute '%s':"
                                + " entry '%s' cannot be found in '%s'",
                        fieldName, ldapSourceDirectory, targetDirectoryName, dynamicAttributeId, targetId,
                        targetDirectoryName);
                throw new DirectoryException(msg);
            }
            targetDn = pseudoNormalizeDn(targetLdapEntry.getNameInNamespace());
            Attributes targetAttributes = targetLdapEntry.getAttributes();

            // step #2.2: find the list of entries that hold candidate
            // dynamic links in the source directory
            SearchControls sctls = ldapSourceDirectory.getSearchControls();
            sctls.setReturningAttributes(new String[] { sourceSession.idAttribute, dynamicAttributeId });
            String filterExpr = String.format("%s=*", dynamicAttributeId);

            if (log.isDebugEnabled()) {
                log.debug(String.format(
                        "LDAPReference.getSourceIdsForTarget(%s): LDAP search search base='%s'"
                                + " filter='%s' scope='%s' [%s]",
                        targetId, searchBaseDn, filterExpr, sctls.getSearchScope(), this));
            }
            NamingEnumeration<SearchResult> results = sourceSession.dirContext.search(searchBaseDn, filterExpr,
                    sctls);
            try {
                while (results.hasMore()) {
                    // step #2.3: for each sourceId and each ldapUrl test
                    // whether the current target entry matches the
                    // collected
                    // URL
                    Attributes sourceAttributes = results.next().getAttributes();

                    NamingEnumeration<?> ldapUrls = sourceAttributes.get(dynamicAttributeId).getAll();
                    try {
                        while (ldapUrls.hasMore()) {
                            LdapURL ldapUrl = new LdapURL(ldapUrls.next().toString());
                            String candidateDN = pseudoNormalizeDn(ldapUrl.getDN());
                            // check base URL
                            if (!targetDn.endsWith(candidateDN)) {
                                continue;
                            }

                            // check onelevel scope constraints
                            if ("onelevel".equals(ldapUrl.getScope())) {
                                int targetDnSize = new LdapName(targetDn).size();
                                int urlDnSize = new LdapName(candidateDN).size();
                                if (targetDnSize - urlDnSize > 1) {
                                    // target is not a direct child of the
                                    // DN of the
                                    // LDAP URL
                                    continue;
                                }
                            }

                            // check that the target entry matches the
                            // filter
                            if (getFilterMatcher().match(targetAttributes, ldapUrl.getFilter())) {
                                // the target match the source url, add it
                                // to the
                                // collected ids
                                sourceIds.add(sourceAttributes.get(sourceSession.idAttribute).get().toString());
                            }
                        }
                    } finally {
                        ldapUrls.close();
                    }
                }
            } finally {
                results.close();
            }
        } catch (NamingException e) {
            throw new DirectoryException("error during reference search for " + targetId, e);
        }
    }

    /*
     * This kind of reference is not supported because Active Directory use filter expression not yet supported by
     * LDAPFilterMatcher. See NXP-4562
     */
    if (dynamicReferences != null && dynamicReferences.length > 0) {
        log.error("This kind of reference is not supported.");
    }

    return new ArrayList<>(sourceIds);
}

From source file:org.josso.gateway.identity.service.store.ldap.LDAPIdentityStore.java

/**
 * Retrieves the roles for the supplied user.
 *
 * @param key the user id of the user for whom role information is to be retrieved.
 * @return the roles associated with the supplied user.
 * @throws SSOIdentityException fatal exception obtaining user roles.
 *//*w  w w.  j av  a 2  s . c  om*/
public BaseRole[] findRolesByUserKey(UserKey key) throws SSOIdentityException {

    try {

        if (!(key instanceof SimpleUserKey)) {
            throw new SSOIdentityException("Unsupported key type : " + key.getClass().getName());
        }

        String[] roleNames = selectRolesByUsername(((SimpleUserKey) key).getId());
        List roles = new ArrayList();
        for (int i = 0; i < roleNames.length; i++) {
            String roleName = roleNames[i];
            BaseRole role = new BaseRoleImpl();
            role.setName(roleName);
            roles.add(role);
        }

        return (BaseRole[]) roles.toArray(new BaseRole[roles.size()]);
    } catch (NamingException e) {
        logger.error("NamingException while obtaining roles", e);
        throw new SSOIdentityException("Error obtaining roles for user : " + key);
    } catch (IOException e) {
        logger.error("StartTLS error", e);
        throw new SSOIdentityException("StartTLS error : " + e.getMessage());
    }
}