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:org.apache.cloudstack.ldap.LdapManagerImpl.java

private void closeContext(final LdapContext context) {
    try {/*from ww w. j  av  a 2  s  .c o  m*/
        if (context != null) {
            context.close();
        }
    } catch (final NamingException e) {
        s_logger.warn(e.getMessage(), e);
    }
}

From source file:org.imirsel.plugins.JndiInitializeServlet.java

public void bindObject(String jndiLoc, Object obj) {
    //System.out.println("JNDI Binding: " + jndiLoc);
    try {//  w  w w  .  j  a v  a 2 s. c om
        ctx.bind(jndiLoc, obj);
    } catch (NamingException e) {
        logger.severe("Error occured with JNDI namespace. " + e + ":" + e.getMessage());
    }
}

From source file:edu.internet2.middleware.subject.provider.ESCOJNDISourceAdapter.java

/**
 * {@inheritDoc}//from  ww  w. ja v a  2 s.  c  om
 */
@Override
public Set<Subject> search(final String searchString) {

    final Set<Subject> result = new HashSet<Subject>();
    Search search = this.getSearch("search");
    String searchExpression;

    // If an scope value is found in the search string
    // the string is decomposed and a decorated Search instance is used.
    final int index = searchString.indexOf(ESCOJNDISourceAdapter.SCOPE_DELIM);
    if (index >= 0) {
        final String searchTerm = searchString.substring(0, index).trim();
        final String scopeTerm = searchString.substring(index + ESCOJNDISourceAdapter.SCOPE_DELIM.length())
                .trim();
        final String[] scopes = scopeTerm.split(ESCOJNDISourceAdapter.SCOPE_SEP);
        search = new ESCOSearchWithScopeDecorator(scopes, search);
        searchExpression = searchTerm;
    } else {
        searchExpression = searchString;
    }

    if (search == null) {
        LOGGER.error("searchType: \"search\" not defined.");
        return result;
    }
    final String[] attributeNames = { this.nameAttributeName, this.subjectIDAttributeName,
            this.descriptionAttributeName, };

    @SuppressWarnings("rawtypes")
    NamingEnumeration ldapResults = this.getLdapResults(search, searchExpression, attributeNames);
    if (ldapResults == null) {
        return result;
    }
    try {
        while (ldapResults.hasMore()) {
            SearchResult si = (SearchResult) ldapResults.next();
            Attributes attributes1 = si.getAttributes();
            Subject subject = this.createSubject(attributes1);
            result.add(subject);
        }
    } catch (NamingException ex) {
        LOGGER.error("LDAP Naming Except: " + ex.getMessage(), ex);
    }

    return result;

}

From source file:io.lavagna.service.Ldap.java

public Pair<Boolean, List<String>> authenticateWithParams(String providerUrl, String ldapManagerDn,
        String ldapManagerPwd, String base, String filter, String username, String password) {
    requireNonNull(username);/*from w  w  w.  ja v  a2 s. co  m*/
    requireNonNull(password);
    List<String> msgs = new ArrayList<>();

    msgs.add(format("connecting to %s with managerDn %s", providerUrl, ldapManagerDn));
    try (InitialDirContextCloseable dctx = ldapConnection.context(providerUrl, ldapManagerDn, ldapManagerPwd)) {
        msgs.add(format("connected [ok]"));
        msgs.add(format("now searching user \"%s\" with base %s and filter %s", username, base, filter));

        SearchControls sc = new SearchControls();
        sc.setReturningAttributes(null);
        sc.setSearchScope(SearchControls.SUBTREE_SCOPE);

        List<SearchResult> srs = Ldap.search(dctx, base,
                new MessageFormat(filter).format(new Object[] { Ldap.escapeLDAPSearchFilter(username) }), sc);
        if (srs.size() != 1) {
            String msg = format("error for username \"%s\" we have %d results instead of 1 [error]", username,
                    srs.size());
            msgs.add(msg);
            LOG.info(msg, username, srs.size());
            return Pair.Companion.of(false, msgs);
        }

        msgs.add("user found, now will connect with given password [ok]");

        SearchResult sr = srs.get(0);

        try (InitialDirContextCloseable uctx = ldapConnection.context(providerUrl, sr.getNameInNamespace(),
                password)) {
            msgs.add("user authenticated, everything seems ok [ok]");
            return Pair.Companion.of(true, msgs);
        } catch (NamingException e) {
            String msg = format("error while checking with username \"%s\" with message: %s [error]", username,
                    e.getMessage());
            msgs.add(msg);
            LOG.info(msg, e);
            return Pair.Companion.of(false, msgs);
        }
    } catch (Throwable e) {
        String errMsg = format(
                "error while opening the connection with message: %s [error], check the logs for a more complete trace",
                e.getMessage());
        msgs.add(errMsg);
        msgs.add("Full stacktrace is:");
        msgs.add(ExceptionUtils.getStackTrace(e));
        LOG.error(errMsg, e);
        return Pair.Companion.of(false, msgs);
    }
}

From source file:org.apache.cloudstack.ldap.LdapUserManager.java

public List<LdapUser> getUsersInGroup(String groupName, LdapContext context) throws NamingException {
    String attributeName = _ldapConfiguration.getGroupUniqueMemeberAttribute();
    final SearchControls controls = new SearchControls();
    controls.setSearchScope(_ldapConfiguration.getScope());
    controls.setReturningAttributes(new String[] { attributeName });

    NamingEnumeration<SearchResult> result = context.search(_ldapConfiguration.getBaseDn(),
            generateGroupSearchFilter(groupName), controls);

    final List<LdapUser> users = new ArrayList<LdapUser>();
    //Expecting only one result which has all the users
    if (result.hasMoreElements()) {
        Attribute attribute = result.nextElement().getAttributes().get(attributeName);
        NamingEnumeration<?> values = attribute.getAll();

        while (values.hasMoreElements()) {
            String userdn = String.valueOf(values.nextElement());
            try {
                users.add(getUserForDn(userdn, context));
            } catch (NamingException e) {
                s_logger.info("Userdn: " + userdn + " Not Found:: Exception message: " + e.getMessage());
            }//from  w w  w . j  av  a  2  s.  c  om
        }
    }

    Collections.sort(users);

    return users;
}

From source file:io.fabric8.bridge.model.BrokerConfig.java

@Override
public int hashCode() {
    int val = 0;
    val += (brokerUrl != null) ? brokerUrl.hashCode() : 0;
    val += maxConnections;
    val += (userName != null) ? userName.hashCode() : 0;
    val += (password != null) ? password.hashCode() : 0;
    val += (clientId != null) ? clientId.hashCode() : 0;
    val += (connectionFactoryRef != null) ? connectionFactoryRef.hashCode() : 0;
    val += (destinationResolverRef != null) ? destinationResolverRef.hashCode() : 0;
    if (connectionFactory != null) {
        try {/*from w w w .  j  av  a  2 s.  co m*/
            val += ((Referenceable) connectionFactory).getReference().hashCode();
        } catch (NamingException e) {
            throw new IllegalArgumentException(
                    "Could not get Reference from ConnectionFactory: " + e.getMessage(), e);
        }
    }
    return val;
}

From source file:org.wso2.carbon.appfactory.userstore.AppFactoryTenantManager.java

protected NamingEnumeration searchForObject(String searchFilter, String returnedAtts[], DirContext dirContext,
        String searchBase) throws UserStoreException {
    SearchControls searchCtls;//from   www .j ava  2 s . c  o  m
    searchCtls = new SearchControls();
    searchCtls.setSearchScope(2);
    if (returnedAtts != null && returnedAtts.length > 0)
        searchCtls.setReturningAttributes(returnedAtts);
    try {
        return dirContext.search(searchBase, searchFilter, searchCtls);
    } catch (NamingException e) {
        log.error("Search failed.", e);
        throw new UserStoreException(e.getMessage());
    }

}

From source file:org.sofun.core.security.oauth.OAuthSofunProvider.java

/**
 * Returns the OAuth token storage service.
 * /*  w  w w .java2s .com*/
 * @return a {@link OAuthJPAStorageImpl} instance.
 * @throws OAuthException
 */
private OAuthJPAStorage getStorage() throws OAuthException {
    if (storage == null) {
        InitialContext ctx;
        try {
            ctx = new InitialContext();
            return (OAuthJPAStorage) ctx.lookup("sofun/OAUthJPAStorageImpl/local");
        } catch (NamingException e) {
            throw new OAuthException(500, e.getMessage());
        }
    }
    return storage;
}

From source file:org.teiid.rhq.plugin.PlatformComponent.java

/**
 * @param mc// ww  w  .  ja va  2s  .  c o m
 * @param configuration
 * @throws Exception
 */
private void getProperties(Configuration configuration) {

    // Get all ManagedComponents of type Teiid and subtype dqp
    Set<ManagedComponent> mcSet = null;
    try {
        mcSet = ProfileServiceUtil.getManagedComponents(getConnection(),
                new org.jboss.managed.api.ComponentType(PluginConstants.ComponentType.Platform.TEIID_TYPE,
                        PluginConstants.ComponentType.Platform.TEIID_SUB_TYPE));
    } catch (NamingException e) {
        LOG.error("NamingException getting components in Platform loadConfiguration(): " + e.getMessage()); //$NON-NLS-1$
    } catch (Exception e) {
        LOG.error("Exception getting components in Platform loadConfiguration(): " + e.getMessage()); //$NON-NLS-1$
    }

    for (ManagedComponent mc : mcSet) {
        Map<String, ManagedProperty> mcMap = mc.getProperties();
        String name = mc.getName();
        setProperties(name, mcMap, configuration);
    }
}

From source file:org.wso2.carbon.appfactory.s4.integration.TenantStratosSubscriptionMessagePublisher.java

/**
 * Publish message to MB/ActiveMQ Queue/*from  w ww  . j  a va  2 s .  c o m*/
 * @param runtimeJson runtimebeans as a json
 * @param tenantInfoJson tenantInfoBean as a json
 * @param restServiceProperties propertyMap
 * @param stage current stage
 * @throws AppFactoryEventException
 */
public void publishMessage(String runtimeJson, String tenantInfoJson, Map<String, String> restServiceProperties,
        String stage) throws AppFactoryEventException {
    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, AppFactoryConstants.ANDES_ICF);
    properties.put(AppFactoryConstants.CF_NAME_PREFIX + AppFactoryConstants.CF_NAME,
            Util.getTCPConnectionURL());
    properties.put(AppFactoryConstants.TOPIC, topicName);
    TopicConnection topicConnection = null;
    TopicSession topicSession = null;
    try {
        ctx = new InitialContext(properties);
        connFactory = (TopicConnectionFactory) ctx.lookup(AppFactoryConstants.CF_NAME);
        topicConnection = connFactory.createTopicConnection();
        topicConnection.start();
        topicSession = topicConnection.createTopicSession(false, TopicSession.CLIENT_ACKNOWLEDGE);
        Topic topic = topicSession.createTopic(topicName);
        MapMessage mapMessage = topicSession.createMapMessage();
        mapMessage.setString(AppFactoryConstants.STAGE, stage);
        mapMessage.setString(AppFactoryConstants.RUNTIMES_INFO, runtimeJson);
        mapMessage.setString(AppFactoryConstants.TENANT_INFO, tenantInfoJson);
        javax.jms.TopicPublisher topicPublisher = topicSession.createPublisher(topic);
        topicPublisher.publish(mapMessage);

        //TODO remove this log
        log.info("Message with Id:" + mapMessage.getJMSMessageID() + " was successfully published to the"
                + " topic " + topicName);

        if (log.isDebugEnabled()) {
            log.debug("Message with Id:" + mapMessage.getJMSMessageID() + " was successfully published to the"
                    + " topic " + topicName);
        }
    } catch (NamingException e) {
        String msg = "Failed to initialize InitialContext";
        throw new AppFactoryEventException(msg, e);
    } catch (JMSException e) {
        String msg = "Failed to publish message due to " + e.getMessage();
        throw new AppFactoryEventException(msg, e);
    } finally {
        if (topicSession != null) {
            try {
                topicSession.close();
            } catch (JMSException e) {
                log.error("Failed to close topic session", e);
            }
        }
        if (topicConnection != null) {
            try {
                topicConnection.close();
            } catch (JMSException e) {
                log.error("Failed to close topic connection", e);
            }
        }
    }

}