Example usage for javax.naming PartialResultException getMessage

List of usage examples for javax.naming PartialResultException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

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

/**
 * @param searchBase//from  ww  w  .  j  a  v a2  s .  c om
 * @param searchFilter
 * @param searchCtls
 * @param objectSid
 * @param primaryGroupID
 * @param userAttributeId
 * @param groupAttributeName
 * @return
 * @throws UserStoreException
 */
private List<String> getAttributeListOfOneElementWithPrimarGroup(String searchBase, String searchFilter,
        SearchControls searchCtls, String objectSid, String primaryGroupID, String userAttributeId,
        String groupAttributeName) throws UserStoreException {
    boolean debug = log.isDebugEnabled();

    List<String> list = new ArrayList<String>();
    DirContext dirContext = null;
    NamingEnumeration<SearchResult> answer = null;

    if (debug) {
        log.debug("GetAttributeListOfOneElementWithPrimarGroup. SearchBase: " + searchBase + " SearchFilter: "
                + searchFilter);
    }
    try {
        dirContext = connectionSource.getContext();
        answer = dirContext.search(escapeDNForSearch(searchBase), searchFilter, searchCtls);
        int count = 0;
        while (answer.hasMore()) {
            if (count > 0) {
                log.error("More than element user exist with name");
                throw new UserStoreException("More than element user exist with name");
            }
            SearchResult sr = (SearchResult) answer.next();
            count++;

            list = parseSearchResult(sr, groupAttributeName);

            String primaryGroupSID = LDAPUtil.getPrimaryGroupSID(sr, objectSid, primaryGroupID);
            String primaryGroupName = LDAPUtil.findGroupBySID(dirContext, searchBase, primaryGroupSID,
                    userAttributeId);
            if (primaryGroupName != null) {
                list.add(primaryGroupName);
            }
        }

    } catch (PartialResultException e) {
        // can be due to referrals in AD. so just ignore error
        String errorMessage = "Error occurred while GetAttributeListOfOneElementWithPrimarGroup. SearchBase: "
                + searchBase + " SearchFilter: " + searchFilter;
        if (isIgnorePartialResultException()) {
            if (log.isDebugEnabled()) {
                log.debug(errorMessage, e);
            }
        } else {
            throw new UserStoreException(errorMessage, e);
        }
    } catch (NamingException e) {
        if (log.isDebugEnabled()) {
            log.debug(e.getMessage(), e);
        }
        throw new UserStoreException(e.getMessage(), e);
    } finally {
        JNDIUtil.closeNamingEnumeration(answer);
        JNDIUtil.closeContext(dirContext);
    }

    if (debug) {
        log.debug("GetAttributeListOfOneElementWithPrimarGroup. SearchBase: " + searchBase + " SearchFilter: "
                + searchFilter);
        Iterator<String> ite = list.iterator();
        while (ite.hasNext()) {
            log.debug("result: " + ite.next());
        }
    }
    return list;
}