@Test public void testFormatForUrlEmpty() throws InvalidNameException { LdapName ldapName = new LdapName(""); String result = AbstractContextSource.formatForUrl(ldapName); assertThat(result).isEqualTo(""); }
static String formatForUrl(LdapName ldapName) { StringBuilder sb = new StringBuilder(); ListIterator<Rdn> it = ldapName.getRdns().listIterator(ldapName.size()); while (it.hasPrevious()) { Rdn component = it.previous(); Attributes attributes = component.toAttributes(); NamingEnumeration<? extends Attribute> allAttributes = attributes.getAll(); while(allAttributes.hasMoreElements()) { Attribute oneAttribute = allAttributes.nextElement(); String encodedAttributeName = nameEncodeForUrl(oneAttribute.getID()); NamingEnumeration <?> allValues; try { allValues = oneAttribute.getAll(); } catch (NamingException e) { throw new UncategorizedLdapException("Unexpected error occurred formatting base URL", e); } while(allValues.hasMoreElements()) { sb.append(encodedAttributeName).append('='); Object oneValue = allValues.nextElement(); if (oneValue instanceof String) { String oneString = (String) oneValue; sb.append(nameEncodeForUrl(oneString)); } else { throw new IllegalArgumentException("Binary attributes not supported for base URL"); } if(allValues.hasMoreElements()) { sb.append('+'); } } if(allAttributes.hasMoreElements()) { sb.append('+'); } } if(it.hasPrevious()) { sb.append(','); } } return sb.toString(); }
AbstractContextSource implements BaseLdapPathContextSource, InitializingBean { static String formatForUrl(LdapName ldapName) { StringBuilder sb = new StringBuilder(); ListIterator<Rdn> it = ldapName.getRdns().listIterator(ldapName.size()); while (it.hasPrevious()) { Rdn component = it.previous(); Attributes attributes = component.toAttributes(); NamingEnumeration<? extends Attribute> allAttributes = attributes.getAll(); while(allAttributes.hasMoreElements()) { Attribute oneAttribute = allAttributes.nextElement(); String encodedAttributeName = nameEncodeForUrl(oneAttribute.getID()); NamingEnumeration <?> allValues; try { allValues = oneAttribute.getAll(); } catch (NamingException e) { throw new UncategorizedLdapException("Unexpected error occurred formatting base URL", e); } while(allValues.hasMoreElements()) { sb.append(encodedAttributeName).append('='); Object oneValue = allValues.nextElement(); if (oneValue instanceof String) { String oneString = (String) oneValue; sb.append(nameEncodeForUrl(oneString)); } else { throw new IllegalArgumentException("Binary attributes not supported for base URL"); } if(allValues.hasMoreElements()) { sb.append('+'); } } if(allAttributes.hasMoreElements()) { sb.append('+'); } } if(it.hasPrevious()) { sb.append(','); } } return sb.toString(); } }
AbstractContextSource implements BaseLdapPathContextSource, InitializingBean { static String formatForUrl(LdapName ldapName) { StringBuilder sb = new StringBuilder(); ListIterator<Rdn> it = ldapName.getRdns().listIterator(ldapName.size()); while (it.hasPrevious()) { Rdn component = it.previous(); Attributes attributes = component.toAttributes(); NamingEnumeration<? extends Attribute> allAttributes = attributes.getAll(); while(allAttributes.hasMoreElements()) { Attribute oneAttribute = allAttributes.nextElement(); String encodedAttributeName = nameEncodeForUrl(oneAttribute.getID()); NamingEnumeration <?> allValues; try { allValues = oneAttribute.getAll(); } catch (NamingException e) { throw new UncategorizedLdapException("Unexpected error occurred formatting base URL", e); } while(allValues.hasMoreElements()) { sb.append(encodedAttributeName).append('='); Object oneValue = allValues.nextElement(); if (oneValue instanceof String) { String oneString = (String) oneValue; sb.append(nameEncodeForUrl(oneString)); } else { throw new IllegalArgumentException("Binary attributes not supported for base URL"); } if(allValues.hasMoreElements()) { sb.append('+'); } } if(allAttributes.hasMoreElements()) { sb.append('+'); } } if(it.hasPrevious()) { sb.append(','); } } return sb.toString(); }  }
AbstractContextSource implements BaseLdapPathContextSource, InitializingBean { static String formatForUrl(LdapName ldapName) { StringBuilder sb = new StringBuilder(); ListIterator<Rdn> it = ldapName.getRdns().listIterator(ldapName.size()); while (it.hasPrevious()) { Rdn component = it.previous(); Attributes attributes = component.toAttributes(); NamingEnumeration<? extends Attribute> allAttributes = attributes.getAll(); while(allAttributes.hasMoreElements()) { Attribute oneAttribute = allAttributes.nextElement(); String encodedAttributeName = nameEncodeForUrl(oneAttribute.getID()); NamingEnumeration <?> allValues; try { allValues = oneAttribute.getAll(); } catch (NamingException e) { throw new UncategorizedLdapException("Unexpected error occurred formatting base URL", e); } while(allValues.hasMoreElements()) { sb.append(encodedAttributeName).append('='); Object oneValue = allValues.nextElement(); if (oneValue instanceof String) { String oneString = (String) oneValue; sb.append(nameEncodeForUrl(oneString)); } else { throw new IllegalArgumentException("Binary attributes not supported for base URL"); } if(allValues.hasMoreElements()) { sb.append('+'); } } if(allAttributes.hasMoreElements()) { sb.append('+'); } } if(it.hasPrevious()) { sb.append(','); } } return sb.toString(); }  DirContext getContext(String principal, String credentials); DirContext getReadOnlyContext(); DirContext getReadWriteContext(); String assembleProviderUrlString(String[] ldapUrls); void setBase(String base); @Override DistinguishedName getBaseLdapPath(); @Override LdapName getBaseLdapName(); @Override String getBaseLdapPathAsString(); void setContextFactory(Class<?> contextFactory); Class<?> getContextFactory(); void setDirObjectFactory(Class<?> dirObjectFactory); Class<?> getDirObjectFactory(); void afterPropertiesSet(); void setPassword(String password); String getPassword(); void setUserDn(String userDn); String getUserDn(); void setUrls(String[] urls); String[] getUrls(); void setUrl(String url); void setPooled(boolean pooled); boolean isPooled(); void setBaseEnvironmentProperties(Map<String, Object> baseEnvironmentProperties); void setAuthenticationSource(AuthenticationSource authenticationSource); AuthenticationSource getAuthenticationSource(); void setCacheEnvironmentProperties(boolean cacheEnvironmentProperties); void setAnonymousReadOnly(boolean anonymousReadOnly); boolean isAnonymousReadOnly(); void setAuthenticationStrategy(DirContextAuthenticationStrategy authenticationStrategy); void setReferral(String referral); }
AbstractContextSource implements BaseLdapPathContextSource, InitializingBean { static String formatForUrl(LdapName ldapName) { StringBuilder sb = new StringBuilder(); ListIterator<Rdn> it = ldapName.getRdns().listIterator(ldapName.size()); while (it.hasPrevious()) { Rdn component = it.previous(); Attributes attributes = component.toAttributes(); NamingEnumeration<? extends Attribute> allAttributes = attributes.getAll(); while(allAttributes.hasMoreElements()) { Attribute oneAttribute = allAttributes.nextElement(); String encodedAttributeName = nameEncodeForUrl(oneAttribute.getID()); NamingEnumeration <?> allValues; try { allValues = oneAttribute.getAll(); } catch (NamingException e) { throw new UncategorizedLdapException("Unexpected error occurred formatting base URL", e); } while(allValues.hasMoreElements()) { sb.append(encodedAttributeName).append('='); Object oneValue = allValues.nextElement(); if (oneValue instanceof String) { String oneString = (String) oneValue; sb.append(nameEncodeForUrl(oneString)); } else { throw new IllegalArgumentException("Binary attributes not supported for base URL"); } if(allValues.hasMoreElements()) { sb.append('+'); } } if(allAttributes.hasMoreElements()) { sb.append('+'); } } if(it.hasPrevious()) { sb.append(','); } } return sb.toString(); }  DirContext getContext(String principal, String credentials); DirContext getReadOnlyContext(); DirContext getReadWriteContext(); String assembleProviderUrlString(String[] ldapUrls); void setBase(String base); @Override DistinguishedName getBaseLdapPath(); @Override LdapName getBaseLdapName(); @Override String getBaseLdapPathAsString(); void setContextFactory(Class<?> contextFactory); Class<?> getContextFactory(); void setDirObjectFactory(Class<?> dirObjectFactory); Class<?> getDirObjectFactory(); void afterPropertiesSet(); void setPassword(String password); String getPassword(); void setUserDn(String userDn); String getUserDn(); void setUrls(String[] urls); String[] getUrls(); void setUrl(String url); void setPooled(boolean pooled); boolean isPooled(); void setBaseEnvironmentProperties(Map<String, Object> baseEnvironmentProperties); void setAuthenticationSource(AuthenticationSource authenticationSource); AuthenticationSource getAuthenticationSource(); void setCacheEnvironmentProperties(boolean cacheEnvironmentProperties); void setAnonymousReadOnly(boolean anonymousReadOnly); boolean isAnonymousReadOnly(); void setAuthenticationStrategy(DirContextAuthenticationStrategy authenticationStrategy); void setReferral(String referral); static final String SUN_LDAP_POOLING_FLAG; }