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:com.aurel.track.util.LdapUtil.java

/**
 * Gets the LDAP users/*from www  . j av  a 2 s.  c o m*/
 * 
 * @param ctx
 * @param loginAttributeName
 * @param searchStrs
 * @return
 */
static List<TPersonBean> getLdapUsers(LdapContext ctx, String loginAttributeName, List<String> searchStrs) {
    List<TPersonBean> personBeans = new LinkedList<TPersonBean>();
    if (ldapMap == null || ldapMap.isEmpty()) {
        LOGGER.error("There is no LDAP mapping in quartz-jobs.xml. Please provide!");
        return personBeans;
    }
    String firstNameAttributeName = ldapMap.get(LdapUtil.LDAP_CONFIG.FIRST_NAME);
    String lastNameAttributName = ldapMap.get(LdapUtil.LDAP_CONFIG.LAST_NAME);
    String emailAttributeName = ldapMap.get(LdapUtil.LDAP_CONFIG.EMAIL);
    String phoneAttributName = ldapMap.get(LdapUtil.LDAP_CONFIG.PHONE);
    for (String searchStr : searchStrs) {
        LOGGER.debug("Searching by filter " + searchStr);
        SearchControls ctls = new SearchControls();
        ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        try {
            NamingEnumeration<SearchResult> results = ctx.search("", searchStr, ctls);
            while (results != null && results.hasMore()) {
                SearchResult sr = (SearchResult) results.next();
                TPersonBean personBean = getPersonBean(sr, loginAttributeName, firstNameAttributeName,
                        lastNameAttributName, emailAttributeName, phoneAttributName);
                if (personBean != null) {
                    LOGGER.debug("Search successful " + searchStr);
                    personBeans.add(personBean);
                }
            }
        } catch (NamingException e) {
            LOGGER.warn("Search failed with " + e.getMessage());
            LOGGER.debug(ExceptionUtils.getStackTrace(e));
        }
    }
    return personBeans;
}

From source file:eu.uqasar.service.AuthenticationService.java

private boolean authenticate(String attemptedPassword, User user) {
    if (user.getSource() == LDAP) {
        try {//from   ww  w.ja  v  a 2  s .  com
            LdapManager manager = LdapManager.getInstance(ldapSettingsService);
            return manager.authenticateBySAMAccountName(user.getUserName(), attemptedPassword);
        } catch (NamingException ex) {
            logger.error(ex.getMessage(), ex);
            return false;
        }
    } else {
        return authenticate(attemptedPassword, user.getPassword(), user.getPwSalt());
    }
}

From source file:org.openiam.idm.srvc.synch.service.generic.LdapAdapterForGenericObject.java

public Response testConnection(SynchConfig config) {
    try {/*from   w  w w . jav  a2s  .  c om*/
        if (connect(config)) {
            closeConnection();
            Response resp = new Response(ResponseStatus.SUCCESS);
            return resp;
        } else {
            Response resp = new Response(ResponseStatus.FAILURE);
            resp.setErrorCode(ResponseCode.FAIL_CONNECTION);
            return resp;
        }
    } catch (NamingException e) {
        e.printStackTrace();
        log.error(e);

        Response resp = new Response(ResponseStatus.FAILURE);
        resp.setErrorCode(ResponseCode.FAIL_CONNECTION);
        resp.setErrorText(e.getMessage());
        return resp;
    }
}

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

@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }// w  w  w.  j  av  a  2 s  .c  o  m
    if (obj != null && obj instanceof BrokerConfig) {

        BrokerConfig config = (BrokerConfig) obj;
        // ignore destinationResolver
        boolean retVal = (this.brokerUrl != null ? this.brokerUrl.equals(config.brokerUrl)
                : config.brokerUrl == null) && this.maxConnections == config.maxConnections
                && (this.userName != null ? this.userName.equals(config.userName) : config.userName == null)
                && (this.password != null ? this.password.equals(config.password) : config.password == null)
                && (this.clientId != null ? this.clientId.equals(config.clientId) : config.clientId == null)
                && (this.connectionFactoryRef != null
                        ? this.connectionFactoryRef.equals(config.connectionFactoryRef)
                        : config.connectionFactoryRef == null)
                && (this.destinationResolverRef != null
                        ? this.destinationResolverRef.equals(config.destinationResolverRef)
                        : config.destinationResolverRef == null);

        if (retVal && connectionFactory != null) {
            if (config.connectionFactory == null) {
                retVal = false;
            } else {
                try {
                    retVal = ((Referenceable) connectionFactory).getReference()
                            .equals(((Referenceable) config.connectionFactory).getReference());
                } catch (NamingException e) {
                    throw new IllegalArgumentException(
                            "Could not get Reference from ConnectionFactory: " + e.getMessage(), e);
                }
            }
        } else if (retVal) {
            retVal = (config.connectionFactory == null);
        }

        return retVal;
    }

    return false;
}

From source file:com.ocpsoft.pretty.faces.el.resolver.CDIBeanNameResolver.java

/**
 * Tries to get the BeanManager from JNDI
 * /*ww  w  .j a  va  2 s.  c om*/
 * @param jndiName
 *           The JNDI name used for lookup
 * @return BeanManager instance or <code>null</code>
 */
private Object getBeanManagerFromJNDI(String jndiName) {

    try {
        // perform lookup
        InitialContext initialContext = new InitialContext();
        Object obj = initialContext.lookup(jndiName);

        if (log.isTraceEnabled()) {
            log.trace("Found BeanManager in: " + jndiName);
        }

        return obj;

    } catch (NamingException e) {
        if (log.isDebugEnabled()) {
            log.debug("Unable to get BeanManager from '" + jndiName + "': " + e.getMessage());
        }
    }

    return null;
}

From source file:org.asimba.engine.cluster.JGroupsCluster.java

/**
 * Return the JChannel instance configured for this JGroupsCluster<br/>
 * Note: the JChannel is connected to upon first instantiation
 */// w  w  w . jav a2  s.  c o m
@Override
public Object getChannel() {
    if (_jChannel == null) {
        String sNodeId = null;

        // initialize channel from initialcontext
        try {
            InitialContext ic = new InitialContext();
            sNodeId = (String) ic.lookup("java:comp/env/" + PROP_ASIMBA_NODE_ID);
            _oLogger.debug("Trying to read the node id from initial context");
        } catch (NamingException e) {
            _oLogger.warn("Getting initialcontext failed! " + e.getMessage());
        }

        if (StringUtils.isEmpty(sNodeId)) {
            // Initialize the channel, based on configuration
            sNodeId = System.getProperty(PROP_ASIMBA_NODE_ID);
        }

        if (StringUtils.isEmpty(sNodeId)) {
            try {
                // Initialize the channel, based on hostname
                sNodeId = getHostName();
            } catch (UnknownHostException ex) {
                _oLogger.error("Getting hostname failed! " + ex.getMessage());
            }
        }

        try {
            if (sNodeId != null) {
                // Apply custom options:
                Map<String, String> mOptions = _mCustomOptions.get(sNodeId);

                _oLogger.info("System property " + PROP_ASIMBA_NODE_ID + " specified; applying"
                        + "custom properties JGroupsCluster '" + _sID + "', node '" + sNodeId + "'");

                for (Entry<String, String> prop : mOptions.entrySet()) {
                    System.setProperty(prop.getKey(), prop.getValue());
                }

            } else {
                _oLogger.info("No " + PROP_ASIMBA_NODE_ID + " system property specified, so no "
                        + "custom properties applied for JGroupsCluster '" + _sID + "'");
            }

            _jChannel = new JChannel(_sConfigLocation);
            if (_sID != null)
                _jChannel.setName(_sID);

            _oLogger.info("Connecting to cluster " + _sID + " with name " + _sClusterName);
            _jChannel.connect(_sClusterName);

        } catch (Exception e) {
            _oLogger.error("Could not create JChannel: " + e.getMessage(), e);
            return null;
        }
    }

    return _jChannel;
}

From source file:org.sdnmq.jms.PacketForwarder.java

/**
 * Setup MQ// w  w w .  j  a va 2s.c  o m
 */
private boolean initMQ() {
    log.trace("Setting up MQ system");

    Properties jndiProps = JNDIHelper.getJNDIProperties();

    Context ctx = null;
    try {
        ctx = new InitialContext(jndiProps);
    } catch (NamingException e) {
        log.error(e.getMessage());
        releaseMQ();
        return false;
    }

    QueueConnectionFactory queueFactory = null;
    try {
        queueFactory = (QueueConnectionFactory) ctx.lookup("QueueConnectionFactory");
    } catch (NamingException e) {
        log.error(e.getMessage());
        releaseMQ();
        return false;
    }

    try {
        connection = queueFactory.createQueueConnection();
    } catch (JMSException e) {
        log.error(e.getMessage());
        releaseMQ();
        return false;
    }

    try {
        session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    } catch (JMSException e) {
        log.error(e.getMessage());
        releaseMQ();
        return false;
    }

    String queueName = System.getProperty(PACKETOUT_QUEUE_PROPERTY, DEFAULT_PACKETOUT_QUEUE_NAME);
    log.info("Using the following queue for packet forwarding requests: " + queueName);
    try {
        packetOutQueue = (Queue) ctx.lookup(queueName);
    } catch (NamingException e) {
        log.error(e.getMessage());
        releaseMQ();
        return false;
    }

    try {
        receiver = session.createReceiver(packetOutQueue);
    } catch (JMSException e) {
        log.error(e.getMessage());
        releaseMQ();
        return false;
    }

    return true;
}

From source file:velo.ejb.seam.action.HomeActionsBean.java

public void test() {
    //System.out.println("!!!!!!!!!!!" + dispatcher);
    //System.out.println("!!!!!!!!!!!" + dispatcher.getScheduler().getClass().getName());

    try {/*  w w w . j a v  a 2 s .co m*/
        InitialContext ic = new InitialContext();
        org.quartz.impl.StdScheduler sched = (org.quartz.impl.StdScheduler) ic.lookup("Quartz");
        System.out.println("!!!!!!!!!!!!!!!!!!NUUUUU: " + sched);
    } catch (NamingException e) {
        System.out.println("WAAAAAAAAAAAA: " + e.getMessage());
    }
}

From source file:com.vangent.hieos.authutil.ldap.LDAPAuthenticationHandler.java

/**
 *
 * @param creds//from   w  w w.java  2  s  .  c o  m
 * @return
 * @throws AuthUtilException
 */
@Override
public AuthenticationContext authenticate(Credentials creds) throws AuthUtilException {
    AuthenticationContext authnCtx = new AuthenticationContext();
    this.configure(creds.getAuthDomainTypeKey());

    LDAPClient ldapClient = null;
    try {

        ldapClient = new LDAPClient(this.ldapURL);

    } catch (NamingException e) {
        log.error("Error accessing LDAP.", e);
        throw new AuthUtilException("Error accessing LDAP." + e.getMessage());
    }

    try {

        boolean status = false;
        String username = "";
        if (creds != null) {
            username = creds.getUserId();
            if (StringUtils.isNotBlank(this.userNameFormat)) {
                username = StringUtils.replace(this.userNameFormat, USERNAME_REPLACE_STRING, username);
            }

            // authenticate
            status = ldapClient.bind(username, creds.getPassword());
        }
        if (status == true) {
            authnCtx.setStatus(AuthenticationContext.Status.SUCCESS);
            if (log.isInfoEnabled()) {
                log.info("LDAPAuthenticationHandler - User, " + username + ", authenticated.");
            }
            // get attributes from LDAP
            authnCtx.setUserProfile(getUserProfile(ldapClient, creds));
        } else {
            authnCtx.setStatus(AuthenticationContext.Status.FAILURE);
            if (log.isInfoEnabled()) {
                log.info("LDAPAuthenticationHandler - User, " + username + ", could not be authenticated.");
            }
        }
    } finally {

        // disconnect, release resources!!!!
        if (ldapClient != null) {
            ldapClient.unbind();
        }
    }

    return authnCtx;
}

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

@Override
public Configuration loadResourceConfiguration() {

    VDBComponent parentComponent = (VDBComponent) this.resourceContext.getParentResourceComponent();
    ManagedComponent mcVdb = null;/*  w ww. jav a  2s. co  m*/
    Configuration configuration = resourceContext.getPluginConfiguration();
    try {
        mcVdb = ProfileServiceUtil.getManagedComponent(getConnection(),
                new ComponentType(PluginConstants.ComponentType.VDB.TYPE,
                        PluginConstants.ComponentType.VDB.SUBTYPE),
                parentComponent.name);
    } catch (NamingException e) {
        final String msg = "NamingException in loadResourceConfiguration(): " + e.getMessage(); //$NON-NLS-1$
        LOG.error(msg, e);
    } catch (Exception e) {
        final String msg = "Exception in loadResourceConfiguration(): " + e.getMessage(); //$NON-NLS-1$
        LOG.error(msg, e);
    }

    // Get data roles from VDB
    ManagedProperty property = mcVdb.getProperty("dataPolicies"); //$NON-NLS-1$
    if (property != null) {
        CollectionValueSupport valueSupport = (CollectionValueSupport) property.getValue();
        MetaValue[] metaValues = valueSupport.getElements();

        for (MetaValue value : metaValues) {
            GenericValueSupport genValueSupport = (GenericValueSupport) value;
            ManagedObjectImpl managedObject = (ManagedObjectImpl) genValueSupport.getValue();

            String dataRoleName = ProfileServiceUtil.getSimpleValue(managedObject, "name", String.class); //$NON-NLS-1$
            Boolean anyAuthenticated = ProfileServiceUtil.getSimpleValue(managedObject, "anyAuthenticated", //$NON-NLS-1$
                    Boolean.class);
            String description = ProfileServiceUtil.getSimpleValue(managedObject, "description", String.class); //$NON-NLS-1$

            configuration.put(new PropertySimple("name", dataRoleName)); //$NON-NLS-1$
            configuration.put(new PropertySimple("anyAuthenticated", //$NON-NLS-1$ 
                    anyAuthenticated));
            configuration.put(new PropertySimple("description", description)); //$NON-NLS-1$

            PropertyList mappedRoleNameList = new PropertyList("mappedRoleNameList"); //$NON-NLS-1$
            configuration.put(mappedRoleNameList);
            ManagedProperty mappedRoleNames = managedObject.getProperty("mappedRoleNames"); //$NON-NLS-1$
            if (mappedRoleNames != null) {
                CollectionValueSupport props = (CollectionValueSupport) mappedRoleNames.getValue();
                for (MetaValue mappedRoleName : props.getElements()) {
                    PropertyMap mappedRoleNameMap = null;

                    try {
                        mappedRoleNameMap = new PropertyMap("map", //$NON-NLS-1$
                                new PropertySimple("name", (ProfileServiceUtil.stringValue(mappedRoleName)))); //$NON-NLS-1$
                    } catch (Exception e) {
                        final String msg = "Exception in loadResourceConfiguration(): " + e.getMessage(); //$NON-NLS-1$
                        LOG.error(msg, e);
                    }
                    mappedRoleNameList.add(mappedRoleNameMap);
                }
            }
        }
    }

    return configuration;

}