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.openkm.principal.LdapPrincipalAdapter.java

@SuppressWarnings("unchecked")
private List<String> ldapSearch(List<String> searchBases, String searchFilter, String attribute) {
    log.debug("ldapSearch({}, {}, {})", new Object[] { searchBases, searchFilter, attribute });
    List<String> al = new ArrayList<String>();
    DirContext ctx = null;//from   w  w  w  . ja v a  2s .co m
    Hashtable<String, String> env = getEnvironment();

    try {
        ctx = new InitialDirContext(env);
        SearchControls searchCtls = new SearchControls();
        searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);

        for (String searchBase : searchBases) {
            NamingEnumeration<SearchResult> results = ctx.search(searchBase, searchFilter, searchCtls);

            while (results.hasMore()) {
                SearchResult searchResult = (SearchResult) results.next();
                Attributes attributes = searchResult.getAttributes();

                if (attribute.equals("")) {
                    StringBuilder sb = new StringBuilder();

                    for (NamingEnumeration<?> ne = attributes.getAll(); ne.hasMore();) {
                        Attribute attr = (Attribute) ne.nextElement();
                        sb.append(attr.toString());
                        sb.append("\n");
                    }

                    al.add(sb.toString());
                } else {
                    Attribute attrib = attributes.get(attribute);

                    if (attrib != null) {
                        // Handle multi-value attributes
                        for (NamingEnumeration<?> ne = attrib.getAll(); ne.hasMore();) {
                            String value = (String) ne.nextElement();

                            // If FQDN get only main part
                            if (value.startsWith("CN=") || value.startsWith("cn=")) {
                                String cn = value.substring(3, value.indexOf(','));
                                log.debug("FQDN: {}, CN: {}", value, cn);
                                al.add(cn);
                            } else {
                                al.add(value);
                            }
                        }
                    }
                }
            }
        }
    } catch (ReferralException e) {
        log.error("ReferralException: {}", e.getMessage());
        log.error("ReferralInfo: {}", e.getReferralInfo());
        log.error("ResolvedObj: {}", e.getResolvedObj());

        try {
            log.error("ReferralContext: {}", e.getReferralContext());
        } catch (NamingException e1) {
            log.error("NamingException logging context: {}", e1.getMessage());
        }
    } catch (NamingException e) {
        log.error("NamingException: {} (Base: {} - Filter: {} - Attribute: {})",
                new Object[] { e.getMessage(), searchBases, searchFilter, attribute });
    } finally {
        try {
            if (ctx != null) {
                ctx.close();
            }
        } catch (NamingException e) {
            log.error("NamingException closing context: {}", e.getMessage());
        }
    }

    log.debug("ldapSearch: {}", al);
    return al;
}

From source file:org.apache.archiva.redback.users.ldap.ctl.DefaultLdapController.java

public Map<String, Collection<String>> findUsersWithRoles(DirContext dirContext)
        throws LdapControllerException {
    Map<String, Collection<String>> usersWithRoles = new HashMap<String, Collection<String>>();

    NamingEnumeration<SearchResult> namingEnumeration = null;
    try {/*from w w  w.  ja  va  2s . c om*/

        SearchControls searchControls = new SearchControls();

        searchControls.setDerefLinkFlag(true);
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);

        String filter = "objectClass=" + getLdapGroupClass();

        namingEnumeration = dirContext.search(getGroupsDn(), filter, searchControls);

        while (namingEnumeration.hasMore()) {
            SearchResult searchResult = namingEnumeration.next();

            String groupName = searchResult.getName();
            // cn=blabla we only want bla bla
            groupName = StringUtils.substringAfter(groupName, "=");

            Attribute uniqueMemberAttr = searchResult.getAttributes().get("uniquemember");

            if (uniqueMemberAttr != null) {
                NamingEnumeration<String> allMembersEnum = (NamingEnumeration<String>) uniqueMemberAttr
                        .getAll();
                while (allMembersEnum.hasMore()) {
                    String userName = allMembersEnum.next();
                    // uid=blabla we only want bla bla
                    userName = StringUtils.substringAfter(userName, "=");
                    userName = StringUtils.substringBefore(userName, ",");
                    Collection<String> roles = usersWithRoles.get(userName);
                    if (roles == null) {
                        roles = new HashSet<String>();
                    }

                    roles.add(groupName);

                    usersWithRoles.put(userName, roles);

                }
            }

            log.debug("found groupName: '{}' with users: {}", groupName);

        }

        return usersWithRoles;
    } catch (NamingException e) {
        throw new LdapControllerException(e.getMessage(), e);
    }

    finally {

        if (namingEnumeration != null) {
            try {
                namingEnumeration.close();
            } catch (NamingException e) {
                log.warn("failed to close search results", e);
            }
        }
    }
}

From source file:org.wso2.carbon.appfactory.eventing.jms.Subscriber.java

public void subscribe() throws AppFactoryEventException {

    Properties properties = new Properties();
    properties.put(Context.INITIAL_CONTEXT_FACTORY, ANDES_ICF);
    properties.put(CF_NAME_PREFIX + CF_NAME, Util.getTCPConnectionURL());
    properties.put(CarbonConstants.REQUEST_BASE_CONTEXT, "true");
    properties.put("topic", topicName);

    try {/* w w w .jav a 2 s.c o  m*/
        ctx = new InitialContext(properties);
        // Lookup connection factory
        connFactory = (TopicConnectionFactory) ctx.lookup(CF_NAME);
        topicConnection = connFactory.createTopicConnection();
        TopicSession topicSession = topicConnection.createTopicSession(false, TopicSession.CLIENT_ACKNOWLEDGE);
        // create durable subscriber with subscription ID
        Topic topic = null;
        try {
            topic = (Topic) ctx.lookup(topicName);
        } catch (NamingException e) {
            topic = topicSession.createTopic(topicName);
        }
        TopicSubscriber topicSubscriber = topicSession.createDurableSubscriber(topic, subscriptionId);
        topicSubscriber.setMessageListener(messageListener);
        topicConnection.start();
    } catch (NamingException e) {
        String errorMsg = "Failed to subscribe to topic:" + topicName + " due to " + e.getMessage();
        throw new AppFactoryEventException(errorMsg, e);
    } catch (JMSException e) {
        String errorMsg = "Failed to subscribe to topic:" + topicName + " due to " + e.getMessage();
        throw new AppFactoryEventException(errorMsg, e);
    }

}

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

void handleBindException(String bindPrincipal, NamingException exception) {
    if (logger.isDebugEnabled()) {
        logger.debug("Authentication for " + bindPrincipal + " failed:" + exception);
    }//w ww.  j  av  a  2 s.  c o  m

    int subErrorCode = parseSubErrorCode(exception.getMessage());

    if (subErrorCode > 0) {
        logger.info("Active Directory authentication failed: " + subCodeToLogMessage(subErrorCode));

        if (convertSubErrorCodesToExceptions) {
            raiseExceptionForErrorCode(subErrorCode, exception);
        }
    } else {
        logger.debug("Failed to locate AD-specific sub-error code in message");
    }
}

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

public void shutdownRepository() {
    log.info("Shutting down repository bound to '{}'", bindName);

    try {/* ww  w . j  av  a 2s .  c om*/
        Context ctx = new InitialContext(jndiEnv);
        RegistryHelper.unregisterRepository(ctx, bindName);
    } catch (NamingException e) {
        log.warn("Unable to shutdown repository " + bindName + ": " + e.getMessage(), e);
    } catch (Throwable e) {
        log.error("Failed to shutdown repository " + bindName + ": " + e.getMessage(), e);
    }
}

From source file:org.easy.ldap.AdminServiceImpl.java

@Override
public List<LdapUser> findAllUsers(String tenantId, LdapUser example) {

    NamingEnumeration<SearchResult> result = null;
    List<LdapUser> out = new ArrayList<LdapUser>();

    LdapName rootDn = namingFactory.createUsersDn(tenantId);
    result = ldapDao.findAll(rootDn, LdapDao.toAttributes(example));

    try {//from  w  w w.java2s.c  o m
        while (result.hasMore()) {
            out.add(LdapDao.toModel(tenantId, result.next().getAttributes()));
        }
    } catch (NamingException e) {
        log.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }

    return out;
}

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

protected DirContext createContext() throws DirectoryException {
    try {/*ww w .ja v  a 2 s . c o  m*/
        /*
         * Dynamic server list requires re-computation on each access
         */
        String serverName = getDescriptor().getServerName();
        if (StringUtils.isEmpty(serverName)) {
            throw new DirectoryException("server configuration is missing for directory " + getName());
        }
        LDAPServerDescriptor serverConfig = getServer();
        if (serverConfig.isDynamicServerList()) {
            String ldapUrls = serverConfig.getLdapUrls();
            contextProperties.put(Context.PROVIDER_URL, ldapUrls);
        }
        return new InitialDirContext(contextProperties);
    } catch (NamingException e) {
        throw new DirectoryException("Cannot connect to LDAP directory '" + getName() + "': " + e.getMessage(),
                e);
    }
}

From source file:de.micromata.genome.util.runtime.LocalSettingsEnv.java

/**
 * Creates the sub context dirs.//from w  w w .j  a v a 2s  .  c  o m
 *
 * @param path the path
 */
protected void createSubContextDirs(String path) {
    int idx = path.lastIndexOf('/');
    if (idx == -1) {
        throw new RuntimeException("Cannot create JNDI Path, because no subcontext: " + path);
    }
    String spath = path.substring(0, idx);
    try {
        initialContext.createSubcontext(spath);
    } catch (NameNotFoundException ex) {
        createSubContextDirs(spath);
        try {
            initialContext.createSubcontext(spath);
        } catch (NamingException ex2) {
            throw new RuntimeException("Cannot create Subcontext: " + spath + "; " + ex2.getMessage(), ex2);
        }
    } catch (NamingException ex) {
        throw new RuntimeException("Cannot create subcontext: " + spath + "; " + ex.getMessage(), ex);
    }
}

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

/**
 * //  ww w.  j  ava  2  s.  c o m
 * @param search
 * @param searchValue
 * @param attributeNames
 * @return attributes
 * @throws SubjectNotFoundException
 * @throws SubjectNotUniqueException
 */
protected Attributes getLdapUnique(Search search, String searchValue, String[] attributeNames)
        throws SubjectNotFoundException, SubjectNotUniqueException {
    Attributes attributes1 = null;
    NamingEnumeration results = getLdapResults(search, searchValue, attributeNames);

    try {
        if (results == null || !results.hasMore()) {
            String errMsg = "No results: " + search.getSearchType() + " filter:" + search.getParam("filter")
                    + " searchValue: " + searchValue;
            throw new SubjectNotFoundException(errMsg);
        }

        SearchResult si = (SearchResult) results.next();
        attributes1 = si.getAttributes();
        if (results.hasMore()) {
            si = (SearchResult) results.next();
            String errMsg = "Search is not unique:" + si.getName() + "\n";
            throw new SubjectNotUniqueException(errMsg);
        }
    } catch (NamingException ex) {
        log.error("Ldap NamingException: " + ex.getMessage(), ex);
    }
    return attributes1;
}

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

/**
 * /*from   ww  w . j  av a  2  s  .c om*/
 * @see edu.internet2.middleware.subject.provider.BaseSourceAdapter#search(java.lang.String)
 */
@Override
public Set<Subject> search(String searchValue) {
    Set<Subject> result = new HashSet<Subject>();
    Search search = getSearch("search");
    if (search == null) {
        log.error("searchType: \"search\" not defined.");
        return result;
    }
    String[] attributeNames = { this.nameAttributeName, this.subjectIDAttributeName,
            this.descriptionAttributeName };
    NamingEnumeration ldapResults = getLdapResults(search, searchValue, attributeNames);
    if (ldapResults == null) {
        return result;
    }
    try {
        while (ldapResults.hasMore()) {
            SearchResult si = (SearchResult) ldapResults.next();
            Attributes attributes1 = si.getAttributes();
            Subject subject = createSubject(attributes1);
            result.add(subject);
        }
    } catch (NamingException ex) {
        log.error("LDAP Naming Except: " + ex.getMessage(), ex);
    }

    return result;
}