javax.naming.PartialResultException Java Examples
The following examples show how to use
javax.naming.PartialResultException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapConnectionWrapper.java From Alpine with Apache License 2.0 | 6 votes |
/** * Convenience method that wraps {@link NamingEnumeration#hasMore()} but ignores {@link PartialResultException}s * that may be thrown as a result. This is typically an issue with a directory server that does not support * {@link Context#REFERRAL} being set to 'ignore' (which is the default value). * * Issue: https://github.com/stevespringett/Alpine/issues/19 * @since 1.4.3 */ private boolean hasMoreEnum(final NamingEnumeration<SearchResult> ne) throws NamingException { if (ne == null) { return false; } boolean hasMore = true; try { if (!ne.hasMore()) { hasMore = false; } } catch (PartialResultException e) { hasMore = false; LOGGER.warn("Partial results returned. If this is an Active Directory server, try using port 3268 or 3269 in " + Config.AlpineKey.LDAP_SERVER_URL.name()); } return hasMore; }
Example #2
Source File: JNDIRealm.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Add values of a specified attribute to a list * * @param attrId Attribute name * @param attrs Attributes containing the new values * @param values ArrayList containing values found so far * @return the list of attribute values * @exception NamingException if a directory server error occurs */ private ArrayList<String> addAttributeValues(String attrId, Attributes attrs, ArrayList<String> values) throws NamingException{ if (containerLog.isTraceEnabled()) containerLog.trace(" retrieving values for attribute " + attrId); if (attrId == null || attrs == null) return values; if (values == null) values = new ArrayList<>(); Attribute attr = attrs.get(attrId); if (attr == null) return values; NamingEnumeration<?> e = attr.getAll(); try { while(e.hasMore()) { String value = (String)e.next(); values.add(value); } } catch (PartialResultException ex) { if (!adCompat) throw ex; } finally { e.close(); } return values; }
Example #3
Source File: JNDIRealm.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Add values of a specified attribute to a list * * @param attrId Attribute name * @param attrs Attributes containing the new values * @param values ArrayList containing values found so far * * @exception NamingException if a directory server error occurs */ private ArrayList<String> addAttributeValues(String attrId, Attributes attrs, ArrayList<String> values) throws NamingException{ if (containerLog.isTraceEnabled()) containerLog.trace(" retrieving values for attribute " + attrId); if (attrId == null || attrs == null) return values; if (values == null) values = new ArrayList<String>(); Attribute attr = attrs.get(attrId); if (attr == null) return (values); NamingEnumeration<?> e = attr.getAll(); try { while(e.hasMore()) { String value = (String)e.next(); values.add(value); } } catch (PartialResultException ex) { if (!adCompat) throw ex; } return values; }
Example #4
Source File: JNDIRealm.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Add values of a specified attribute to a list * * @param attrId Attribute name * @param attrs Attributes containing the new values * @param values ArrayList containing values found so far * * @exception NamingException if a directory server error occurs */ private ArrayList<String> addAttributeValues(String attrId, Attributes attrs, ArrayList<String> values) throws NamingException{ if (containerLog.isTraceEnabled()) containerLog.trace(" retrieving values for attribute " + attrId); if (attrId == null || attrs == null) return values; if (values == null) values = new ArrayList<String>(); Attribute attr = attrs.get(attrId); if (attr == null) return values; NamingEnumeration<?> e = attr.getAll(); try { while(e.hasMore()) { String value = (String)e.next(); values.add(value); } } catch (PartialResultException ex) { if (!adCompat) throw ex; } finally { e.close(); } return values; }
Example #5
Source File: LdapAccessServiceBeanTest.java From development with Apache License 2.0 | 5 votes |
@Test public void search_withPartialResultException() throws Exception { // given initAttribute(SEARCH_ATTRIBUTES[0], aMock); initAttribute(SEARCH_ATTRIBUTES[1], aMock); initAttribute(SEARCH_ATTRIBUTES[2], aMock); when(Boolean.valueOf(neMock.hasMore())).thenReturn(Boolean.TRUE) .thenThrow(new PartialResultException()); Map<SettingType, String> map = new HashMap<SettingType, String>(); map.put(SettingType.LDAP_ATTR_UID, SEARCH_ATTRIBUTES[0]); map.put(SettingType.LDAP_ATTR_FIRST_NAME, SEARCH_ATTRIBUTES[1]); map.put(SettingType.LDAP_ATTR_EMAIL, SEARCH_ATTRIBUTES[2]); ILdapResultMapper<VOUserDetails> mapper = new LdapVOUserDetailsMapper( null, map); List<VOUserDetails> list = new ArrayList<VOUserDetails>(); // when list = bean.search(new Properties(), "baseDN", "filter", mapper, false); // then assertNotNull(list); assertEquals(1, list.size()); VOUserDetails det = list.get(0); assertEquals(SEARCH_ATTRIBUTES[0], det.getRealmUserId()); assertEquals(SEARCH_ATTRIBUTES[1], det.getFirstName()); assertEquals(SEARCH_ATTRIBUTES[2], det.getEMail()); }
Example #6
Source File: LdapAccessServiceBean.java From development with Apache License 2.0 | 5 votes |
private boolean hasMoreEnum(NamingEnumeration<SearchResult> namingEnum) throws NamingException { boolean hasMore = true; try { if (!namingEnum.hasMore()) { hasMore = false; } } catch (PartialResultException e) { hasMore = false; logger.logWarn(Log4jLogger.SYSTEM_LOG, e, LogMessageIdentifier.WARN_LDAP_PARTIAL_EXCEPTION); } return hasMore; }
Example #7
Source File: LdapClient.java From iaf with Apache License 2.0 | 5 votes |
public String getFirstSearchResult(NamingEnumeration<SearchResult> searchResultEnum) throws NamingException { String result=null; try { if (searchResultEnum.hasMore()) { result=getFirstAttribute(searchResultEnum.next()); } } catch(PartialResultException e) { if (log.isDebugEnabled()) log.debug("ignoring Exception: "+e); } finally { searchResultEnum.close(); } return result; }
Example #8
Source File: LdapClient.java From iaf with Apache License 2.0 | 5 votes |
public void mapMultiValuedAttribute(NamingEnumeration<SearchResult> searchResultEnum, Callback<Attribute,Object> callback) throws NamingException { try { while (searchResultEnum.hasMore()) { Attributes attributes=searchResultEnum.next().getAttributes(); NamingEnumeration<? extends Attribute> attrenum=attributes.getAll(); try { while (attrenum.hasMore()) { Attribute attr=attrenum.next(); NamingEnumeration<?> multivalueattribute=attr.getAll(); try { while (multivalueattribute.hasMore()) { callback.handle(attr,multivalueattribute.next()); } } finally { multivalueattribute.close(); } } } finally { attrenum.close(); } } } catch(PartialResultException e) { if (log.isDebugEnabled()) log.debug("ignoring Exception: "+e); } finally { searchResultEnum.close(); } }
Example #9
Source File: LdapClient.java From iaf with Apache License 2.0 | 5 votes |
/** * runs a set of attribute values through a Mapper. Only the first value of each attribute is mapped. */ public void mapMultipleAttributes(NamingEnumeration<SearchResult> searchResultEnum, Callback<Attribute,Object> callback) throws NamingException { try { while (searchResultEnum.hasMore()) { Attributes attributes=searchResultEnum.next().getAttributes(); NamingEnumeration<? extends Attribute> attrenum=attributes.getAll(); try { while (attrenum.hasMore()) { Attribute attr=attrenum.next(); NamingEnumeration<?> multivalueattribute=attr.getAll(); try { if (multivalueattribute.hasMore()) { callback.handle(attr,multivalueattribute.next()); } } finally { multivalueattribute.close(); } } } finally { attrenum.close(); } } } catch(PartialResultException e) { if (log.isDebugEnabled()) log.debug("ignoring Exception: "+e); } finally { searchResultEnum.close(); } }
Example #10
Source File: LdapAuthenticator.java From onedev with MIT License | 4 votes |
private Collection<String> retrieveGroupsByFilter(DirContext ctx, DirContext referralCtx, String userDN) { Collection<String> groupNames = new HashSet<>(); try { SearchGroupsUsingFilter groupRetrieval = (SearchGroupsUsingFilter) getGroupRetrieval(); String groupNameAttribute = groupRetrieval.getGroupNameAttribute(); Name groupSearchBase = new CompositeName().add(groupRetrieval.getGroupSearchBase()); String groupSearchFilter = StringUtils.replace(groupRetrieval.getGroupSearchFilter(), "{0}", userDN); groupSearchFilter = StringUtils.replace(groupSearchFilter, "\\", "\\\\"); logger.debug("Evaluated group search filter: " + groupSearchFilter); SearchControls searchControls = new SearchControls(); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); searchControls.setReturningAttributes(new String[]{groupNameAttribute}); searchControls.setReturningObjFlag(true); NamingEnumeration<SearchResult> results; if (referralCtx != null) results = referralCtx.search(groupSearchBase, groupSearchFilter, searchControls); else results = ctx.search(groupSearchBase, groupSearchFilter, searchControls); if (results != null) { while (results.hasMore()) { SearchResult searchResult = (SearchResult) results.next(); Attributes searchResultAttributes = searchResult.getAttributes(); if (searchResultAttributes == null || searchResultAttributes.get(groupNameAttribute) == null || searchResultAttributes.get(groupNameAttribute).get() == null) { throw new RuntimeException("Can not find attribute '" + groupNameAttribute + "' in the returned group object."); } groupNames.add((String) searchResultAttributes.get(groupNameAttribute).get()); } } } catch (PartialResultException pre) { logger.warn("Partial exception detected. You may try to set property " + "'follow referrals' to true to avoid this exception.", pre); } catch (NamingException e) { logger.error("Error retrieving groups by filter", e); } return groupNames; }