View | Details | Raw Unified | Return to bug 59123
Collapse All | Expand All

(-)a/java/org/apache/catalina/realm/JNDIRealm.java (-43 / +56 lines)
Lines 1684-1744 public class JNDIRealm extends RealmBase { Link Here
1684
1684
1685
        NamingEnumeration<SearchResult> results =
1685
        NamingEnumeration<SearchResult> results =
1686
            context.search(userBase, filter, constraints);
1686
            context.search(userBase, filter, constraints);
1687
1688
1689
        // Fail if no entries found
1690
        try {
1687
        try {
1691
            if (results == null || !results.hasMore()) {
1688
1692
                return (null);
1689
            // Fail if no entries found
1690
            try {
1691
                if (results == null || !results.hasMore()) {
1692
                    return null;
1693
                }
1694
            } catch (PartialResultException ex) {
1695
                if (!adCompat) {
1696
                    throw ex;
1697
                } else {
1698
                    return null;
1699
                }
1693
            }
1700
            }
1694
        } catch (PartialResultException ex) {
1695
            if (!adCompat)
1696
                throw ex;
1697
            else
1698
                return (null);
1699
        }
1700
1701
1701
        // Get result for the first entry found
1702
            // Get result for the first entry found
1702
        SearchResult result = results.next();
1703
            SearchResult result = results.next();
1703
1704
1704
        // Check no further entries were found
1705
            // Check no further entries were found
1705
        try {
1706
            try {
1706
            if (results.hasMore()) {
1707
                if (results.hasMore()) {
1707
                if(containerLog.isInfoEnabled())
1708
                    if(containerLog.isInfoEnabled())
1708
                    containerLog.info("username " + username + " has multiple entries");
1709
                        containerLog.info("username " + username + " has multiple entries");
1709
                return (null);
1710
                    return (null);
1711
                }
1712
            } catch (PartialResultException ex) {
1713
                if (!adCompat)
1714
                    throw ex;
1710
            }
1715
            }
1711
        } catch (PartialResultException ex) {
1712
            if (!adCompat)
1713
                throw ex;
1714
        }
1715
1716
1716
        String dn = getDistinguishedName(context, userBase, result);
1717
            String dn = getDistinguishedName(context, userBase, result);
1717
1718
1718
        if (containerLog.isTraceEnabled())
1719
            if (containerLog.isTraceEnabled())
1719
            containerLog.trace("  entry found for " + username + " with dn " + dn);
1720
                containerLog.trace("  entry found for " + username + " with dn " + dn);
1720
1721
1721
        // Get the entry's attributes
1722
            // Get the entry's attributes
1722
        Attributes attrs = result.getAttributes();
1723
            Attributes attrs = result.getAttributes();
1723
        if (attrs == null)
1724
            if (attrs == null)
1724
            return null;
1725
                return null;
1725
1726
1726
        // Retrieve value of userPassword
1727
            // Retrieve value of userPassword
1727
        String password = null;
1728
            String password = null;
1728
        if (userPassword != null)
1729
            if (userPassword != null)
1729
            password = getAttributeValue(userPassword, attrs);
1730
                password = getAttributeValue(userPassword, attrs);
1730
1731
1731
        String userRoleAttrValue = null;
1732
            String userRoleAttrValue = null;
1732
        if (userRoleAttribute != null) {
1733
            if (userRoleAttribute != null) {
1733
            userRoleAttrValue = getAttributeValue(userRoleAttribute, attrs);
1734
                userRoleAttrValue = getAttributeValue(userRoleAttribute, attrs);
1734
        }
1735
            }
1735
1736
1736
        // Retrieve values of userRoleName attribute
1737
            // Retrieve values of userRoleName attribute
1737
        ArrayList<String> roles = null;
1738
            ArrayList<String> roles = null;
1738
        if (userRoleName != null)
1739
            if (userRoleName != null)
1739
            roles = addAttributeValues(userRoleName, attrs, roles);
1740
                roles = addAttributeValues(userRoleName, attrs, roles);
1741
1742
            return new User(username, dn, password, roles, userRoleAttrValue);
1743
        } finally {
1744
            if (results != null) {
1745
                results.close();
1746
            }
1747
        }
1740
1748
1741
        return new User(username, dn, password, roles, userRoleAttrValue);
1742
    }
1749
    }
1743
1750
1744
1751
Lines 2003-2008 public class JNDIRealm extends RealmBase { Link Here
2003
        } catch (PartialResultException ex) {
2010
        } catch (PartialResultException ex) {
2004
            if (!adCompat)
2011
            if (!adCompat)
2005
                throw ex;
2012
                throw ex;
2013
        } finally {
2014
            results.close();
2006
        }
2015
        }
2007
2016
2008
        if (containerLog.isTraceEnabled()) {
2017
        if (containerLog.isTraceEnabled()) {
Lines 2054-2059 public class JNDIRealm extends RealmBase { Link Here
2054
                    } catch (PartialResultException ex) {
2063
                    } catch (PartialResultException ex) {
2055
                        if (!adCompat)
2064
                        if (!adCompat)
2056
                            throw ex;
2065
                            throw ex;
2066
                    } finally {
2067
                        results.close();
2057
                    }
2068
                    }
2058
                }
2069
                }
2059
2070
Lines 2131-2136 public class JNDIRealm extends RealmBase { Link Here
2131
        } catch (PartialResultException ex) {
2142
        } catch (PartialResultException ex) {
2132
            if (!adCompat)
2143
            if (!adCompat)
2133
                throw ex;
2144
                throw ex;
2145
        } finally {
2146
            e.close();
2134
        }
2147
        }
2135
        return values;
2148
        return values;
2136
    }
2149
    }

Return to bug 59123