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.sdnmq.jms.PacketHandler.java

/**
 * Initialization of JMS.//from  w w w .j  a  v a  2 s .c  om
 */
private void initMQ() {
    log.trace("Setting up JMS ...");

    Properties jndiProps = JNDIHelper.getJNDIProperties();

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

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

    try {
        connection = topicFactory.createTopicConnection();
    } catch (JMSException e) {
        log.error("Could not create JMS connection: " + e.getMessage());
        releaseMQ();
        return;
    }

    try {
        session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    } catch (JMSException e) {
        log.error("Could not create JMS session: " + e.getMessage());
        releaseMQ();
        return;
    }

    // Get the JNDI object name of the packet-in topic object from the OpenDaylight configuration.
    String topicName = System.getProperty(PACKETIN_TOPIC_PROPERTY, DEFAULT_PACKETIN_TOPIC_NAME);
    log.info("Using the following topic for packet-in events: " + topicName);
    try {
        packetinTopic = (Topic) ctx.lookup(topicName);
    } catch (NamingException e) {
        log.error("Could not resolve topic object: " + e.getMessage());
        releaseMQ();
        return;
    }

    try {
        publisher = session.createPublisher(packetinTopic);
    } catch (JMSException e) {
        log.error(e.getMessage());
        releaseMQ();
        return;
    }

    log.trace("JMS setup finished successfully");
}

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

/**
 * // w  w w.j  av  a  2s .c  o  m
 * @param attributes1
 * @return subject
 */
private Subject createSubject(Attributes attributes1) {
    String name1 = "";
    String subjectID = "";
    String description = "";
    try {
        Attribute attribute = attributes1.get(this.subjectIDAttributeName);
        if (attribute == null) {
            log.error("The LDAP attribute \"" + this.subjectIDAttributeName
                    + "\" does not have a value. It is beging used as the Grouper special attribute \"SubjectID\".");
            return null;
        }
        subjectID = (String) attribute.get();
        attribute = attributes1.get(this.nameAttributeName);
        if (attribute == null) {
            log.error("The LDAP attribute \"" + this.nameAttributeName
                    + "\" does not have a value. It is being used as the Grouper special attribute \"name\".");
            return null;
        }
        name1 = (String) attribute.get();
        attribute = attributes1.get(this.descriptionAttributeName);
        if (attribute == null) {
            log.error("The LDAP attribute \"" + this.descriptionAttributeName
                    + "\" does not have a value. It is being used as the Grouper special attribute \"description\".");
        } else {
            description = (String) attribute.get();
        }
    } catch (NamingException ex) {
        log.error("LDAP Naming Except: " + ex.getMessage(), ex);
    }

    return new JNDISubject(subjectID, name1, description, this.getSubjectType().getName(), this.getId(), null);
}

From source file:org.wso2.carbon.datasource.core.DataSourceRepository.java

private void registerJNDI(DataSourceMetaInfo dsmInfo, Object dsObject) throws DataSourceException {
    try {//from   w ww. j  av  a  2  s.  com
        /*PrivilegedCarbonContext.startTenantFlow();
           PrivilegedCarbonContext.getCurrentContext().setTenantId(this.getTenantId());*/
        JNDIConfig jndiConfig = dsmInfo.getJndiConfig();
        if (jndiConfig == null) {
            return;
        }
        InitialContext context;
        try {
            context = new InitialContext(jndiConfig.extractHashtableEnv());
        } catch (NamingException e) {
            throw new DataSourceException("Error creating JNDI initial context: " + e.getMessage(), e);
        }
        this.checkAndCreateJNDISubContexts(context, jndiConfig.getName());

        try {
            context.rebind(jndiConfig.getName(), dsObject);
        } catch (NamingException e) {
            throw new DataSourceException(
                    "Error in binding to JNDI with name '" + jndiConfig.getName() + "' - " + e.getMessage(), e);
        }
    } finally {
        /*PrivilegedCarbonContext.endTenantFlow();*/
    }
}

From source file:org.wso2.carbon.datasource.core.DataSourceRepository.java

private void unregisterJNDI(DataSourceMetaInfo dsmInfo) {
    try {//from  ww  w. ja v a 2 s.  c  o m
        /*PrivilegedCarbonContext.startTenantFlow();
           PrivilegedCarbonContext.getCurrentContext().setTenantId(this.getTenantId());*/
        JNDIConfig jndiConfig = dsmInfo.getJndiConfig();
        if (jndiConfig == null) {
            return;
        }
        try {
            InitialContext context = new InitialContext(jndiConfig.extractHashtableEnv());
            context.unbind(jndiConfig.getName());
        } catch (NamingException e) {
            log.error("Error in unregistering JNDI name: " + jndiConfig.getName() + " - " + e.getMessage(), e);
        }
    } finally {
        /*PrivilegedCarbonContext.endTenantFlow();*/
    }
}

From source file:com.evolveum.midpoint.pwdfilter.opendj.PasswordPusher.java

private void readConfig() throws InitializationException {

    String configFile = "/opt/midpoint/opendj-pwdpusher.xml";
    if (System.getProperty("config") != null) {
        configFile = System.getProperty("config");
    }//from w ww  .  ja v  a 2s.c  o m

    File f = new File(configFile);
    if (!f.exists() || !f.canRead()) {
        throw new IllegalArgumentException("Config file " + configFile + " does not exist or is not readable");
    }

    try {
        XMLConfiguration config = new XMLConfiguration(f);

        String notifierDN = "cn=" + config.getString("passwordpusher.statusNotifierName")
                + ",cn=Account Status Notification Handlers";
        String ldapURL = config.getString("passwordpusher.ldapServerURL");
        boolean ldapSSL = config.getBoolean("passwordpusher.ldapServerSSL");
        String ldapUsername = config.getString("passwordpusher.ldapServerUsername");
        String ldapPassword = config.getString("passwordpusher.ldapServerPassword");

        Hashtable<Object, Object> env = new Hashtable<Object, Object>();
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, ldapURL + "/cn=config");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, ldapUsername);
        env.put(Context.SECURITY_CREDENTIALS, ldapPassword);

        if (ldapSSL) {
            env.put(Context.SECURITY_PROTOCOL, "ssl");
        }

        try {
            DirContext context = new InitialDirContext(env);
            Attributes attr = context.getAttributes(notifierDN);

            this.endPoint = attr.get("ds-cfg-referrals-url").get(0).toString();
            this.username = attr.get("ds-cfg-midpoint-username").get(0).toString();
            this.password = attr.get("ds-cfg-midpoint-password").get(0).toString();
            this.pwdChangeDirectory = attr.get("ds-cfg-midpoint-passwordcachedir").get(0).toString();
        } catch (NamingException ne) {
            throw new InitializationException(
                    ERR_MIDPOINT_PWDSYNC_READING_CONFIG_FROM_LDAP.get(ne.getMessage()), ne);
        }
    } catch (ConfigurationException ce) {
        throw new InitializationException(ERR_MIDPOINT_PWDSYNC_PARSING_XML_CONFIG.get(ce.getMessage()), ce);
    }
}

From source file:iplatform.admin.ui.server.auth.ad.ActiveDirectoryLdapAuthenticationProvider.java

void raiseExceptionForErrorCode(int code, NamingException exception) {
    //String hexString = Integer.toHexString(code);
    //Throwable cause = new ActiveDirectoryAuthenticationException(hexString, exception.getMessage(), exception);
    Throwable cause = new Exception(exception.getMessage());
    switch (code) {
    case PASSWORD_EXPIRED:
        throw new CredentialsExpiredException(messages.getMessage(
                "LdapAuthenticationProvider.credentialsExpired", "User credentials have expired"), cause);
    case ACCOUNT_DISABLED:
        throw new DisabledException(
                messages.getMessage("LdapAuthenticationProvider.disabled", "User is disabled"), cause);
    case ACCOUNT_EXPIRED:
        throw new AccountExpiredException(
                messages.getMessage("LdapAuthenticationProvider.expired", "User account has expired"), cause);
    case ACCOUNT_LOCKED:
        throw new LockedException(
                messages.getMessage("LdapAuthenticationProvider.locked", "User account is locked"), cause);
    default://  www.jav a2s .  c om
        throw badCredentials(cause);
    }
}

From source file:it.openutils.mgnlaws.magnolia.init.ClasspathProviderImpl.java

/**
 * @see info.magnolia.repository.Provider#init(info.magnolia.repository.RepositoryMapping)
 *//*from www  . j av  a 2s.c  o  m*/
public void init(RepositoryMapping repositoryMapping) throws RepositoryNotInitializedException {
    checkXmlSettings();

    this.repositoryMapping = repositoryMapping;
    /* connect to repository */
    Map params = this.repositoryMapping.getParameters();
    String configFile = (String) params.get(CONFIG_FILENAME_KEY);
    if (!StringUtils.startsWith(configFile, ClasspathPropertiesInitializer.CLASSPATH_PREFIX)) {
        configFile = Path.getAbsoluteFileSystemPath(configFile);
    }
    String repositoryHome = (String) params.get(REPOSITORY_HOME_KEY);
    repositoryHome = getRepositoryHome(repositoryHome);

    // cleanup the path, to remove eventual ../.. and make it absolute
    try {
        File repoHomeFile = new File(repositoryHome);
        repositoryHome = repoHomeFile.getCanonicalPath();
    } catch (IOException e1) {
        // should never happen and it's not a problem at this point, just pass it to jackrabbit and see
    }

    String clusterid = SystemProperty.getProperty(MAGNOLIA_CLUSTERID_PROPERTY);
    if (StringUtils.isNotBlank(clusterid)) {
        System.setProperty(JACKRABBIT_CLUSTER_ID_PROPERTY, clusterid);
    }

    // get it back from system properties, if it has been set elsewhere
    clusterid = System.getProperty(JACKRABBIT_CLUSTER_ID_PROPERTY);

    log.info("Loading repository at {} (config file: {}) - cluster id: \"{}\"",
            new Object[] { repositoryHome, configFile, StringUtils.defaultString(clusterid, "<unset>") });

    bindName = (String) params.get(BIND_NAME_KEY);
    jndiEnv = new Hashtable<String, Object>();
    jndiEnv.put(Context.INITIAL_CONTEXT_FACTORY, params.get(CONTEXT_FACTORY_CLASS_KEY));
    jndiEnv.put(Context.PROVIDER_URL, params.get(PROVIDER_URL_KEY));

    try {
        InitialContext ctx = new InitialContext(jndiEnv);
        // first try to find the existing object if any
        try {
            this.repository = (Repository) ctx.lookup(bindName);
        } catch (NameNotFoundException ne) {
            log.debug("No JNDI bound Repository found with name {}, trying to initialize a new Repository",
                    bindName);
            ClasspathRegistryHelper.registerRepository(ctx, bindName, configFile, repositoryHome, true);
            this.repository = (Repository) ctx.lookup(bindName);
        }
        this.validateWorkspaces();
    } catch (NamingException e) {
        log.error("Unable to initialize repository: " + e.getMessage(), e);
        throw new RepositoryNotInitializedException(e);
    } catch (RepositoryException e) {
        log.error("Unable to initialize repository: " + e.getMessage(), e);
        throw new RepositoryNotInitializedException(e);
    } catch (TransformerFactoryConfigurationError e) {
        log.error("Unable to initialize repository: " + e.getMessage(), e);
        throw new RepositoryNotInitializedException(e);
    }
}

From source file:velo.jbpm.MailHandler.java

public void send() {
    boolean isApproversGroup = false;
    String resultedActor;//from w  w w  .jav a2 s  .com

    try {
        log.debug("MailNode of a business process has just invoked.");

        log.debug("Sending email to the specified template: " + template);

        if (actors == null) {
            log.error("Actors was set to null, aboring sending mail process.");
            return;
        } else {
            log.debug("The specified actors is: " + actors);
        }

        //HANDLE APPROVERS GROUP SUROUNDED WITH []
        if ((actors.startsWith("[")) && (actors.endsWith("]"))) {
            log.debug(
                    "Found a string surounded with '[]' meaning the actor is an approvers group, determining whether it is an expression or not.");
            String agStr = actors.substring(1, actors.length() - 1);
            isApproversGroup = true;
            if (isExpression(agStr)) {
                log.debug("ApproversGroup is an expression, evaluating expression now.");
                String result = evaluate(agStr);
                log.debug("Expression result is: '" + result + "' (overriding actors with the result)");

                /////actors = result;
                resultedActor = result;
            } else {
                log.debug("Approvers group is not expression and would be: '" + agStr + "'");
                /////actors = agStr;
                resultedActor = agStr;
            }
            //INDIVIDUAL
        } else {

            //if an expression of an individual user
            if ((actors.startsWith("#{")) && (actors.endsWith("}"))) {
                log.debug("The specified actor is an expression (single user), evaluating expression now...");
                String result = evaluate(actors);

                log.debug("Expression evaluation result is '" + result + "', overriding 'actors' with result.");
                //////actors = result;
                resultedActor = result;

                //not an expression but single user
            } else {
                log.debug(
                        "The specified actor is NOT an expression(and is not an approvers group), evaluating as a context var...");
                String result = (String) executionContext.getVariable(actors);
                log.debug("Context var result for actors '" + actors + "' is: '" + result
                        + "', overriding 'actors' with result.");
                //get the real value as the specified value is the var name
                //////actors = result;
                resultedActor = result;
            }
        }

        Context initialContext = new InitialContext();
        EmailManagerLocal emailManager = (EmailManagerLocal) initialContext.lookup("velo/EmailBean/local");
        EmailTemplate et = emailManager.findEmailTemplate(template);

        if (et == null) {
            log.error("Could not send mail, could not find email template named: '" + template
                    + "' in repository!");
            return;
        }

        /*
        //copied from executionContext.getVariable code:)
        if (executionContext.getTaskInstance()!=null) {
           et.addContentVar("processVars", executionContext.getTaskInstance().getVariableInstances());
        } else {
           et.addContentVar("processVars", executionContext.getContextInstance().getVariables());
        }
        */

        //adding process vars map to the template
        et.addContentVar("processVars", executionContext.getContextInstance().getVariables());
        //add the process to the context
        et.addContentVar("process", executionContext.getProcessInstance());

        JbpmCommentsUtils jbpmCommentsUtils = new JbpmCommentsUtils();

        et.addContentVar("processCommentsHtml",
                jbpmCommentsUtils.getProcessCommentsAsHtml(executionContext.getProcessInstance()));
        //the current node
        et.addContentVar("node", executionContext.getNode());
        et.addContentVar("currentTime", new Date());

        /*
        Transition t = executionContext.getNode().getDefaultLeavingTransition();
        Node nextNode = t.getTo();
        System.out.println("!!!!!!!!!!!!!!!!!" + nextNode);
                
        if (nextNode != null) {
           System.out.println("!!!!!!!!!!!!!!!!!" + nextNode.getName());
           System.out.println("!!!!!!!!!!!!!!!!!" + nextNode.getDescription());
        }
                
        TaskNode taskNode = (TaskNode)nextNode;
                
        Task ta = (Task)taskNode.getTasksMap().get("bla");
        ta.getDescription();
        */

        EdmEmailSender sender = new EdmEmailSender();

        /*currently 'TO' is not supported
        if (to != null) {
           addEmailAddress(to);
        }
        */

        //if AG, then handle it, otherwise handle an individual approver
        if (isApproversGroup) {
            ApproversGroupManagerLocal approversGroupManager = (ApproversGroupManagerLocal) initialContext
                    .lookup("velo/ApproversGroupBean/local");
            //Not sure why, even though it's a local interface the session get closed and a lazy loading exception occurs
            //thus, loading entity eagerly.
            ApproversGroup ag = approversGroupManager.findApproversGroupEagerly(resultedActor);

            //make sure AG entity was found and there are associated approvers, otherwise abort.
            if (ag == null) {
                log.error("Could not find any approvers group for unique name: '" + resultedActor
                        + "', skipping sending mail process");
                return;
            } else {
                if (ag.getApprovers().size() > 0) {
                    log.debug("Found ApproversGroup with uniqueName '" + ag.getUniqueName()
                            + "', with associated approvers number '" + ag.getApprovers().size() + "'");
                } else {
                    log.info("Found ApproversGroup with uniqueName '" + ag.getUniqueName()
                            + "', but with 0 associated approvers, skipping sending mail process...");
                    return;
                }
            }

            for (User currApprover : ag.getApprovers()) {
                String email = currApprover.getEmail();
                //make sure email is not null
                if (email == null) {
                    log.info("User '" + currApprover.getName()
                            + "' has no email address, skipping sending mail to user.");
                    continue;
                }

                if (Generic.isEmailValid(email)) {
                    log.trace("Current iterated Approver with username '" + currApprover.getName()
                            + "', has a valid email address and will recieve an email to address:  '" + email
                            + "'");
                    addEmailAddress(email);
                } else {
                    log.warn("Current iterated Approver with username '" + currApprover.getName()
                            + "', has an INVALID email address, skipping sending mail to this approver.");
                }
            }
            //handle an individual   
        } else {
            log.debug("Recipient is an individual, loading approver(user) entity from repository with name: '"
                    + resultedActor + "'");
            UserManagerLocal userManager = (UserManagerLocal) initialContext.lookup("velo/UserBean/local");

            User user = userManager.findUser(resultedActor);

            if (user == null) {
                log.warn("Could not find actor(user) in repository for name: " + resultedActor
                        + ", aboring mail.");
                return;
            } else {
                String emailAddr = user.getEmail();
                if (emailAddr != null) {
                    if (Generic.isEmailValid(emailAddr)) {
                        addEmailAddress(emailAddr);
                    } else {
                        log.warn("User '" + resultedActor
                                + "' was found in repository but has an INVALID email address: '" + emailAddr
                                + "'");
                    }
                } else {
                    log.warn("Could not find email address of user: " + user.getName());
                }
            }
        }

        if (addresses != null) {
            log.debug("Sending mail to addresses: " + addresses + ", subject: " + et.getSubject());
            sender.addHtmlEmail(addresses, et.getSubject(), et.getParsedContent());
            log.debug("Sending...");
            sender.send();
            log.debug("Successfully sent email...!");
        } else {
            log.warn("Skipping sending email since no email address was resulted(from to/actors)");
            return;
        }

    } catch (NamingException e) {
        log.error("Naming Exception error due to " + e.getMessage());
    } catch (EmailException e) {
        log.error("Error sending email due to: " + e.getMessage());
    } catch (ExpressionCreationException e) {
        log.error("Error sending email due to: " + e.getMessage());
    }

}

From source file:org.wso2.carbon.user.core.ldap.LDAPConnectionContext.java

public LdapContext getContextWithCredentials(String userDN, String password)
        throws UserStoreException, NamingException, AuthenticationException {
    LdapContext context = null;//from  www  .j a  v  a  2s  .c  om

    //create a temp env for this particular authentication session by copying the original env
    Hashtable<String, String> tempEnv = new Hashtable<String, String>();
    for (Object key : environment.keySet()) {
        tempEnv.put((String) key, (String) environment.get(key));
    }
    //replace connection name and password with the passed credentials to this method
    tempEnv.put(Context.SECURITY_PRINCIPAL, userDN);
    tempEnv.put(Context.SECURITY_CREDENTIALS, password);

    //if dcMap is not populated, it is not DNS case
    if (dcMap == null) {

        //replace environment properties with these credentials
        context = new InitialLdapContext(tempEnv, null);

    } else if (dcMap != null && dcMap.size() != 0) {
        try {
            //first try the first entry in dcMap, if it fails, try iteratively
            Integer firstKey = dcMap.firstKey();
            SRVRecord firstRecord = dcMap.get(firstKey);
            //compose the connection URL
            tempEnv.put(Context.PROVIDER_URL, getLDAPURLFromSRVRecord(firstRecord));
            context = new InitialLdapContext(tempEnv, null);

        } catch (AuthenticationException e) {
            throw e;

        } catch (NamingException e) {
            log.error("Error obtaining connection to first Domain Controller." + e.getMessage(), e);
            log.info("Trying to connect with other Domain Controllers");

            for (Integer integer : dcMap.keySet()) {
                try {
                    SRVRecord srv = dcMap.get(integer);
                    environment.put(Context.PROVIDER_URL, getLDAPURLFromSRVRecord(srv));
                    context = new InitialLdapContext(environment, null);
                    break;
                } catch (AuthenticationException e2) {
                    throw e2;
                } catch (NamingException e1) {
                    if (integer == (dcMap.lastKey())) {
                        log.error("Error obtaining connection for all " + integer + " Domain Controllers."
                                + e1.getMessage(), e1);
                        throw new UserStoreException("Error obtaining connection. " + e1.getMessage(), e1);
                    }
                }
            }
        }
    }
    return (context);
}

From source file:org.wso2.carbon.ndatasource.core.DataSourceRepository.java

private void registerJNDI(DataSourceMetaInfo dsmInfo, Object dsObject) throws DataSourceException {
    try {//  w  w  w  .  j  av  a  2  s  .  c o m
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(this.getTenantId());
        JNDIConfig jndiConfig = dsmInfo.getJndiConfig();
        if (jndiConfig == null) {
            return;
        }
        InitialContext context;
        try {
            context = new InitialContext(jndiConfig.extractHashtableEnv());
        } catch (NamingException e) {
            throw new DataSourceException("Error creating JNDI initial context: " + e.getMessage(), e);
        }
        this.checkAndCreateJNDISubContexts(context, jndiConfig.getName());

        try {
            context.rebind(jndiConfig.getName(), dsObject);
        } catch (NamingException e) {
            throw new DataSourceException(
                    "Error in binding to JNDI with name '" + jndiConfig.getName() + "' - " + e.getMessage(), e);
        }
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}